signal-desktop/ts/util/getMuteOptions.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-05-23 18:37:53 +00:00
// Copyright 2020-2022 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import * as durations from './durations';
import type { LocalizerType } from '../types/Util';
2021-08-05 12:35:33 +00:00
import { getMutedUntilText } from './getMutedUntilText';
2022-05-23 18:37:53 +00:00
import { isConversationMuted } from './isConversationMuted';
2020-08-27 19:45:08 +00:00
export type MuteOption = {
2020-08-27 19:45:08 +00:00
name: string;
disabled?: boolean;
value: number;
};
2021-08-05 12:35:33 +00:00
export function getMuteOptions(
muteExpiresAt: undefined | number,
i18n: LocalizerType
): Array<MuteOption> {
2020-08-27 19:45:08 +00:00
return [
2022-05-23 18:37:53 +00:00
...(muteExpiresAt && isConversationMuted({ muteExpiresAt })
2021-08-05 12:35:33 +00:00
? [
{
name: getMutedUntilText(muteExpiresAt, i18n),
disabled: true,
value: -1,
},
{
name: i18n('unmute'),
value: 0,
},
]
: []),
2020-08-27 19:45:08 +00:00
{
name: i18n('muteHour'),
value: durations.HOUR,
2020-08-27 19:45:08 +00:00
},
2021-04-09 16:19:38 +00:00
{
name: i18n('muteEightHours'),
value: 8 * durations.HOUR,
2021-04-09 16:19:38 +00:00
},
2020-08-27 19:45:08 +00:00
{
name: i18n('muteDay'),
value: durations.DAY,
2020-08-27 19:45:08 +00:00
},
{
name: i18n('muteWeek'),
value: durations.WEEK,
2020-08-27 19:45:08 +00:00
},
{
2021-04-09 16:19:38 +00:00
name: i18n('muteAlways'),
value: Number.MAX_SAFE_INTEGER,
2020-08-27 19:45:08 +00:00
},
];
}