Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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