signal-desktop/ts/util/getMuteOptions.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 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,
},
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:unmute'),
2021-08-05 12:35:33 +00:00
value: 0,
},
]
: []),
2020-08-27 19:45:08 +00:00
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:muteHour'),
value: durations.HOUR,
2020-08-27 19:45:08 +00:00
},
2021-04-09 16:19:38 +00:00
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:muteEightHours'),
value: 8 * durations.HOUR,
2021-04-09 16:19:38 +00:00
},
2020-08-27 19:45:08 +00:00
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:muteDay'),
value: durations.DAY,
2020-08-27 19:45:08 +00:00
},
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:muteWeek'),
value: durations.WEEK,
2020-08-27 19:45:08 +00:00
},
{
2023-03-30 00:03:25 +00:00
name: i18n('icu:muteAlways'),
2021-04-09 16:19:38 +00:00
value: Number.MAX_SAFE_INTEGER,
2020-08-27 19:45:08 +00:00
},
];
}