Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Treat the master push rule as authoritative
Browse files Browse the repository at this point in the history
Previously the push rule was ignored, leading to all kinds of interesting issues regarding notifications. This fixes those issues by giving the master push rule the authority it deserves for reasonable defaults.

Part 2 of the fix for:
* element-hq/element-web#5603
* element-hq/element-web#5606

Signed-off-by: Travis Ralston <travpc@gmail.com>
  • Loading branch information
turt2live committed Nov 16, 2017
1 parent 5976fb2 commit 0f81f6a
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/settings/controllers/NotificationControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,36 @@ limitations under the License.
*/

import SettingController from "./SettingController";
import MatrixClientPeg from '../../MatrixClientPeg';

// XXX: This feels wrong.
import PushProcessor from "matrix-js-sdk/lib/pushprocessor";

function isMasterRuleEnabled(){
// Return the value of the master push rule as a default
const processor = new PushProcessor(MatrixClientPeg.get());
const masterRule = processor.getPushRuleById(".m.rule.master");

if (!masterRule) {
console.warn("No master push rule! Notifications are disabled for this user.");
return false;
}

// Why enabled == false means "enabled" is beyond me.
return !masterRule.enabled;
}

export class NotificationsEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references
if (!Notifier.isPossible()) return false;

if (calculatedValue === null || true) {
console.log(isMasterRuleEnabled());
return isMasterRuleEnabled();
}

return calculatedValue && Notifier.isPossible();
return calculatedValue;
}

onChange(level, roomId, newValue) {
Expand All @@ -35,15 +59,22 @@ export class NotificationsEnabledController extends SettingController {
export class NotificationBodyEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references
if (!Notifier.isPossible()) return false;

if (calculatedValue === null) {
return isMasterRuleEnabled();
}

return calculatedValue && Notifier.isEnabled();
return calculatedValue;
}
}

export class AudioNotificationsEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references
if (!Notifier.isPossible()) return false;

return calculatedValue && Notifier.isEnabled();
// Note: Audio notifications are *not* enabled by default.
return calculatedValue;
}
}

0 comments on commit 0f81f6a

Please sign in to comment.