Skip to content

Commit b454318

Browse files
Use an underride rule for Element Call notifications (#2873)
1 parent 692f1d4 commit b454318

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/pushprocessor.ts

+22
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [
9393
],
9494
actions: [],
9595
},
96+
];
97+
98+
const DEFAULT_UNDERRIDE_RULES: IPushRule[] = [
9699
{
97100
// For homeservers which don't support MSC3914 yet
98101
rule_id: ".org.matrix.msc3914.rule.room.call",
@@ -163,6 +166,7 @@ export class PushProcessor {
163166
if (!newRules) newRules = {} as IPushRules;
164167
if (!newRules.global) newRules.global = {} as PushRuleSet;
165168
if (!newRules.global.override) newRules.global.override = [];
169+
if (!newRules.global.override) newRules.global.underride = [];
166170

167171
// Merge the client-level defaults with the ones from the server
168172
const globalOverrides = newRules.global.override;
@@ -183,6 +187,24 @@ export class PushProcessor {
183187
}
184188
}
185189

190+
const globalUnderrides = newRules.global.underride ?? [];
191+
for (const underride of DEFAULT_UNDERRIDE_RULES) {
192+
const existingRule = globalUnderrides
193+
.find((r) => r.rule_id === underride.rule_id);
194+
195+
if (existingRule) {
196+
// Copy over the actions, default, and conditions. Don't touch the user's preference.
197+
existingRule.default = underride.default;
198+
existingRule.conditions = underride.conditions;
199+
existingRule.actions = underride.actions;
200+
} else {
201+
// Add the rule
202+
const ruleId = underride.rule_id;
203+
logger.warn(`Adding default global underride for ${ruleId}`);
204+
globalUnderrides.push(underride);
205+
}
206+
}
207+
186208
return newRules;
187209
}
188210

0 commit comments

Comments
 (0)