signal-desktop/ts/util/getMuteOptions.ts

55 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 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';
import { isMuted } from './isMuted';
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 [
2021-08-05 12:35:33 +00:00
...(isMuted(muteExpiresAt)
? [
{
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
},
];
}