isMuted
-> isConversationMuted
This commit is contained in:
parent
3f0ed541f6
commit
28ab6e11f6
8 changed files with 44 additions and 44 deletions
|
@ -44,7 +44,7 @@ import type {
|
|||
ReplaceAvatarActionType,
|
||||
SaveAvatarToDiskActionType,
|
||||
} from '../../../types/Avatar';
|
||||
import { isMuted } from '../../../util/isMuted';
|
||||
import { isConversationMuted } from '../../../util/isConversationMuted';
|
||||
|
||||
enum ModalState {
|
||||
NothingOpen,
|
||||
|
@ -305,7 +305,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
|
|||
throw missingCaseError(modalState);
|
||||
}
|
||||
|
||||
const isConversationMuted = isMuted(conversation.muteExpiresAt);
|
||||
const isMuted = isConversationMuted(conversation);
|
||||
|
||||
return (
|
||||
<div className="conversation-details-panel">
|
||||
|
@ -348,11 +348,9 @@ export const ConversationDetails: React.ComponentType<Props> = ({
|
|||
</>
|
||||
)}
|
||||
<Button
|
||||
icon={
|
||||
isConversationMuted ? ButtonIconType.muted : ButtonIconType.unmuted
|
||||
}
|
||||
icon={isMuted ? ButtonIconType.muted : ButtonIconType.unmuted}
|
||||
onClick={() => {
|
||||
if (isConversationMuted) {
|
||||
if (isMuted) {
|
||||
setModalState(ModalState.UnmuteNotifications);
|
||||
} else {
|
||||
setModalState(ModalState.MuteNotifications);
|
||||
|
@ -360,7 +358,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
|
|||
}}
|
||||
variant={ButtonVariant.Details}
|
||||
>
|
||||
{isConversationMuted ? i18n('unmute') : i18n('mute')}
|
||||
{isMuted ? i18n('unmute') : i18n('mute')}
|
||||
</Button>
|
||||
<Button
|
||||
icon={ButtonIconType.search}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { PanelSection } from './PanelSection';
|
|||
import { PanelRow } from './PanelRow';
|
||||
import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon';
|
||||
import { Select } from '../../Select';
|
||||
import { isMuted } from '../../../util/isMuted';
|
||||
import { isConversationMuted } from '../../../util/isConversationMuted';
|
||||
import { getMuteOptions } from '../../../util/getMuteOptions';
|
||||
import { parseIntOrThrow } from '../../../util/parseIntOrThrow';
|
||||
import { useUniqueId } from '../../../hooks/useUniqueId';
|
||||
|
@ -40,7 +40,7 @@ export const ConversationNotificationsSettings: FunctionComponent<
|
|||
const mentionsSelectId = useUniqueId();
|
||||
const muteOptions = useMemo(
|
||||
() => [
|
||||
...(isMuted(muteExpiresAt)
|
||||
...(isConversationMuted({ muteExpiresAt })
|
||||
? []
|
||||
: [
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ import type {
|
|||
import type { MessageModel } from './messages';
|
||||
import { getContact } from '../messages/helpers';
|
||||
import { strictAssert } from '../util/assert';
|
||||
import { isMuted } from '../util/isMuted';
|
||||
import { isConversationMuted } from '../util/isConversationMuted';
|
||||
import { isConversationSMSOnly } from '../util/isConversationSMSOnly';
|
||||
import { isConversationUnregistered } from '../util/isConversationUnregistered';
|
||||
import { missingCaseError } from '../util/missingCaseError';
|
||||
|
@ -5203,7 +5203,7 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
isMuted(): boolean {
|
||||
return isMuted(this.get('muteExpiresAt'));
|
||||
return isConversationMuted(this.attributes);
|
||||
}
|
||||
|
||||
async notify(
|
||||
|
|
23
ts/test-both/util/isConversationMuted_test.ts
Normal file
23
ts/test-both/util/isConversationMuted_test.ts
Normal 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 }));
|
||||
});
|
||||
});
|
|
@ -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));
|
||||
});
|
||||
});
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as durations from './durations';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
import { getMutedUntilText } from './getMutedUntilText';
|
||||
import { isMuted } from './isMuted';
|
||||
import { isConversationMuted } from './isConversationMuted';
|
||||
|
||||
export type MuteOption = {
|
||||
name: string;
|
||||
|
@ -17,7 +17,7 @@ export function getMuteOptions(
|
|||
i18n: LocalizerType
|
||||
): Array<MuteOption> {
|
||||
return [
|
||||
...(isMuted(muteExpiresAt)
|
||||
...(muteExpiresAt && isConversationMuted({ muteExpiresAt })
|
||||
? [
|
||||
{
|
||||
name: getMutedUntilText(muteExpiresAt, i18n),
|
||||
|
|
9
ts/util/isConversationMuted.ts
Normal file
9
ts/util/isConversationMuted.ts
Normal 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);
|
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue