Skip to content

Commit

Permalink
fix: Prevent app's bridges from overriding lastMsg prop on rooms col (#…
Browse files Browse the repository at this point in the history
…29756)

Co-authored-by: Gabriel Casals <[email protected]>
Co-authored-by: Kevin Aleman <[email protected]>
  • Loading branch information
3 people authored and sampaiodiego committed Jul 13, 2023
1 parent 9aa995c commit c27ab3f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dirty-crabs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Prevent app's bridges from overriding the lastMsg prop which further was affecting Omni-Visitor abandonment feature for app
19 changes: 18 additions & 1 deletion apps/meteor/app/apps/server/converters/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ export class AppRoomsConverter {
let v;
if (room.visitor) {
const visitor = await LivechatVisitors.findOneById(room.visitor.id);

const lastMessageTs = room?.visitor?.lastMessageTs;
const phone = room?.visitor?.channelPhone;
v = {
_id: visitor._id,
username: visitor.username,
token: visitor.token,
status: visitor.status || 'online',
...(lastMessageTs && { lastMessageTs }),
...(phone && { phone }),
};
}

Expand Down Expand Up @@ -172,9 +177,21 @@ export class AppRoomsConverter {
return undefined;
}

const { lastMessageTs, phone } = v;

delete room.v;

return this.orch.getConverters().get('visitors').convertById(v._id);
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 }),
...(lastMessageTs && { lastMessageTs }),
};
},
department: async (room) => {
const { departmentId } = room;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ callbacks.add(
if (!(isOmnichannelRoom(room) && room.v.token)) {
return message;
}
if (message.t) {
return message;
}
if (message.token) {
await LivechatRooms.setVisitorLastMessageTimestampByRoomId(room._id, message.ts);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core-typings/src/IInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export enum LivechatInquiryStatus {
OPEN = 'open',
}

// This is a subset of the IVisitor interface + channel related fields
// IMPORTANT: If you're adding a new field here, make sure to update the
// apps-engine's room converter to include it too
export interface IVisitor {
_id: string;
username: string;
Expand Down

0 comments on commit c27ab3f

Please sign in to comment.