Skip to content

Node.js based forum software built for the modern web

fix: hide unenterable rooms from the chat list (#14483)

palmoni52540ec8ebcef
diff --git a/src/messaging/index.js b/src/messaging/index.js
index d95dd09a31..28ca026a4c 100644
--- a/src/messaging/index.js
+++ b/src/messaging/index.js
@@ -197,6 +197,7 @@ Messaging.getRecentChats = async (callerUid, uid, start, stop) => {
const results = await utils.promiseParallel({
roomData: Messaging.getRoomsData(roomIds),
unread: db.isSortedSetMembers(`uid:${uid}:chat:rooms:unread`, roomIds),
+ inRoom: Messaging.isUserInRoom(uid, roomIds),
users: getUsers(roomIds, uid),
teasers: Messaging.getTeasers(uid, roomIds),
});
@@ -222,6 +223,7 @@ Messaging.searchRecentChats = async (callerUid, uid, query) => {
const results = await utils.promiseParallel({
roomData: Messaging.getRoomsData(roomIds),
unread: db.isSortedSetMembers(`uid:${uid}:chat:rooms:unread`, roomIds),
+ inRoom: Messaging.isUserInRoom(uid, roomIds),
users: getUsers(roomIds, uid),
teasers: Messaging.getTeasers(uid, roomIds),
});
@@ -254,7 +256,16 @@ Messaging.searchRecentChats = async (callerUid, uid, query) => {
};
async function modifyChatRooms(uid, results) {
+ const danglingRoomIds = [];
await Promise.all(results.roomData.map(async (room, index) => {
+ // Hide rooms the viewer cannot actually open, mirroring Messaging.loadRoom's
+ // visibility check. A private room the viewer is no longer a member of would
+ // otherwise show up as an empty/unenterable entry in the chat list.
+ if (room && !room.public && results.inRoom && !results.inRoom[index]) {
+ danglingRoomIds.push(room.roomId);
+ results.roomData[index] = null;
+ return;
+ }
if (room) {
room.users = results.users[index];
room.groupChat = room.users.length > 2;
@@ -273,6 +284,15 @@ async function modifyChatRooms(uid, results) {
}
}));
+ // Self-heal: drop dangling room references from the user's list so they don't
+ // keep showing up. These arise when the room set and membership set drift apart.
+ if (danglingRoomIds.length) {
+ await db.sortedSetRemove([
+ `uid:${uid}:chat:rooms`,
+ `uid:${uid}:chat:rooms:unread`,
+ ], danglingRoomIds);
+ }
+
return results.roomData.filter(Boolean);
}