From 18ac2db2ea5c44de4153efbf133b8085ba613075 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 20 Dec 2019 14:47:49 -0700 Subject: [PATCH] Fix Notifier imports in NotificationControllers require() is a bit weird for riot-web's webpack, so we fork it out to its own function to reduce the weirdness. The added weirdness is that require() is sync though exports a module instead. If we use import(), we get a promise which doesn't help us here. We therefore have to require() and pull out the default export, though this is only a problem for webpack - babel (our chosen compiler for exporting ES6) doesn't need this, hence the if statement. --- .../controllers/NotificationControllers.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/settings/controllers/NotificationControllers.js b/src/settings/controllers/NotificationControllers.js index ada4155206..395da765a1 100644 --- a/src/settings/controllers/NotificationControllers.js +++ b/src/settings/controllers/NotificationControllers.js @@ -34,10 +34,15 @@ function isMasterRuleEnabled() { return !masterRule.enabled; } +function getNotifier() { + let Notifier = require('../../Notifier'); // avoids cyclical references + if (Notifier.default) Notifier = Notifier.default; // correct for webpack require() weirdness + return Notifier; +} + export class NotificationsEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; if (calculatedValue === null || calculatedAtLevel === "default") { return isMasterRuleEnabled(); @@ -47,18 +52,15 @@ export class NotificationsEnabledController extends SettingController { } onChange(level, roomId, newValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - - if (Notifier.supportsDesktopNotifications()) { - Notifier.setEnabled(newValue); + if (getNotifier().supportsDesktopNotifications()) { + getNotifier().setEnabled(newValue); } } } export class NotificationBodyEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; if (calculatedValue === null) { return isMasterRuleEnabled(); @@ -70,8 +72,7 @@ export class NotificationBodyEnabledController extends SettingController { export class AudioNotificationsEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; // Note: Audio notifications are *not* enabled by default. return calculatedValue;