From 1cde686a13870331f266a138ef7af97b12fa8460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 4 May 2022 16:22:43 +0200 Subject: [PATCH] MSC3786: Add a default push rule to ignore `m.room.server_acl` events (#2333) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- spec/unit/pushprocessor.spec.js | 17 +++++++++++++++++ src/pushprocessor.ts | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/spec/unit/pushprocessor.spec.js b/spec/unit/pushprocessor.spec.js index 85fadcf78..df7666d5c 100644 --- a/spec/unit/pushprocessor.spec.js +++ b/spec/unit/pushprocessor.spec.js @@ -1,5 +1,6 @@ import * as utils from "../test-utils/test-utils"; import { PushProcessor } from "../../src/pushprocessor"; +import { EventType } from "../../src"; describe('NotificationService', function() { const testUserId = "@ali:matrix.org"; @@ -208,6 +209,7 @@ describe('NotificationService', function() { msgtype: "m.text", }, }); + matrixClient.pushRules = PushProcessor.rewriteDefaultRules(matrixClient.pushRules); pushProcessor = new PushProcessor(matrixClient); }); @@ -295,6 +297,21 @@ describe('NotificationService', function() { expect(actions.tweaks.highlight).toEqual(false); }); + it('should not bing on room server ACL changes', function() { + testEvent = utils.mkEvent({ + type: EventType.RoomServerAcl, + room: testRoomId, + user: "@alfred:localhost", + event: true, + content: {}, + }); + + const actions = pushProcessor.actionsForEvent(testEvent); + expect(actions.tweaks.highlight).toBeFalsy(); + expect(actions.tweaks.sound).toBeFalsy(); + expect(actions.notify).toBeFalsy(); + }); + // invalid it('should gracefully handle bad input.', function() { diff --git a/src/pushprocessor.ts b/src/pushprocessor.ts index 2f4f58bd4..5afe8505e 100644 --- a/src/pushprocessor.ts +++ b/src/pushprocessor.ts @@ -34,6 +34,7 @@ import { PushRuleSet, TweakName, } from "./@types/PushRules"; +import { EventType } from "./@types/event"; /** * @module pushprocessor @@ -96,6 +97,22 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [ PushRuleActionName.DontNotify, ], }, + { + // For homeservers which don't support MSC3786 yet + rule_id: ".org.matrix.msc3786.rule.room.server_acl", + default: true, + enabled: true, + conditions: [ + { + kind: ConditionKind.EventMatch, + key: "type", + pattern: EventType.RoomServerAcl, + }, + ], + actions: [ + PushRuleActionName.DontNotify, + ], + }, ]; export interface IActionsObject {