Skip to content

Commit

Permalink
chore: add updater on afterOmnichannelSaveMessage (save-last-visitor-…
Browse files Browse the repository at this point in the history
…message-timestamp) hook (#32977)
  • Loading branch information
ricardogarim committed Aug 5, 2024
1 parent e2a750f commit cf778f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { callbacks } from '../../../../lib/callbacks';

callbacks.add(
'afterOmnichannelSaveMessage',
async (message, { room }) => {
if (message.t) {
return message;
}
if (!isMessageFromVisitor(message)) {
async (message, { roomUpdater }) => {
if (message.t || !isMessageFromVisitor(message)) {
return message;
}

await LivechatRooms.setVisitorLastMessageTimestampByRoomId(room._id, message.ts);
await LivechatRooms.getVisitorLastMessageTsUpdateQueryByRoomId(message.ts, roomUpdater);

return message;
},
callbacks.priority.HIGH,
'save-last-visitor-message-timestamp',
Expand Down
13 changes: 2 additions & 11 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2403,17 +2403,8 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
return this.deleteOne(query);
}

setVisitorLastMessageTimestampByRoomId(roomId: string, lastMessageTs: Date) {
const query = {
_id: roomId,
};
const update = {
$set: {
'v.lastMessageTs': lastMessageTs,
},
};

return this.updateOne(query, update);
getVisitorLastMessageTsUpdateQueryByRoomId(lastMessageTs: Date, updater: Updater<IOmnichannelRoom> = this.getUpdater()) {
return updater.set('v.lastMessageTs', lastMessageTs);
}

setVisitorInactivityInSecondsById(roomId: string, visitorInactivity: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/ILivechatRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export interface ILivechatRoomsModel extends IBaseModel<IOmnichannelRoom> {
removeAgentByRoomId(roomId: string): Promise<UpdateResult>;
removeByVisitorToken(token: string): Promise<DeleteResult>;
removeById(_id: string): Promise<DeleteResult>;
setVisitorLastMessageTimestampByRoomId(roomId: string, lastMessageTs: Date): Promise<UpdateResult>;
getVisitorLastMessageTsUpdateQueryByRoomId(lastMessageTs: Date, updater?: Updater<IOmnichannelRoom>): Updater<IOmnichannelRoom>;
setVisitorInactivityInSecondsById(roomId: string, visitorInactivity: any): Promise<UpdateResult>;
changeVisitorByRoomId(roomId: string, visitor: { _id: string; username: string; token: string }): Promise<UpdateResult>;
unarchiveOneById(roomId: string): Promise<UpdateResult>;
Expand Down

0 comments on commit cf778f1

Please sign in to comment.