fix: use localized strings for notification header subtitle

pull/3206/head
Audric Ackermann 7 months ago
parent 9119fef90a
commit cc17285009
No known key found for this signature in database

@ -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;

@ -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

Loading…
Cancel
Save