fix: admins should see public chats

even if they are not in any of the groups
isekai-main
Barış Soner Uşaklı 1 year ago
parent 7dd143e1f8
commit aeb27f4b8d

@ -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]]');
}

@ -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;

Loading…
Cancel
Save