Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions apps/meteor/app/apps/server/converters/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class AppRoomsConverter {
if (room.visitor) {
const visitor = await LivechatVisitors.findOneById(room.visitor.id);

const lastMessageTs = room?.visitor?.lastMessageTs;
const phone = room?.visitor?.channelPhone;
const { lastMessageTs, phone } = room.visitorChannelInfo;

v = {
_id: visitor._id,
username: visitor.username,
Expand Down Expand Up @@ -170,26 +170,32 @@ export class AppRoomsConverter {

return this.orch.getConverters().get('users').convertById(u._id);
},
visitor: async (room) => {
visitor: (room) => {
const { v } = room;

if (!v) {
return undefined;
}

const { lastMessageTs, phone } = v;
return this.orch.getConverters().get('visitors').convertById(v._id);
},
// Note: room.v is not just visitor, it also contains channel related visitor data
// so we need to pass this data to the converter
// So suppose you have a contact whom we're contacting using SMS via 2 phone no's,
// let's call X and Y. Then if the contact sends a message using X phone number,
// then room.v.phoneNo would be X and correspondingly we'll store the timestamp of
// the last message from this visitor from X phone no on room.v.lastMessageTs
visitorChannelInfo: (room) => {
const { v } = room;

delete room.v;
if (!v) {
return undefined;
}

const { lastMessageTs, phone } = v;

return {
...(await this.orch.getConverters().get('visitors').convertById(v._id)),
// Note: room.v is not just visitor, it also contains channel related visitor data
// so we need to pass this data to the converter
// So suppose you have a contact whom we're contacting using SMS via 2 phone no's,
// let's call X and Y. Then if the contact sends a message using X phone number,
// then room.v.phoneNo would be X and correspondingly we'll store the timestamp of
// the last message from this visitor from X phone no on room.v.lastMessageTs
...(phone && { channelPhone: phone }),
...(phone && { phone }),
...(lastMessageTs && { lastMessageTs }),
};
},
Expand Down