Merge pull request #5203 from matrix-org/t3chguy/fix/15150

Don't show Notifications Prompt Toast if user has master rule enabled
This commit is contained in:
Michael Telatynski 2020-09-15 14:09:38 +01:00 committed by GitHub
commit 9a3c30b1f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View file

@ -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:
@ -258,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() {
@ -283,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);
@ -296,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() &&
!this.isEnabled() && !this._isToolbarHidden();
return !isGuest && this.supportsDesktopNotifications() && !isPushNotifyDisabled() &&
!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";

View file

@ -1344,7 +1344,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.firstSyncComplete = true;
this.firstSyncPromise.resolve();
if (Notifier.shouldShowToolbar()) {
if (Notifier.shouldShowPrompt()) {
showNotificationsToast();
}

View file

@ -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");

View file

@ -24,7 +24,7 @@ const onAccept = () => {
};
const onReject = () => {
Notifier.setToolbarHidden(true);
Notifier.setPromptHidden(true);
};
const TOAST_KEY = "desktopnotifications";