mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #13115, prevent messages from getting duplicated
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user