Skip to content
Snippets Groups Projects
Unverified Commit cf778f16 authored by Ricardo Garim's avatar Ricardo Garim Committed by GitHub
Browse files

chore: add updater on afterOmnichannelSaveMessage...

chore: add updater on afterOmnichannelSaveMessage (save-last-visitor-message-timestamp) hook (#32977)
parent e2a750f3
No related branches found
No related tags found
No related merge requests found
......@@ -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',
......
......@@ -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) {
......
......@@ -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>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment