The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/lib/server/functions/getUserSingleOwnedRooms.js

25 lines
829 B

import { Rooms } from '../../../models/server';
export const getUserSingleOwnedRooms = function(subscribedRooms) {
const roomsThatWillChangeOwner = subscribedRooms.filter(({ shouldChangeOwner }) => shouldChangeOwner).map(({ rid }) => rid);
const roomsThatWillBeRemoved = subscribedRooms.filter(({ shouldBeRemoved }) => shouldBeRemoved).map(({ rid }) => rid);
const roomIds = roomsThatWillBeRemoved.concat(roomsThatWillChangeOwner);
const rooms = Rooms.findByIds(roomIds, { fields: { _id: 1, name: 1, fname: 1 } });
const result = {
shouldBeRemoved: [],
shouldChangeOwner: [],
};
rooms.forEach((room) => {
const name = room.fname || room.name;
if (roomsThatWillBeRemoved.includes(room._id)) {
result.shouldBeRemoved.push(name);
} else {
result.shouldChangeOwner.push(name);
}
});
return result;
};