Skip to content

Node.js based forum software built for the modern web

fix: chat unread pushes kept going to the room's old members (#14905)

palmoni53e53f1ae0f2a
diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js
index e90efff43f..a38c7b9bb4 100644
--- a/src/messaging/rooms.js
+++ b/src/messaging/rooms.js
@@ -344,7 +344,7 @@ module.exports = function (Messaging) {
...groupChats.map(id => [`chat:room:${id}`, { groupChat: 1, userCount: countMap[id] }]),
...privateChats.map(id => [`chat:room:${id}`, { groupChat: 0, userCount: countMap[id] }]),
]);
- roomUidCache.del(roomIds.map(id => `chat:room:${id}:users`));
+ roomUidCache.del(roomIds.map(id => `chat:room:${id}:uids:online:all`));
}
Messaging.leaveRoom = async (uids, roomId) => {
diff --git a/test/messaging.js b/test/messaging.js
index e2c13922e2..22652acff3 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -1033,6 +1033,38 @@ describe('Messaging Library', () => {
});
});
+ describe('unread count pushes', () => {
+ it('should follow membership changes in a private room', async () => {
+ const ownerUid = await User.create({ username: utils.generateUUID().slice(0, 10) });
+ const leaverUid = await User.create({ username: utils.generateUUID().slice(0, 10) });
+ const lateUid = await User.create({ username: utils.generateUUID().slice(0, 10) });
+ const roomId = await Messaging.newRoom(ownerUid, { uids: [leaverUid] });
+
+ const pushedTo = [];
+ const { pushUnreadCount } = Messaging;
+ Messaging.pushUnreadCount = (uids, data) => {
+ pushedTo.push(uids.map(String));
+ return pushUnreadCount(uids, data);
+ };
+ try {
+ let message = await Messaging.sendMessage({ uid: ownerUid, roomId, content: 'before the leave' });
+ await Messaging.notifyUsersInRoom(ownerUid, roomId, message);
+
+ await Messaging.leaveRoom([leaverUid], roomId);
+ await Messaging.addUsersToRoom(ownerUid, [lateUid], roomId);
+
+ message = await Messaging.sendMessage({ uid: ownerUid, roomId, content: 'after the leave' });
+ await Messaging.notifyUsersInRoom(ownerUid, roomId, message);
+ } finally {
+ Messaging.pushUnreadCount = pushUnreadCount;
+ }
+
+ const lastPush = pushedTo.pop();
+ assert(!lastPush.includes(String(leaverUid)));
+ assert(lastPush.includes(String(lateUid)));
+ });
+ });
+
describe('.markRead()', () => {
const plugins = require('../src/plugins');
let markReadRoomId;