clean up and fix the isMasterRuleEnabled logic

pull/21833/head
Michael Telatynski 2020-06-17 16:31:42 +01:00
parent 17476a5e73
commit ff98242d14
1 changed files with 8 additions and 6 deletions

View File

@ -20,18 +20,20 @@ import {MatrixClientPeg} from '../../MatrixClientPeg';
// XXX: This feels wrong. // XXX: This feels wrong.
import {PushProcessor} from "matrix-js-sdk/src/pushprocessor"; import {PushProcessor} from "matrix-js-sdk/src/pushprocessor";
function isMasterRuleEnabled() { // .m.rule.master being enabled means all events match that push rule
// default action on this rule is dont_notify, but it could be something else
function isPushNotifyDisabled() {
// Return the value of the master push rule as a default // Return the value of the master push rule as a default
const processor = new PushProcessor(MatrixClientPeg.get()); const processor = new PushProcessor(MatrixClientPeg.get());
const masterRule = processor.getPushRuleById(".m.rule.master"); const masterRule = processor.getPushRuleById(".m.rule.master");
if (!masterRule) { if (!masterRule) {
console.warn("No master push rule! Notifications are disabled for this user."); console.warn("No master push rule! Notifications are disabled for this user.");
return false; return true;
} }
// Why enabled == false means "enabled" is beyond me. // If the rule is enabled then check it does not notify on everything
return !masterRule.enabled; return masterRule.enabled && !masterRule.actions.includes("notify");
} }
function getNotifier() { function getNotifier() {
@ -45,7 +47,7 @@ export class NotificationsEnabledController extends SettingController {
if (!getNotifier().isPossible()) return false; if (!getNotifier().isPossible()) return false;
if (calculatedValue === null || calculatedAtLevel === "default") { if (calculatedValue === null || calculatedAtLevel === "default") {
return !isMasterRuleEnabled(); return !isPushNotifyDisabled();
} }
return calculatedValue; return calculatedValue;
@ -63,7 +65,7 @@ export class NotificationBodyEnabledController extends SettingController {
if (!getNotifier().isPossible()) return false; if (!getNotifier().isPossible()) return false;
if (calculatedValue === null) { if (calculatedValue === null) {
return !isMasterRuleEnabled(); return !isPushNotifyDisabled();
} }
return calculatedValue; return calculatedValue;