diff --git a/ts/components/conversation/header/ConversationHeaderTitle.tsx b/ts/components/conversation/header/ConversationHeaderTitle.tsx index f9b81bf88..196679fe9 100644 --- a/ts/components/conversation/header/ConversationHeaderTitle.tsx +++ b/ts/components/conversation/header/ConversationHeaderTitle.tsx @@ -34,6 +34,19 @@ type ConversationHeaderTitleProps = { showSubtitle?: boolean; }; +function useLocalizedNotificationText() { + const currentNotificationSetting = useSelectedNotificationSetting(); + switch (currentNotificationSetting) { + case 'mentions_only': + return window.i18n('notificationsHeaderMentionsOnly'); + case 'disabled': + return window.i18n('notificationsHeaderMute'); + case 'all': + default: + return window.i18n('notificationsHeaderAllMessages'); + } +} + export const ConversationHeaderTitle = (props: ConversationHeaderTitleProps) => { const { showSubtitle = true } = props; @@ -41,7 +54,6 @@ export const ConversationHeaderTitle = (props: ConversationHeaderTitleProps) => const convoId = useSelectedConversationKey(); const convoName = useSelectedNicknameOrProfileNameOrShortenedPubkey(); - const notificationSetting = useSelectedNotificationSetting(); const isRightPanelOn = useIsRightPanelShowing(); const subscriberCount = useSelectedSubscriberCount(); @@ -65,10 +77,7 @@ export const ConversationHeaderTitle = (props: ConversationHeaderTitleProps) => const { i18n } = window; - const notificationSubtitle = useMemo( - () => (notificationSetting ? i18n('sessionNotifications') : null), - [i18n, notificationSetting] - ); + const notificationSubtitle = useLocalizedNotificationText(); const memberCountSubtitle = useMemo(() => { let count = 0; diff --git a/ts/state/selectors/selectedConversation.ts b/ts/state/selectors/selectedConversation.ts index 8669e21bc..a2f5c08b7 100644 --- a/ts/state/selectors/selectedConversation.ts +++ b/ts/state/selectors/selectedConversation.ts @@ -17,25 +17,6 @@ import { } from './conversations'; import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo'; -/** - * Returns the formatted text for notification setting. - */ -const getCurrentNotificationSettingText = (state: StateType): string | undefined => { - if (!state) { - return undefined; - } - const currentNotificationSetting = getSelectedConversation(state)?.currentNotificationSetting; - switch (currentNotificationSetting) { - case 'mentions_only': - return window.i18n('notificationsMentionsOnly'); - case 'disabled': - return window.i18n('notificationsMute'); - case 'all': - default: - return window.i18n('notificationsAllMessages'); - } -}; - const getIsSelectedPrivate = (state: StateType): boolean => { return Boolean(getSelectedConversation(state)?.isPrivate) || false; }; @@ -120,6 +101,19 @@ function getSelectedBlindedDisabledMsgRequests(state: StateType) { return isBlindedAndDisabledMsgRequests; } +/** + * Defaults to 'all' if undefined + */ +function getSelectedNotificationSetting(state: StateType) { + const selectedConvoPubkey = getSelectedConversationKey(state); + if (!selectedConvoPubkey) { + return false; + } + const selectedConvo = getSelectedConversation(state); + + return selectedConvo?.currentNotificationSetting || 'all'; +} + const getSelectedConversationType = (state: StateType): ConversationTypeEnum | null => { const selected = getSelectedConversation(state); if (!selected || !selected.type) { @@ -239,6 +233,10 @@ export function useSelectedHasDisabledBlindedMsgRequests() { return useSelector(getSelectedBlindedDisabledMsgRequests); } +export function useSelectedNotificationSetting() { + return useSelector(getSelectedNotificationSetting); +} + /** * Returns true if the given arguments corresponds to a private contact which is approved both sides. i.e. a friend. */ @@ -285,10 +283,6 @@ export function useSelectedSubscriberCount() { return useSelector(getSelectedSubscriberCount); } -export function useSelectedNotificationSetting() { - return useSelector(getCurrentNotificationSettingText); -} - export function useSelectedIsKickedFromGroup() { return useSelector( (state: StateType) => Boolean(getSelectedConversation(state)?.isKickedFromGroup) || false