Node.js based forum software built for the modern web
fix: merge notifications for flags on the same chat message (#14866)
palmoni5a8d93e12303e
diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.jsonindex f4053fbd32..2226ac5356 100644--- a/public/language/en-GB/notifications.json+++ b/public/language/en-GB/notifications.json@@ -51,6 +51,9 @@"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)","user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)","user-flagged-message": "<strong>%1</strong> flagged a chat message in <strong>%2</strong>",+ "user-flagged-message-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a chat message in <strong>%3</strong>",+ "user-flagged-message-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a chat message in <strong>%4</strong>",+ "user-flagged-message-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a chat message in <strong>%4</strong>","user-posted-to" : "<strong>%1</strong> posted a reply in <strong>%2</strong>","user-posted-to-dual" : "<strong>%1</strong> and <strong>%2</strong> replied in <strong>%3</strong>","user-posted-to-triple" : "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> replied in <strong>%4</strong>",diff --git a/src/flags.js b/src/flags.jsindex 0b78eaf975..0d1dd0c760 100644--- a/src/flags.js+++ b/src/flags.js@@ -1016,18 +1016,20 @@ Flags.notify = async function (flagObj, uid, notifySelf = false) {const roomId = await messaging.getRoomIdByMid(flagObj.targetId);const roomData = roomId ? await messaging.getRoomData(roomId) : null;const targetDisplayname = await user.getNotificationDisplayname(flagObj.targetUid);+ const roomName = roomData?.roomName || targetDisplayname;let bodyLong = String(flagObj.target?.content || '');if (bodyLong && bodyLong.length > 500) {bodyLong = bodyLong.substring(0, 497) + '...';}notifObj = await notifications.create({type: 'new-message-flag',- bodyShort: translator.compile('notifications:user-flagged-message', displayname, roomData?.roomName || targetDisplayname),+ bodyShort: translator.compile('notifications:user-flagged-message', displayname, roomName),bodyLong: bodyLong,path: `/flags/${flagObj.flagId}`,nid: `flag:message:${flagObj.targetId}:${uid}`,from: uid,mergeId: `notifications:user-flagged-message|${flagObj.targetId}`,+ roomName: roomName,});} else {throw new Error('[[error:invalid-data]]');diff --git a/src/notifications.js b/src/notifications.jsindex 8bdd545930..7400ca8206 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -516,6 +516,7 @@ Notifications.merge = async function (notifications) {'notifications:user-posted-to','notifications:user-flagged-post-in','notifications:user-flagged-user',+ 'notifications:user-flagged-message','new-chat','notifications:user-posted-in-public-room','new-register',@@ -564,6 +565,13 @@ Notifications.merge = async function (notifications) {break;}+ case 'notifications:user-flagged-message': {+ buildMergedNotif(mergeId, notifObj, set, [+ tx.escape(notifObj.roomName),+ ]);+ break;+ }+case 'notifications:user-posted-in-public-room': {buildMergedNotif(mergeId, notifObj, set, [notifObj.roomIcon, tx.escape(notifObj.roomName),