mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #13115, limit bodyLength length
send out notification if bodyLong.length exceeds limit add a max item limit to ttl cache get rid of has/get check if item isn't in cache get returns undefined
This commit is contained in:
@@ -22,6 +22,7 @@ const Notifications = module.exports;
|
||||
|
||||
// ttlcache for email-only chat notifications
|
||||
const notificationCache = ttlCache({
|
||||
max: 1000,
|
||||
ttl: (meta.config.notificationSendDelay || 60) * 1000,
|
||||
noDisposeOnSet: true,
|
||||
dispose: sendEmail,
|
||||
@@ -246,11 +247,14 @@ async function pushToUids(uids, notification) {
|
||||
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
|
||||
if (delayNotificationTypes.includes(notification.type)) {
|
||||
const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
|
||||
if (notificationCache.has(cacheKey)) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
await sendEmail({ uids: results.uidsToEmail, notification });
|
||||
}
|
||||
@@ -264,8 +268,7 @@ async function pushToUids(uids, notification) {
|
||||
}
|
||||
|
||||
async function sendEmail({ uids, notification }, mergeId, reason) {
|
||||
// Only act on cache item expiry
|
||||
if (reason && reason !== 'stale') {
|
||||
if (reason && reason === 'set') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user