Skip to content

Commit

Permalink
Use an underride rule for Element Call notifications (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBrandner authored Nov 14, 2022
1 parent 692f1d4 commit b454318
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/pushprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit b454318

Please sign in to comment.