From aeb27f4b8d6b3cbc2eff10f7349d3268fd07bd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 18 Aug 2023 21:41:00 -0400 Subject: [PATCH] fix: admins should see public chats even if they are not in any of the groups --- src/messaging/index.js | 11 +++++++++-- src/messaging/rooms.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/messaging/index.js b/src/messaging/index.js index 5199345720..0d58e0c019 100644 --- a/src/messaging/index.js +++ b/src/messaging/index.js @@ -130,11 +130,13 @@ Messaging.getPublicRooms = async (callerUid, uid) => { const allRoomIds = await Messaging.getPublicRoomIdsFromSet('chat:rooms:public:order'); const allRoomData = await Messaging.getRoomsData(allRoomIds); + const isAdmin = await privileges.users.isAdministrator(callerUid); const checks = await Promise.all( allRoomData.map( room => room && ( !Array.isArray(room.groups) || !room.groups.length || + isAdmin || groups.isMemberOfAny(uid, room && room.groups) ) ) @@ -369,16 +371,21 @@ Messaging.canMessageUser = async (uid, toUid) => { }; Messaging.canMessageRoom = async (uid, roomId) => { + console.log('can message room', uid, roomId); if (meta.config.disableChat || uid <= 0) { throw new Error('[[error:chat-disabled]]'); } - const [inRoom, canChat] = await Promise.all([ + const [roomData, inRoom, canChat] = await Promise.all([ + Messaging.getRoomData(roomId), Messaging.isUserInRoom(uid, roomId), privileges.global.can('chat', uid), checkReputation(uid), ]); - + if (!roomData) { + throw new Error('[[error:no-room]]'); + } + console.log('can chat', canChat); if (!inRoom) { throw new Error('[[error:not-in-room]]'); } diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index 5428489f42..202b8238df 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -454,7 +454,7 @@ module.exports = function (Messaging) { if (!room || (!room.public && !inRoom) || (room.public && ( - Array.isArray(room.groups) && room.groups.length && !(await groups.isMemberOfAny(uid, room.groups))) + Array.isArray(room.groups) && room.groups.length && !isAdmin && !(await groups.isMemberOfAny(uid, room.groups))) ) ) { return null;