Skip to content

Commit

Permalink
Deprecate old room _id for DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Mar 26, 2020
1 parent ebbbd09 commit 61902da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/lib/server/functions/createDirectRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export const createDirectRoom = function(members, roomExtraData = {}, options =
const sortedMembers = members.sort((u1, u2) => (u1.name || u1.username).localeCompare(u2.name || u2.username));

const usernames = sortedMembers.map(({ username }) => username);
const uids = sortedMembers.map(({ _id }) => _id);
const uids = members.map(({ _id }) => _id).sort();

const room = Rooms.findDirectRoomContainingAllUserIDs(uids, { fields: { _id: 1 } });
// Deprecated: using users' _id to compose the room _id is deprecated
const room = uids.length <= 2
? Rooms.findById(uids.join(''), { fields: { _id: 1 } })
: Rooms.findDirectRoomContainingAllUserIDs(uids, { fields: { _id: 1 } });

const isNewRoom = !room;

const rid = room?._id || Rooms.insert({
...uids.length <= 2 && { _id: uids.join('') }, // Deprecated: using users' _id to compose the room _id is deprecated
t: 'd',
usernames,
usersCount: members.length,
Expand Down

0 comments on commit 61902da

Please sign in to comment.