Skip to content

Commit f112d17

Browse files
authored
Merge pull request matrix-org#4782 from matrix-org/t3chguy/fix_desktop_notifs
clean up and fix the isMasterRuleEnabled logic
2 parents 68ca8b3 + ff98242 commit f112d17

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/settings/controllers/NotificationControllers.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ import {MatrixClientPeg} from '../../MatrixClientPeg';
2020
// XXX: This feels wrong.
2121
import {PushProcessor} from "matrix-js-sdk/src/pushprocessor";
2222

23-
function isMasterRuleEnabled() {
23+
// .m.rule.master being enabled means all events match that push rule
24+
// default action on this rule is dont_notify, but it could be something else
25+
function isPushNotifyDisabled() {
2426
// Return the value of the master push rule as a default
2527
const processor = new PushProcessor(MatrixClientPeg.get());
2628
const masterRule = processor.getPushRuleById(".m.rule.master");
2729

2830
if (!masterRule) {
2931
console.warn("No master push rule! Notifications are disabled for this user.");
30-
return false;
32+
return true;
3133
}
3234

33-
// Why enabled == false means "enabled" is beyond me.
34-
return !masterRule.enabled;
35+
// If the rule is enabled then check it does not notify on everything
36+
return masterRule.enabled && !masterRule.actions.includes("notify");
3537
}
3638

3739
function getNotifier() {
@@ -45,7 +47,7 @@ export class NotificationsEnabledController extends SettingController {
4547
if (!getNotifier().isPossible()) return false;
4648

4749
if (calculatedValue === null || calculatedAtLevel === "default") {
48-
return !isMasterRuleEnabled();
50+
return !isPushNotifyDisabled();
4951
}
5052

5153
return calculatedValue;
@@ -63,7 +65,7 @@ export class NotificationBodyEnabledController extends SettingController {
6365
if (!getNotifier().isPossible()) return false;
6466

6567
if (calculatedValue === null) {
66-
return !isMasterRuleEnabled();
68+
return !isPushNotifyDisabled();
6769
}
6870

6971
return calculatedValue;

0 commit comments

Comments
 (0)