Skip to content

Node.js based forum software built for the modern web

fix: chat message flag notifications went to global moderators (#14888)

palmoni597de7b82293b
diff --git a/src/flags.js b/src/flags.js
index 0d1dd0c760..be876cb767 100644
--- a/src/flags.js
+++ b/src/flags.js
@@ -1013,6 +1013,7 @@ Flags.notify = async function (flagObj, uid, notifySelf = false) {
targetDisplayname: targetDisplayname,
});
} else if (flagObj.type === 'message') {
+ uids = admins;
const roomId = await messaging.getRoomIdByMid(flagObj.targetId);
const roomData = roomId ? await messaging.getRoomData(roomId) : null;
const targetDisplayname = await user.getNotificationDisplayname(flagObj.targetUid);
diff --git a/test/flags.js b/test/flags.js
index 3c96c3ee57..3e13663bca 100644
--- a/test/flags.js
+++ b/test/flags.js
@@ -728,6 +728,22 @@ describe('Flags', () => {
});
});
+ describe('.notify()', () => {
+ it('should only notify administrators of a chat message flag', async () => {
+ const globalModUid = await User.create({ username: 'message-flag-global-mod' });
+ await Groups.join('Global Moderators', globalModUid);
+
+ const roomId = await messaging.newRoom(uid1, { uids: [uid3] });
+ const { mid } = await messaging.sendMessage({ uid: uid3, roomId, content: 'private chat content' });
+ await api.flags.create({ uid: uid1 }, { type: 'message', id: mid, reason: 'spam', roomId });
+ await sleep(2000);
+
+ const nid = `flag:message:${mid}:${uid1}`;
+ assert(await db.isSortedSetMember(`uid:${adminUid}:notifications:unread`, nid));
+ assert(!await db.isSortedSetMember(`uid:${globalModUid}:notifications:unread`, nid));
+ });
+ });
+
describe('.getTarget()', () => {
it('should return a post\'s data if queried with type "post"', (done) => {
Flags.getTarget('post', 1, 1, (err, data) => {