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
|
|
|
|
|
2021-08-26 14:10:58 +00:00
|
|
|
import * as durations from './durations';
|
2021-10-26 19:15:33 +00:00
|
|
|
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
|
|
|
|
2021-04-01 21:02:22 +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'),
|
2021-08-26 14:10:58 +00:00
|
|
|
value: durations.HOUR,
|
2020-08-27 19:45:08 +00:00
|
|
|
},
|
2021-04-09 16:19:38 +00:00
|
|
|
{
|
|
|
|
name: i18n('muteEightHours'),
|
2021-08-26 14:10:58 +00:00
|
|
|
value: 8 * durations.HOUR,
|
2021-04-09 16:19:38 +00:00
|
|
|
},
|
2020-08-27 19:45:08 +00:00
|
|
|
{
|
|
|
|
name: i18n('muteDay'),
|
2021-08-26 14:10:58 +00:00
|
|
|
value: durations.DAY,
|
2020-08-27 19:45:08 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: i18n('muteWeek'),
|
2021-08-26 14:10:58 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|