// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useMemo } from 'react'; import type { ConversationTypeType } from '../../../state/ducks/conversations'; import type { LocalizerType } from '../../../types/Util'; import { PanelSection } from './PanelSection'; import { PanelRow } from './PanelRow'; import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon'; import { Select } from '../../Select'; import { isConversationMuted } from '../../../util/isConversationMuted'; import { getMuteOptions } from '../../../util/getMuteOptions'; import { parseIntOrThrow } from '../../../util/parseIntOrThrow'; import { useUniqueId } from '../../../hooks/useUniqueId'; type PropsType = { id: string; conversationType: ConversationTypeType; dontNotifyForMentionsIfMuted: boolean; i18n: LocalizerType; muteExpiresAt: undefined | number; setDontNotifyForMentionsIfMuted: ( conversationId: string, dontNotifyForMentionsIfMuted: boolean ) => unknown; setMuteExpiration: ( conversationId: string, muteExpiresAt: undefined | number ) => unknown; }; export function ConversationNotificationsSettings({ id, conversationType, dontNotifyForMentionsIfMuted, i18n, muteExpiresAt, setMuteExpiration, setDontNotifyForMentionsIfMuted, }: PropsType): JSX.Element { const muteNotificationsSelectId = useUniqueId(); const mentionsSelectId = useUniqueId(); const muteOptions = useMemo( () => [ ...(isConversationMuted({ muteExpiresAt }) ? [] : [ { disabled: true, text: i18n('icu:notMuted'), value: -1, }, ]), ...getMuteOptions(muteExpiresAt, i18n).map( ({ disabled, name, value }) => ({ disabled, text: name, value, }) ), ], [i18n, muteExpiresAt] ); const onMuteChange = (rawValue: string) => { const ms = parseIntOrThrow( rawValue, 'NotificationSettings: mute ms was not an integer' ); setMuteExpiration(id, ms); }; const onChangeDontNotifyForMentionsIfMuted = (rawValue: string) => { setDontNotifyForMentionsIfMuted(id, rawValue === 'yes'); }; return (