diff --git a/public/language/en-GB/admin/settings/chat.json b/public/language/en-GB/admin/settings/chat.json
index 6d6cad284b..b491a3104b 100644
--- a/public/language/en-GB/admin/settings/chat.json
+++ b/public/language/en-GB/admin/settings/chat.json
@@ -10,8 +10,6 @@
"max-chat-room-name-length": "Maximum length of chat room names",
"max-room-size": "Maximum number of users in chat rooms",
"delay": "Time between chat messages (ms)",
- "notification-delay": "Notification delay for chat messages",
- "notification-delay-help": "Additional messages sent between this time are collated, and the user is notified once per delay period. Set this to 0 to disable the delay.",
"restrictions.seconds-edit-after": "Number of seconds a chat message will remain editable.",
"restrictions.seconds-delete-after": "Number of seconds a chat message will remain deletable."
}
\ No newline at end of file
diff --git a/public/language/en-GB/admin/settings/notifications.json b/public/language/en-GB/admin/settings/notifications.json
index c6d8b928ce..a2f82b82fb 100644
--- a/public/language/en-GB/admin/settings/notifications.json
+++ b/public/language/en-GB/admin/settings/notifications.json
@@ -3,5 +3,7 @@
"welcome-notification": "Welcome Notification",
"welcome-notification-link": "Welcome Notification Link",
"welcome-notification-uid": "Welcome Notification User (UID)",
- "post-queue-notification-uid": "Post Queue User (UID)"
+ "post-queue-notification-uid": "Post Queue User (UID)",
+ "notification-delay": "Delay for sending notification emails (seconds)",
+ "notification-delay-help": "If the user has read the notification within this time, the email will not be sent.
Default: 60 seconds."
}
\ No newline at end of file
diff --git a/src/notifications.js b/src/notifications.js
index e7db55cf99..6aa5088594 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -282,7 +282,10 @@ async function pushToUids(uids, notification) {
notificationCache.delete(cacheKey);
}
} else {
- await sendEmail({ uids: results.uidsToEmail, notification });
+ notificationCache.set(`delayed:nid:${notification.nid}`, {
+ uids: results.uidsToEmail,
+ notification,
+ });
}
}
@@ -294,11 +297,22 @@ async function pushToUids(uids, notification) {
});
}
-async function sendEmail({ uids, notification }, mergeId, reason) {
+async function sendEmail({ uids, notification }, cacheKey, reason) {
if ((reason && reason === 'set') || !uids.length) {
return;
}
+ // check if notification already read by users
+ // if so don't send email, https://github.com/NodeBB/NodeBB/issues/5867
+ const hasRead = await db.isMemberOfSortedSets(
+ uids.map(uid => `uid:${uid}:notifications:read`),
+ notification.nid
+ );
+ uids = uids.filter((uid, index) => !hasRead[index]);
+ if (!uids.length) {
+ return;
+ }
+
// Update CTA messaging (as not all notification types need custom text)
if (['new-reply', 'new-chat'].includes(notification.type)) {
notification['cta-type'] = notification.type;
diff --git a/src/views/admin/settings/chat.tpl b/src/views/admin/settings/chat.tpl
index df1c4e21e0..920783c2bd 100644
--- a/src/views/admin/settings/chat.tpl
+++ b/src/views/admin/settings/chat.tpl
@@ -59,12 +59,6 @@
-
-
[[admin/settings/chat:notification-delay-help]]
-[[admin/settings/notifications:notification-delay-help]]
+