`isMuted` -> `isConversationMuted`

This commit is contained in:
Evan Hahn 2022-05-23 18:37:53 +00:00 committed by GitHub
parent 3f0ed541f6
commit 28ab6e11f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 44 deletions

View File

@ -44,7 +44,7 @@ import type {
ReplaceAvatarActionType, ReplaceAvatarActionType,
SaveAvatarToDiskActionType, SaveAvatarToDiskActionType,
} from '../../../types/Avatar'; } from '../../../types/Avatar';
import { isMuted } from '../../../util/isMuted'; import { isConversationMuted } from '../../../util/isConversationMuted';
enum ModalState { enum ModalState {
NothingOpen, NothingOpen,
@ -305,7 +305,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
throw missingCaseError(modalState); throw missingCaseError(modalState);
} }
const isConversationMuted = isMuted(conversation.muteExpiresAt); const isMuted = isConversationMuted(conversation);
return ( return (
<div className="conversation-details-panel"> <div className="conversation-details-panel">
@ -348,11 +348,9 @@ export const ConversationDetails: React.ComponentType<Props> = ({
</> </>
)} )}
<Button <Button
icon={ icon={isMuted ? ButtonIconType.muted : ButtonIconType.unmuted}
isConversationMuted ? ButtonIconType.muted : ButtonIconType.unmuted
}
onClick={() => { onClick={() => {
if (isConversationMuted) { if (isMuted) {
setModalState(ModalState.UnmuteNotifications); setModalState(ModalState.UnmuteNotifications);
} else { } else {
setModalState(ModalState.MuteNotifications); setModalState(ModalState.MuteNotifications);
@ -360,7 +358,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
}} }}
variant={ButtonVariant.Details} variant={ButtonVariant.Details}
> >
{isConversationMuted ? i18n('unmute') : i18n('mute')} {isMuted ? i18n('unmute') : i18n('mute')}
</Button> </Button>
<Button <Button
icon={ButtonIconType.search} icon={ButtonIconType.search}

View File

@ -10,7 +10,7 @@ import { PanelSection } from './PanelSection';
import { PanelRow } from './PanelRow'; import { PanelRow } from './PanelRow';
import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon'; import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon';
import { Select } from '../../Select'; import { Select } from '../../Select';
import { isMuted } from '../../../util/isMuted'; import { isConversationMuted } from '../../../util/isConversationMuted';
import { getMuteOptions } from '../../../util/getMuteOptions'; import { getMuteOptions } from '../../../util/getMuteOptions';
import { parseIntOrThrow } from '../../../util/parseIntOrThrow'; import { parseIntOrThrow } from '../../../util/parseIntOrThrow';
import { useUniqueId } from '../../../hooks/useUniqueId'; import { useUniqueId } from '../../../hooks/useUniqueId';
@ -40,7 +40,7 @@ export const ConversationNotificationsSettings: FunctionComponent<
const mentionsSelectId = useUniqueId(); const mentionsSelectId = useUniqueId();
const muteOptions = useMemo( const muteOptions = useMemo(
() => [ () => [
...(isMuted(muteExpiresAt) ...(isConversationMuted({ muteExpiresAt })
? [] ? []
: [ : [
{ {

View File

@ -44,7 +44,7 @@ import type {
import type { MessageModel } from './messages'; import type { MessageModel } from './messages';
import { getContact } from '../messages/helpers'; import { getContact } from '../messages/helpers';
import { strictAssert } from '../util/assert'; import { strictAssert } from '../util/assert';
import { isMuted } from '../util/isMuted'; import { isConversationMuted } from '../util/isConversationMuted';
import { isConversationSMSOnly } from '../util/isConversationSMSOnly'; import { isConversationSMSOnly } from '../util/isConversationSMSOnly';
import { isConversationUnregistered } from '../util/isConversationUnregistered'; import { isConversationUnregistered } from '../util/isConversationUnregistered';
import { missingCaseError } from '../util/missingCaseError'; import { missingCaseError } from '../util/missingCaseError';
@ -5203,7 +5203,7 @@ export class ConversationModel extends window.Backbone
} }
isMuted(): boolean { isMuted(): boolean {
return isMuted(this.get('muteExpiresAt')); return isConversationMuted(this.attributes);
} }
async notify( async notify(

View File

@ -0,0 +1,23 @@
// Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { isConversationMuted } from '../../util/isConversationMuted';
describe('isConversationMuted', () => {
it('returns false if passed an undefined expiry time', () => {
assert.isFalse(isConversationMuted({}));
assert.isFalse(isConversationMuted({ muteExpiresAt: undefined }));
});
it('returns false if passed a date in the past', () => {
assert.isFalse(isConversationMuted({ muteExpiresAt: 0 }));
assert.isFalse(isConversationMuted({ muteExpiresAt: Date.now() - 123 }));
});
it('returns true if passed a date in the future', () => {
assert.isTrue(isConversationMuted({ muteExpiresAt: Date.now() + 123 }));
assert.isTrue(isConversationMuted({ muteExpiresAt: Date.now() + 123456 }));
});
});

View File

@ -1,22 +0,0 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { isMuted } from '../../util/isMuted';
describe('isMuted', () => {
it('returns false if passed undefined', () => {
assert.isFalse(isMuted(undefined));
});
it('returns false if passed a date in the past', () => {
assert.isFalse(isMuted(0));
assert.isFalse(isMuted(Date.now() - 123));
});
it('returns false if passed a date in the future', () => {
assert.isTrue(isMuted(Date.now() + 123));
assert.isTrue(isMuted(Date.now() + 123456));
});
});

View File

@ -1,10 +1,10 @@
// Copyright 2020-2021 Signal Messenger, LLC // Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import * as durations from './durations'; import * as durations from './durations';
import type { LocalizerType } from '../types/Util'; import type { LocalizerType } from '../types/Util';
import { getMutedUntilText } from './getMutedUntilText'; import { getMutedUntilText } from './getMutedUntilText';
import { isMuted } from './isMuted'; import { isConversationMuted } from './isConversationMuted';
export type MuteOption = { export type MuteOption = {
name: string; name: string;
@ -17,7 +17,7 @@ export function getMuteOptions(
i18n: LocalizerType i18n: LocalizerType
): Array<MuteOption> { ): Array<MuteOption> {
return [ return [
...(isMuted(muteExpiresAt) ...(muteExpiresAt && isConversationMuted({ muteExpiresAt })
? [ ? [
{ {
name: getMutedUntilText(muteExpiresAt, i18n), name: getMutedUntilText(muteExpiresAt, i18n),

View File

@ -0,0 +1,9 @@
// Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationAttributesType } from '../model-types.d';
export const isConversationMuted = ({
muteExpiresAt,
}: Readonly<Pick<ConversationAttributesType, 'muteExpiresAt'>>): boolean =>
Boolean(muteExpiresAt && Date.now() < muteExpiresAt);

View File

@ -1,8 +0,0 @@
// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function isMuted(
muteExpiresAt: undefined | number
): muteExpiresAt is number {
return Boolean(muteExpiresAt && Date.now() < muteExpiresAt);
}