From d1af424b3fad847b725270f519e932275808a06e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 6 Sep 2017 10:56:08 +0100 Subject: [PATCH] allow hiding of notification body for privacy reasons Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Notifier.js | 22 ++++++++++++++++++---- src/UserSettingsStore.js | 11 +++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Notifier.js b/src/Notifier.js index 155564dcdf..93ef192fe0 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -80,10 +80,11 @@ const Notifier = { if (ev.getContent().body) msg = ev.getContent().body; } - const avatarUrl = ev.sender ? Avatar.avatarUrlForMember( - ev.sender, 40, 40, 'crop' - ) : null; + if (!this.isBodyEnabled()) { + msg = ''; + } + const avatarUrl = ev.sender ? Avatar.avatarUrlForMember(ev.sender, 40, 40, 'crop') : null; const notif = plaf.displayNotification(title, msg, avatarUrl, room); // if displayNotification returns non-null, the platform supports @@ -195,6 +196,19 @@ const Notifier = { return enabled === 'true'; }, + setBodyEnabled: function(enable) { + if (!global.localStorage) return; + global.localStorage.setItem('notifications_body_enabled', enable ? 'true' : 'false'); + }, + + isBodyEnabled: function() { + if (!global.localStorage) return true; + const enabled = global.localStorage.getItem('notifications_body_enabled'); + // default to true if the popups are enabled + if (enabled === null) return this.isEnabled(); + return enabled === 'true'; + }, + setAudioEnabled: function(enable) { if (!global.localStorage) return; global.localStorage.setItem('audio_notifications_enabled', @@ -303,7 +317,7 @@ const Notifier = { this._playAudioNotification(ev, room); } } - } + }, }; if (!global.mxNotifier) { diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index 68a1ba229f..ec95c99e6b 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -73,6 +73,17 @@ export default { Notifier.setEnabled(enable); }, + getEnableNotificationBody: function() { + return Notifier.isBodyEnabled(); + }, + + setEnableNotificationBody: function(enable) { + if (!Notifier.supportsDesktopNotifications()) { + return; + } + Notifier.setBodyEnabled(enable); + }, + getEnableAudioNotifications: function() { return Notifier.isAudioEnabled(); },