From 493d3ae28859907010815dfbe4804247b6e79e15 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 14 Sep 2020 14:35:08 +0100 Subject: [PATCH 1/2] Don't show Notifications Prompt Toast if user has master rule enabled --- src/Notifier.ts | 3 ++- src/settings/controllers/NotificationControllers.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Notifier.ts b/src/Notifier.ts index 473de6c161..03f037be98 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -33,6 +33,7 @@ import Modal from './Modal'; import SettingsStore from "./settings/SettingsStore"; import { hideToast as hideNotificationsToast } from "./toasts/DesktopNotificationsToast"; import {SettingLevel} from "./settings/SettingLevel"; +import {isPushNotifyDisabled} from "./settings/controllers/NotificationControllers"; /* * Dispatches: @@ -302,7 +303,7 @@ export const Notifier = { return false; } const isGuest = client.isGuest(); - return !isGuest && this.supportsDesktopNotifications() && + return !isGuest && this.supportsDesktopNotifications() && !isPushNotifyDisabled() && !this.isEnabled() && !this._isToolbarHidden(); }, diff --git a/src/settings/controllers/NotificationControllers.ts b/src/settings/controllers/NotificationControllers.ts index bf5971d02e..323c64e9c3 100644 --- a/src/settings/controllers/NotificationControllers.ts +++ b/src/settings/controllers/NotificationControllers.ts @@ -24,7 +24,7 @@ import {PushProcessor} from "matrix-js-sdk/src/pushprocessor"; // .m.rule.master being enabled means all events match that push rule // default action on this rule is dont_notify, but it could be something else -function isPushNotifyDisabled(): boolean { +export function isPushNotifyDisabled(): boolean { // Return the value of the master push rule as a default const processor = new PushProcessor(MatrixClientPeg.get()); const masterRule = processor.getPushRuleById(".m.rule.master"); From 6b5426bddd7f882a818bbab5db46f70491ae8e5a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 15 Sep 2020 13:58:29 +0100 Subject: [PATCH 2/2] Rename toolbar Notifier methods to prompt --- src/Notifier.ts | 10 +++++----- src/components/structures/MatrixChat.tsx | 2 +- src/toasts/DesktopNotificationsToast.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Notifier.ts b/src/Notifier.ts index 03f037be98..2643de1abc 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -259,7 +259,7 @@ export const Notifier = { } // set the notifications_hidden flag, as the user has knowingly interacted // with the setting we shouldn't nag them any further - this.setToolbarHidden(true); + this.setPromptHidden(true); }, isEnabled: function() { @@ -284,7 +284,7 @@ export const Notifier = { return SettingsStore.getValue("audioNotificationsEnabled"); }, - setToolbarHidden: function(hidden: boolean, persistent = true) { + setPromptHidden: function(hidden: boolean, persistent = true) { this.toolbarHidden = hidden; Analytics.trackEvent('Notifier', 'Set Toolbar Hidden', hidden); @@ -297,17 +297,17 @@ export const Notifier = { } }, - shouldShowToolbar: function() { + shouldShowPrompt: function() { const client = MatrixClientPeg.get(); if (!client) { return false; } const isGuest = client.isGuest(); return !isGuest && this.supportsDesktopNotifications() && !isPushNotifyDisabled() && - !this.isEnabled() && !this._isToolbarHidden(); + !this.isEnabled() && !this._isPromptHidden(); }, - _isToolbarHidden: function() { + _isPromptHidden: function() { // Check localStorage for any such meta data if (global.localStorage) { return global.localStorage.getItem("notifications_hidden") === "true"; diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index d3d5835dae..4cdb58014e 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1344,7 +1344,7 @@ export default class MatrixChat extends React.PureComponent { this.firstSyncComplete = true; this.firstSyncPromise.resolve(); - if (Notifier.shouldShowToolbar()) { + if (Notifier.shouldShowPrompt()) { showNotificationsToast(); } diff --git a/src/toasts/DesktopNotificationsToast.ts b/src/toasts/DesktopNotificationsToast.ts index 413e82e20b..d8aa7647a3 100644 --- a/src/toasts/DesktopNotificationsToast.ts +++ b/src/toasts/DesktopNotificationsToast.ts @@ -24,7 +24,7 @@ const onAccept = () => { }; const onReject = () => { - Notifier.setToolbarHidden(true); + Notifier.setPromptHidden(true); }; const TOAST_KEY = "desktopnotifications";