Treat the master push rule as authoritative

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:
* https://github.com/vector-im/riot-web/issues/5603
* https://github.com/vector-im/riot-web/issues/5606

Signed-off-by: Travis Ralston <travpc@gmail.com>
pull/21833/head
Travis Ralston 2017-11-15 22:09:40 -07:00
parent 5976fb2eed
commit fb1f20b7d4
1 changed files with 34 additions and 3 deletions

View File

@ -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;
return calculatedValue && Notifier.isPossible();
if (calculatedValue === null) {
console.log(isMasterRuleEnabled());
return isMasterRuleEnabled();
}
return calculatedValue;
}
onChange(level, roomId, newValue) {
@ -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;
return calculatedValue && Notifier.isEnabled();
if (calculatedValue === null) {
return isMasterRuleEnabled();
}
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;
}
}