From b3be11ba474ccf76c8a7c4d92d4ffbbd584dccd7 Mon Sep 17 00:00:00 2001
From: mpDBL <44492966+mpdbl@users.noreply.github.com>
Date: Thu, 21 Nov 2019 01:28:19 +0100
Subject: [PATCH] [NEW] Setting to dismiss desktop notification only after
interaction (#14807)
* added default and user specific setting for desktop notification
* added parameter to REST API endpoint users.setPreferences require user interaction setting of desktop notifications
* added usage of user specific setting 'desktopNotificationRequireInteraction'
* added descriptions for user preference and default setting
* add descriptions and label texts
---
app/api/server/v1/users.js | 1 +
app/lib/server/startup/settings.js | 6 ++++++
app/ui-account/client/accountPreferences.html | 8 ++++++++
app/ui-account/client/accountPreferences.js | 13 +++++++++++++
app/ui/client/lib/notification.js | 1 +
packages/rocketchat-i18n/i18n/de-IN.i18n.json | 3 +++
packages/rocketchat-i18n/i18n/de.i18n.json | 3 +++
packages/rocketchat-i18n/i18n/en.i18n.json | 3 +++
tests/data/user.js | 1 +
tests/end-to-end/api/00-miscellaneous.js | 1 +
10 files changed, 40 insertions(+)
diff --git a/app/api/server/v1/users.js b/app/api/server/v1/users.js
index 49bcd0426c1..ec3a3090a47 100644
--- a/app/api/server/v1/users.js
+++ b/app/api/server/v1/users.js
@@ -512,6 +512,7 @@ API.v1.addRoute('users.setPreferences', { authRequired: true }, {
enableAutoAway: Match.Maybe(Boolean),
highlights: Match.Maybe(Array),
desktopNotificationDuration: Match.Maybe(Number),
+ desktopNotificationRequireInteraction: Match.Maybe(Boolean),
messageViewMode: Match.Maybe(Number),
hideUsernames: Match.Maybe(Boolean),
hideRoles: Match.Maybe(Boolean),
diff --git a/app/lib/server/startup/settings.js b/app/lib/server/startup/settings.js
index cef860175cb..2340fd5dff3 100644
--- a/app/lib/server/startup/settings.js
+++ b/app/lib/server/startup/settings.js
@@ -225,6 +225,12 @@ settings.addGroup('Accounts', function() {
public: true,
i18nLabel: 'Notification_Duration',
});
+ this.add('Accounts_Default_User_Preferences_desktopNotificationRequireInteraction', false, {
+ type: 'boolean',
+ public: true,
+ i18nLabel: 'Notification_RequireInteraction',
+ i18nDescription: 'Notification_RequireInteraction_Description',
+ });
this.add('Accounts_Default_User_Preferences_audioNotifications', 'mentions', {
type: 'select',
values: [
diff --git a/app/ui-account/client/accountPreferences.html b/app/ui-account/client/accountPreferences.html
index 4b1ded75dd7..4e91e24964a 100644
--- a/app/ui-account/client/accountPreferences.html
+++ b/app/ui-account/client/accountPreferences.html
@@ -102,6 +102,14 @@
{{/if}}
+
diff --git a/app/ui-account/client/accountPreferences.js b/app/ui-account/client/accountPreferences.js
index 35c148a70d7..279a910f0c5 100644
--- a/app/ui-account/client/accountPreferences.js
+++ b/app/ui-account/client/accountPreferences.js
@@ -90,6 +90,13 @@ Template.accountPreferences.helpers({
defaultDesktopNotificationDuration() {
return settings.get('Accounts_Default_User_Preferences_desktopNotificationDuration');
},
+ desktopNotificationRequireInteraction() {
+ const userPref = getUserPreference(Meteor.userId(), 'desktopNotificationRequireInteraction', 'undefined');
+ return userPref !== 'undefined' ? userPref : undefined;
+ },
+ defaultDesktopNotificationRequireInteraction() {
+ return settings.get('Accounts_Default_User_Preferences_desktopNotificationRequireInteraction');
+ },
idleTimeLimit() {
return getUserPreference(Meteor.userId(), 'idleTimeLimit');
},
@@ -189,6 +196,12 @@ Template.accountPreferences.onCreated(function() {
data.hideRoles = JSON.parse($('#hideRoles').find('input:checked').val());
}
+ if ($('input[name=desktopNotificationRequireInteraction]:checked').val() === undefined) {
+ data.desktopNotificationRequireInteraction = settings.get('Accounts_Default_User_Preferences_desktopNotificationRequireInteraction');
+ } else {
+ data.desktopNotificationRequireInteraction = JSON.parse($('input[name=desktopNotificationRequireInteraction]:checked').val());
+ }
+
// if highlights changed we need page reload
const highlights = getUserPreference(Meteor.userId(), 'highlights');
if (highlights && highlights.join('\n') !== data.highlights.join('\n')) {
diff --git a/app/ui/client/lib/notification.js b/app/ui/client/lib/notification.js
index 60b55200b46..6e5c09b8228 100644
--- a/app/ui/client/lib/notification.js
+++ b/app/ui/client/lib/notification.js
@@ -41,6 +41,7 @@ export const KonchatNotification = {
tag: notification.payload._id,
silent: true,
canReply: true,
+ requireInteraction: getUserPreference(Meteor.userId(), 'desktopNotificationRequireInteraction'),
});
const notificationDuration = notification.duration - 0 || getUserPreference(Meteor.userId(), 'desktopNotificationDuration') - 0;
diff --git a/packages/rocketchat-i18n/i18n/de-IN.i18n.json b/packages/rocketchat-i18n/i18n/de-IN.i18n.json
index 83967590fd9..340256a7d21 100644
--- a/packages/rocketchat-i18n/i18n/de-IN.i18n.json
+++ b/packages/rocketchat-i18n/i18n/de-IN.i18n.json
@@ -2164,6 +2164,8 @@
"Not_Imported_Messages_Title": "Der Import folgender Nachrichten schlug fehl",
"Notification_Desktop_Default_For": "Desktop-Benachrichtigungen anzeigen für",
"Notification_Duration": "Benachrichtigungsdauer",
+ "Notification_RequireInteraction": "Der Benutzer muss mit der Desktop-Benachrichtigung interagieren um diese auszublenden",
+ "Notification_RequireInteraction_Description": "Verwendung nur mit Chrome Browser Version > 50 möglich. Verwendet den Parameter requireInteraction um die Anzeigedauer der Desktop-Benachrichtigung bis zur Benutzerinteraktion zu verlängern.",
"Notification_Mobile_Default_For": "Mobile Benachrichtigungen anzeigen für",
"Notifications": "Benachrichtigungen",
"Notifications_Always_Notify_Mobile": "Immer das Mobiltelefon benachrichtigen",
@@ -2212,6 +2214,7 @@
"Only_authorized_users_can_write_new_messages": "Nur Authentifizierte Benutzer können neue Nachrichten schreiben",
"Only_from_users": "Löscht nur den Inhalt dieser Benutzer",
"Only_On_Desktop": "Desktop Modus (senden mit der Eingabeaste nur auf dem Desktop PC)",
+ "Only_works_with_chrome_version_greater_50": "Funktioniert nur mit Chrome Browser Versionen > 50",
"Only_you_can_see_this_message": "Nur Du kannst diese Nachricht sehen",
"Oops!": "Hoppla",
"Oops_page_not_found": "Hoppla, Seite nicht gefunden",
diff --git a/packages/rocketchat-i18n/i18n/de.i18n.json b/packages/rocketchat-i18n/i18n/de.i18n.json
index 5d52710c630..50f973a2539 100644
--- a/packages/rocketchat-i18n/i18n/de.i18n.json
+++ b/packages/rocketchat-i18n/i18n/de.i18n.json
@@ -2316,6 +2316,8 @@
"Not_Imported_Messages_Title": "Der Import folgender Nachrichten schlug fehl",
"Notification_Desktop_Default_For": "Desktop-Benachrichtigungen anzeigen für",
"Notification_Duration": "Benachrichtigungsdauer",
+ "Notification_RequireInteraction": "Benutzerinteraktion notwendig um Benachrichtigung auszublenden",
+ "Notification_RequireInteraction_Description": "Verwendung nur mit Chrome Browser Version > 50 möglich. Verwendet den Parameter requireInteraction um die Anzeigedauer der Desktop-Benachrichtigung bis zur Benutzerinteraktion zu verlängern.",
"Notification_Mobile_Default_For": "Mobile Benachrichtigungen anzeigen für",
"Notifications": "Benachrichtigungen",
"Notifications_Always_Notify_Mobile": "Immer das Mobiltelefon benachrichtigen",
@@ -2362,6 +2364,7 @@
"Only_authorized_users_can_write_new_messages": "Nur Authentifizierte Benutzer können neue Nachrichten schreiben",
"Only_from_users": "Löscht nur den Inhalt dieser Benutzer (lassen Sie den Inhalt leer)",
"Only_On_Desktop": "Desktop Modus (senden mit der Eingabeaste nur auf dem Desktop PC)",
+ "Only_works_with_chrome_version_greater_50": "Funktioniert nur mit Chrome Browser Versionen > 50",
"Only_you_can_see_this_message": "Nur Sie können diese Nachricht sehen",
"Oops!": "Hoppla",
"Oops_page_not_found": "Hoppla, Seite nicht gefunden",
diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json
index 0a4d67b627f..486d9229156 100644
--- a/packages/rocketchat-i18n/i18n/en.i18n.json
+++ b/packages/rocketchat-i18n/i18n/en.i18n.json
@@ -2328,6 +2328,8 @@
"Not_Imported_Messages_Title": "The following messages were not imported successfully",
"Notification_Desktop_Default_For": "Show Desktop Notifications For",
"Notification_Duration": "Notification Duration",
+ "Notification_RequireInteraction": "Require Interaction to Dismiss Desktop Notification",
+ "Notification_RequireInteraction_Description": "Works only with Chrome browser versions > 50. Utilizes the parameter requireInteraction to show the desktop notification to indefinite until the user interacts with it.",
"Notification_Mobile_Default_For": "Push Mobile Notifications For",
"Notifications": "Notifications",
"Notifications_Always_Notify_Mobile": "Always notify mobile",
@@ -2375,6 +2377,7 @@
"Only_authorized_users_can_write_new_messages": "Only authorized users can write new messages",
"Only_from_users": "Only prune content from these users (leave empty to prune everyone's content)",
"Only_On_Desktop": "Desktop mode (only sends with enter on desktop)",
+ "Only_works_with_chrome_version_greater_50": "Only works with Chrome browser versions > 50",
"Only_you_can_see_this_message": "Only you can see this message",
"Oops!": "Oops",
"Oops_page_not_found": "Oops, page not found",
diff --git a/tests/data/user.js b/tests/data/user.js
index 2dd53e72132..eb89086973b 100644
--- a/tests/data/user.js
+++ b/tests/data/user.js
@@ -24,6 +24,7 @@ export const preferences = {
enableAutoAway: true,
highlights: [],
desktopNotificationDuration: 0,
+ desktopNotificationRequireInteraction: false,
messageViewMode: 0,
hideUsernames: false,
hideRoles: false,
diff --git a/tests/end-to-end/api/00-miscellaneous.js b/tests/end-to-end/api/00-miscellaneous.js
index 3a6773fa2ba..32fc0632192 100644
--- a/tests/end-to-end/api/00-miscellaneous.js
+++ b/tests/end-to-end/api/00-miscellaneous.js
@@ -125,6 +125,7 @@ describe('miscellaneous', function() {
'enableAutoAway',
// 'highlights',
'desktopNotificationDuration',
+ 'desktopNotificationRequireInteraction',
'messageViewMode',
'hideUsernames',
'hideRoles',