Ignore the default value when calculating if notifications are enabled

This is to make the "Enable desktop notifications" checkbox accurately reflect the user's preference. The device-level setting is still respected. 

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-12-25 13:29:30 -07:00
parent 6f674f21f6
commit 2815c576c1
3 changed files with 11 additions and 9 deletions

View file

@ -222,9 +222,9 @@ export default class SettingsStore {
if (explicit) { if (explicit) {
const handler = handlers[level]; const handler = handlers[level];
if (!handler) return SettingsStore._tryControllerOverride(settingName, level, roomId, null); if (!handler) return SettingsStore._tryControllerOverride(settingName, level, roomId, null, null);
const value = handler.getValue(settingName, roomId); const value = handler.getValue(settingName, roomId);
return SettingsStore._tryControllerOverride(settingName, level, roomId, value); return SettingsStore._tryControllerOverride(settingName, level, roomId, value, level);
} }
for (let i = minIndex; i < levelOrder.length; i++) { for (let i = minIndex; i < levelOrder.length; i++) {
@ -234,17 +234,17 @@ export default class SettingsStore {
const value = handler.getValue(settingName, roomId); const value = handler.getValue(settingName, roomId);
if (value === null || value === undefined) continue; if (value === null || value === undefined) continue;
return SettingsStore._tryControllerOverride(settingName, level, roomId, value); return SettingsStore._tryControllerOverride(settingName, level, roomId, value, levelOrder[i]);
} }
return SettingsStore._tryControllerOverride(settingName, level, roomId, null); return SettingsStore._tryControllerOverride(settingName, level, roomId, null, null);
} }
static _tryControllerOverride(settingName, level, roomId, calculatedValue) { static _tryControllerOverride(settingName, level, roomId, calculatedValue, calculatedAtLevel) {
const controller = SETTINGS[settingName].controller; const controller = SETTINGS[settingName].controller;
if (!controller) return calculatedValue; if (!controller) return calculatedValue;
const actualValue = controller.getValueOverride(level, roomId, calculatedValue); const actualValue = controller.getValueOverride(level, roomId, calculatedValue, calculatedAtLevel);
if (actualValue !== undefined && actualValue !== null) return actualValue; if (actualValue !== undefined && actualValue !== null) return actualValue;
return calculatedValue; return calculatedValue;
} }

View file

@ -35,11 +35,11 @@ function isMasterRuleEnabled() {
} }
export class NotificationsEnabledController extends SettingController { export class NotificationsEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) {
const Notifier = require('../../Notifier'); // avoids cyclical references const Notifier = require('../../Notifier'); // avoids cyclical references
if (!Notifier.isPossible()) return false; if (!Notifier.isPossible()) return false;
if (calculatedValue === null) { if (calculatedValue === null || calculatedAtLevel === "default") {
return isMasterRuleEnabled(); return isMasterRuleEnabled();
} }

View file

@ -31,9 +31,11 @@ export default class SettingController {
* @param {String} roomId The room ID, may be null. * @param {String} roomId The room ID, may be null.
* @param {*} calculatedValue The value that the handlers think the setting should be, * @param {*} calculatedValue The value that the handlers think the setting should be,
* may be null. * may be null.
* @param {string} calculatedAtLevel The level for which the calculated value was
* calculated at. May be null.
* @return {*} The value that should be used, or null if no override is applicable. * @return {*} The value that should be used, or null if no override is applicable.
*/ */
getValueOverride(level, roomId, calculatedValue) { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) {
return null; // no override return null; // no override
} }