1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Use an underride rule for Element Call notifications (#2873)

This commit is contained in:
Šimon Brandner
2022-11-14 11:42:51 +01:00
committed by GitHub
parent 692f1d49b9
commit b454318684

View File

@@ -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;
}