Add option to change room notification settings (#2281)

This commit is contained in:
Ajay Bura 2025-03-20 20:27:00 +11:00 committed by GitHub
parent 074a5e855d
commit 71bfc96b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 409 additions and 164 deletions

View file

@ -7,6 +7,19 @@ export enum NotificationMode {
NotifyLoud = 'NotifyLoud',
}
export const getNotificationMode = (actions: PushRuleAction[]): NotificationMode => {
const soundTweak = actions.find(
(action) => typeof action === 'object' && action.set_tweak === TweakName.Sound
);
const notify = actions.find(
(action) => typeof action === 'string' && action === PushRuleActionName.Notify
);
if (notify && soundTweak) return NotificationMode.NotifyLoud;
if (notify) return NotificationMode.Notify;
return NotificationMode.OFF;
};
export type NotificationModeOptions = {
soundValue?: string;
highlight?: boolean;
@ -49,18 +62,7 @@ export const useNotificationModeActions = (
};
export const useNotificationActionsMode = (actions: PushRuleAction[]): NotificationMode => {
const mode: NotificationMode = useMemo(() => {
const soundTweak = actions.find(
(action) => typeof action === 'object' && action.set_tweak === TweakName.Sound
);
const notify = actions.find(
(action) => typeof action === 'string' && action === PushRuleActionName.Notify
);
if (notify && soundTweak) return NotificationMode.NotifyLoud;
if (notify) return NotificationMode.Notify;
return NotificationMode.OFF;
}, [actions]);
const mode: NotificationMode = useMemo(() => getNotificationMode(actions), [actions]);
return mode;
};