From 1ff8e1e47db9edd77725615adc7d2bfcc9602486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 2 Feb 2025 18:57:54 -0500 Subject: [PATCH] fix: #13115, prevent messages from getting duplicated --- src/notifications.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) 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'); + + 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 }); } - notificationCache.set(cacheKey, { uids: results.uidsToEmail, notification }); - if (notification.bodyLong.length >= 1000) { - notificationCache.delete(cacheKey); - } - } 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; }