fix: #13115, prevent messages from getting duplicated

This commit is contained in:
Barış Soner Uşaklı
2025-02-02 18:57:54 -05:00
parent 8e9fdb5fd6
commit 1ff8e1e47d

View File

@@ -243,20 +243,25 @@ async function pushToUids(uids, notification) {
if (notification.type) { if (notification.type) {
results = await getUidsBySettings(data.uids); results = await getUidsBySettings(data.uids);
} }
await sendNotification(results.uidsToNotify); await sendNotification(results.uidsToNotify);
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
if (delayNotificationTypes.includes(notification.type)) { if (results.uidsToEmail.length) {
const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`; const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
const payload = notificationCache.get(cacheKey); if (delayNotificationTypes.includes(notification.type)) {
if (payload !== undefined) { const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
notification.bodyLong = [payload.notification.bodyLong, notification.bodyLong].join('\n'); 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', { plugins.hooks.fire('action:notification.pushed', {
@@ -268,7 +273,7 @@ async function pushToUids(uids, notification) {
} }
async function sendEmail({ uids, notification }, mergeId, reason) { async function sendEmail({ uids, notification }, mergeId, reason) {
if (reason && reason === 'set') { if ((reason && reason === 'set') || !uids.length) {
return; return;
} }