From a1791ca197a1ac46ef43b9154753a69771dcd869 Mon Sep 17 00:00:00 2001
From: Ajay Bura <32841439+ajbura@users.noreply.github.com>
Date: Mon, 16 Dec 2024 18:31:27 +0530
Subject: [PATCH] add all messages notification settings options
---
.../settings/notifications/AllMessages.tsx | 151 ++++++++++++++++++
.../settings/notifications/Notifications.tsx | 2 +
2 files changed, 153 insertions(+)
create mode 100644 src/app/features/settings/notifications/AllMessages.tsx
diff --git a/src/app/features/settings/notifications/AllMessages.tsx b/src/app/features/settings/notifications/AllMessages.tsx
new file mode 100644
index 00000000..8334fd38
--- /dev/null
+++ b/src/app/features/settings/notifications/AllMessages.tsx
@@ -0,0 +1,151 @@
+import React, { useCallback, useMemo } from 'react';
+import { Badge, Box, Text } from 'folds';
+import { ConditionKind, IPushRules, PushRuleCondition, PushRuleKind, RuleId } from 'matrix-js-sdk';
+import { useAccountData } from '../../../hooks/useAccountData';
+import { AccountDataEvent } from '../../../../types/matrix/accountData';
+import { NotificationModeSwitcher } from './NotificationModeSwitcher';
+import { SequenceCard } from '../../../components/sequence-card';
+import { SequenceCardStyle } from '../styles.css';
+import { SettingTile } from '../../../components/setting-tile';
+import { PushRuleData, usePushRule } from '../../../hooks/usePushRule';
+import {
+ getNotificationModeActions,
+ NotificationMode,
+ useNotificationModeActions,
+} from '../../../hooks/useNotificationMode';
+import { useMatrixClient } from '../../../hooks/useMatrixClient';
+
+const getAllMessageDefaultRule = (
+ ruleId: RuleId,
+ encrypted: boolean,
+ oneToOne: boolean
+): PushRuleData => {
+ const conditions: PushRuleCondition[] = [];
+ if (oneToOne)
+ conditions.push({
+ kind: ConditionKind.RoomMemberCount,
+ is: '2',
+ });
+ conditions.push({
+ kind: ConditionKind.EventMatch,
+ key: 'type',
+ pattern: encrypted ? 'm.room.encrypted' : 'm.room.message',
+ });
+
+ return {
+ kind: PushRuleKind.Underride,
+ pushRule: {
+ rule_id: ruleId,
+ default: true,
+ enabled: true,
+ conditions,
+ actions: getNotificationModeActions(NotificationMode.NotifyLoud),
+ },
+ };
+};
+
+type PushRulesProps = {
+ ruleId: RuleId.DM | RuleId.EncryptedDM | RuleId.Message | RuleId.EncryptedMessage;
+ pushRules: IPushRules;
+ encrypted?: boolean;
+ oneToOne?: boolean;
+};
+function AllMessagesModeSwitcher({ ruleId, pushRules, encrypted, oneToOne }: PushRulesProps) {
+ const mx = useMatrixClient();
+ const defaultPushRuleData = getAllMessageDefaultRule(
+ ruleId,
+ encrypted ?? false,
+ oneToOne ?? false
+ );
+ const { kind, pushRule } = usePushRule(pushRules, ruleId) ?? defaultPushRuleData;
+ const getModeActions = useNotificationModeActions();
+
+ const handleChange = useCallback(
+ async (mode: NotificationMode) => {
+ const actions = getModeActions(mode);
+ await mx.setPushRuleActions('global', kind, ruleId, actions);
+ },
+ [mx, getModeActions, kind, ruleId]
+ );
+
+ return ;
+}
+
+export function AllMessagesNotifications() {
+ const pushRulesEvt = useAccountData(AccountDataEvent.PushRules);
+ const pushRules = useMemo(
+ () => pushRulesEvt?.getContent() ?? { global: {} },
+ [pushRulesEvt]
+ );
+
+ return (
+
+
+ All Messages
+
+ Hint:
+
+ 1
+
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+ );
+}
diff --git a/src/app/features/settings/notifications/Notifications.tsx b/src/app/features/settings/notifications/Notifications.tsx
index 3f948b00..c9e4ef72 100644
--- a/src/app/features/settings/notifications/Notifications.tsx
+++ b/src/app/features/settings/notifications/Notifications.tsx
@@ -7,6 +7,7 @@ import { SettingTile } from '../../../components/setting-tile';
import { useSetting } from '../../../state/hooks/settings';
import { settingsAtom } from '../../../state/settings';
import { usePermissionState } from '../../../hooks/usePermission';
+import { AllMessagesNotifications } from './AllMessages';
function SystemNotification() {
const notifPermission = usePermissionState(
@@ -100,6 +101,7 @@ export function Notifications({ requestClose }: NotificationsProps) {
+