diff --git a/src/pushprocessor.ts b/src/pushprocessor.ts index 065eab19218..7c127d4c7ca 100644 --- a/src/pushprocessor.ts +++ b/src/pushprocessor.ts @@ -93,6 +93,9 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [ ], actions: [], }, +]; + +const DEFAULT_UNDERRIDE_RULES: IPushRule[] = [ { // For homeservers which don't support MSC3914 yet rule_id: ".org.matrix.msc3914.rule.room.call", @@ -163,6 +166,7 @@ export class PushProcessor { if (!newRules) newRules = {} as IPushRules; if (!newRules.global) newRules.global = {} as PushRuleSet; if (!newRules.global.override) newRules.global.override = []; + if (!newRules.global.override) newRules.global.underride = []; // Merge the client-level defaults with the ones from the server const globalOverrides = newRules.global.override; @@ -183,6 +187,24 @@ export class PushProcessor { } } + const globalUnderrides = newRules.global.underride ?? []; + for (const underride of DEFAULT_UNDERRIDE_RULES) { + const existingRule = globalUnderrides + .find((r) => r.rule_id === underride.rule_id); + + if (existingRule) { + // Copy over the actions, default, and conditions. Don't touch the user's preference. + existingRule.default = underride.default; + existingRule.conditions = underride.conditions; + existingRule.actions = underride.actions; + } else { + // Add the rule + const ruleId = underride.rule_id; + logger.warn(`Adding default global underride for ${ruleId}`); + globalUnderrides.push(underride); + } + } + return newRules; }