Skip to content

Commit

Permalink
use /pushrules instead of /m.push_rules
Browse files Browse the repository at this point in the history
The ability to set account for event types changed. See https://spec.matrix.org/v1.12/client-server-api/#server-behaviour-12.

The correct api is documented here: https://spec.matrix.org/v1.12/client-server-api/#push-rules-api.

fixes cinnyapp#2034
  • Loading branch information
LevitatingBusinessMan committed Dec 14, 2024
1 parent 00d5553 commit 1630e6b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/molecules/global-notification/GlobalNotification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function getTypeActions(type, highlightValue = false) {

function useGlobalNotif() {
const mx = useMatrixClient();
const pushRules = useAccountData('m.push_rules')?.getContent();
const pushRules = useAccountData('pushrules')?.getContent();
const underride = pushRules?.global?.underride ?? [];
const rulesToType = {
[DM]: notifType.ON,
Expand Down Expand Up @@ -93,7 +93,7 @@ function useGlobalNotif() {
}
ruleContent.actions = getTypeActions(type);

mx.setAccountData('m.push_rules', content);
mx.setAccountData('pushrules', content);
};

const dmRule = underride.find((rule) => rule.rule_id === DM);
Expand Down
8 changes: 4 additions & 4 deletions src/app/molecules/global-notification/KeywordNotification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const KEYWORD = 'keyword';

function useKeywordNotif() {
const mx = useMatrixClient();
const pushRules = useAccountData('m.push_rules')?.getContent();
const pushRules = useAccountData('pushrules')?.getContent();
const override = pushRules?.global?.override ?? [];
const content = pushRules?.global?.content ?? [];

Expand Down Expand Up @@ -92,7 +92,7 @@ function useKeywordNotif() {
});
}

mx.setAccountData('m.push_rules', evtContent);
mx.setAccountData('pushrules', evtContent);
};

const addKeyword = (keyword) => {
Expand All @@ -104,11 +104,11 @@ function useKeywordNotif() {
default: false,
actions: getTypeActions(rulesToType[KEYWORD] ?? notifType.NOISY, true),
});
mx.setAccountData('m.push_rules', pushRules);
mx.setAccountData('pushrules', pushRules);
};
const removeKeyword = (rule) => {
pushRules.global.content = content.filter((r) => r.rule_id !== rule.rule_id);
mx.setAccountData('m.push_rules', pushRules);
mx.setAccountData('pushrules', pushRules);
};

const dsRule = override.find((rule) => rule.rule_id === DISPLAY_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/room-list/mutedRoomList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useBindMutedRoomsAtom = (mx: MatrixClient, mutedAtom: typeof mutedR
const setMuted = useSetAtom(mutedAtom);

useEffect(() => {
const overrideRules = mx.getAccountData('m.push_rules')?.getContent<IPushRules>()
const overrideRules = mx.getAccountData('pushrules')?.getContent<IPushRules>()
?.global?.override;
if (overrideRules) {
const mutedRooms = overrideRules.reduce<string[]>((rooms, rule) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const getNotificationType = (mx: MatrixClient, roomId: string): Notificat
}

if (!roomPushRule) {
const overrideRules = mx.getAccountData('m.push_rules')?.getContent<IPushRules>()
const overrideRules = mx.getAccountData('pushrules')?.getContent<IPushRules>()
?.global?.override;
if (!overrideRules) return NotificationType.Default;

Expand Down

0 comments on commit 1630e6b

Please sign in to comment.