Skip to content

Node.js based forum software built for the modern web

fix: #13115, prevent messages from getting duplicated

Barış Soner Uşaklı1ff8e1e47db9
diff --git a/src/notifications.js b/src/notifications.js
index 65804da6ab..7f7bb5268a 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -243,20 +243,25 @@ async function pushToUids(uids, notification) {
if (notification.type) {
results = await getUidsBySettings(data.uids);
}
+
await sendNotification(results.uidsToNotify);
- const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
- if (delayNotificationTypes.includes(notification.type)) {
- const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
- const payload = notificationCache.get(cacheKey);
- if (payload !== undefined) {
- notification.bodyLong = [payload.notification.bodyLong, notification.bodyLong].join('\n');
- }
- notificationCache.set(cacheKey, { uids: results.uidsToEmail, notification });
- if (notification.bodyLong.length >= 1000) {
- notificationCache.delete(cacheKey);
+
+ if (results.uidsToEmail.length) {
+ const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
+ if (delayNotificationTypes.includes(notification.type)) {
+ const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
+ const payload = notificationCache.get(cacheKey);
+ let { bodyLong } = notification;
+ if (payload !== undefined) {
+ bodyLong = [payload.notification.bodyLong, bodyLong].join('\n');
+ }
+ notificationCache.set(cacheKey, { uids: results.uidsToEmail, notification: { ...notification, bodyLong } });
+ if (notification.bodyLong.length >= 1000) {
+ notificationCache.delete(cacheKey);
+ }
+ } else {
+ await sendEmail({ uids: results.uidsToEmail, notification });
}
- } else {
- await sendEmail({ uids: results.uidsToEmail, notification });
}
plugins.hooks.fire('action:notification.pushed', {
@@ -268,7 +273,7 @@ async function pushToUids(uids, notification) {
}
async function sendEmail({ uids, notification }, mergeId, reason) {
- if (reason && reason === 'set') {
+ if ((reason && reason === 'set') || !uids.length) {
return;
}