Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 9 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,14 @@ export class AppRoomsConverter {
let v;
if (room.visitor) {
const visitor = await LivechatVisitors.findOneById(room.visitor.id);

const lastMessageTs = room?.visitor?.lastMessageTs;
v = {
_id: visitor._id,
username: visitor.username,
token: visitor.token,
status: visitor.status || 'online',
...(lastMessageTs && { lastMessageTs }),
};
}
Comment thread
ggazzo marked this conversation as resolved.

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

const { lastMessageTs } = v;

delete room.v;

return this.orch.getConverters().get('visitors').convertById(v._id);
return {
...(await this.orch.getConverters().get('visitors').convertById(v._id)),
...(lastMessageTs && { lastMessageTs }),
Comment thread
murtaza98 marked this conversation as resolved.
};
},
department: async (room) => {
const { departmentId } = room;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { callbackLogger } from '../lib/logger';

callbacks.add(
'afterSaveMessage',
async function (message, room) {
if (!(isOmnichannelRoom(room) && room.v.token)) {
return message;
}
if (message.t) {
return message;
}
if (message.token) {
await LivechatRooms.setVisitorLastMessageTimestampByRoomId(room._id, message.ts);
callbackLogger.debug({
Comment thread
ggazzo marked this conversation as resolved.
Outdated
msg: 'Saved last visitor message timestamp',
rid: room._id,
msgId: message._id,
});
}
return message;
},
Expand Down