Skip to content

Commit

Permalink
Merge branch 'improve/threadMetrics' of github.com:RocketChat/Rocket.…
Browse files Browse the repository at this point in the history
…Chat into improve/threadMetrics

* 'improve/threadMetrics' of github.com:RocketChat/Rocket.Chat:
  chore: add updater on afterOmnichannelSaveMessage (save-last-visitor-message-timestamp) hook (#32977)
  chore: move afterOmnichannelSaveMessage hook to work with updater (#32978)
  feat: Upgrade `fuselage-toastbar` adding pause on hover (#32969)
  • Loading branch information
gabriellsh committed Aug 7, 2024
2 parents 5d8cf4f + 634809e commit bbadb0f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-swans-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/uikit-playground': minor
'@rocket.chat/meteor': minor
---

Upgrades fuselage-toastbar version in order to add pause on hover functionality
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

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

callbacks.add(
'afterSaveMessage',
async (message, room) => {
// only call webhook if it is a livechat room
if (!isOmnichannelRoom(room)) {
return message;
}
return callbacks.run('afterOmnichannelSaveMessage', message, { room });

const updater = LivechatRooms.getUpdater();
const result = await callbacks.run('afterOmnichannelSaveMessage', message, { room, roomUpdater: updater });

if (updater.hasChanges()) {
await updater.persist({ _id: room._id });
}

return result;
},
callbacks.priority.MEDIUM,
'after-omnichannel-save-message',
Expand Down
10 changes: 2 additions & 8 deletions apps/meteor/app/livechat/server/hooks/saveAnalyticsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getAnalyticsData = (room: IOmnichannelRoom, now: Date): Record<string, str

callbacks.add(
'afterOmnichannelSaveMessage',
async (message, { room }) => {
async (message, { room, roomUpdater }) => {
if (!message || isEditedMessage(message)) {
return message;
}
Expand All @@ -71,13 +71,7 @@ callbacks.add(
}

const analyticsData = getAnalyticsData(room, new Date());
const updater = await LivechatRooms.getAnalyticsUpdateQueryByRoomId(room, message, analyticsData);

if (updater.hasChanges()) {
await updater.persist({
_id: room._id,
});
}
await LivechatRooms.getAnalyticsUpdateQueryByRoomId(room, message, analyticsData, roomUpdater);

return message;
},
Expand Down
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
3 changes: 2 additions & 1 deletion apps/meteor/lib/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
MessageMention,
OmnichannelSourceType,
} from '@rocket.chat/core-typings';
import type { Updater } from '@rocket.chat/models';
import type { FilterOperators } from 'mongodb';

import type { ILoginAttempt } from '../app/authentication/server/ILoginAttempt';
Expand Down Expand Up @@ -50,7 +51,7 @@ interface EventLikeCallbackSignatures {
'afterFileUpload': (params: { user: IUser; room: IRoom; message: IMessage }) => void;
'afterRoomNameChange': (params: { rid: string; name: string; oldName: string }) => void;
'afterSaveMessage': (message: IMessage, room: IRoom, uid?: string) => void;
'afterOmnichannelSaveMessage': (message: IMessage, constant: { room: IOmnichannelRoom }) => void;
'afterOmnichannelSaveMessage': (message: IMessage, constant: { room: IOmnichannelRoom; roomUpdater: Updater<IOmnichannelRoom> }) => void;
'livechat.removeAgentDepartment': (params: { departmentId: ILivechatDepartmentRecord['_id']; agentsId: ILivechatAgent['_id'][] }) => void;
'livechat.saveAgentDepartment': (params: { departmentId: ILivechatDepartmentRecord['_id']; agentsId: ILivechatAgent['_id'][] }) => void;
'livechat.closeRoom': (params: { room: IOmnichannelRoom; options: CloseRoomParams['options'] }) => void;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"@rocket.chat/fuselage": "0.58.0",
"@rocket.chat/fuselage-hooks": "^0.33.1",
"@rocket.chat/fuselage-polyfills": "~0.31.25",
"@rocket.chat/fuselage-toastbar": "^0.32.0",
"@rocket.chat/fuselage-toastbar": "^0.33.0",
"@rocket.chat/fuselage-tokens": "^0.33.1",
"@rocket.chat/fuselage-ui-kit": "workspace:^",
"@rocket.chat/gazzodown": "workspace:^",
Expand Down
23 changes: 9 additions & 14 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
];
}

getUpdater(): Updater<IOmnichannelRoom> {
return super.getUpdater();
}

getQueueMetrics({
departmentId,
agentId,
Expand Down Expand Up @@ -2056,7 +2060,7 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
return this.getAnalyticsUpdateQuery(analyticsData, updater).set('metrics.servedBy.lr', message.ts);
}

return updater;
return this.getAnalyticsUpdateQuery(analyticsData, updater);
}

private getAnalyticsUpdateQueryBySentByVisitor(
Expand All @@ -2071,10 +2075,10 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive

// update visitor timestamp, only if its new inquiry and not continuing message
if (agentLastReply >= visitorLastQuery) {
return this.getAnalyticsUpdateQuery(analyticsData).set('metrics.v.lq', message.ts);
return this.getAnalyticsUpdateQuery(analyticsData, updater).set('metrics.v.lq', message.ts);
}

return updater;
return this.getAnalyticsUpdateQuery(analyticsData, updater);
}

async getAnalyticsUpdateQueryByRoomId(
Expand Down Expand Up @@ -2399,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
4 changes: 3 additions & 1 deletion packages/model-typings/src/models/ILivechatRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type WithOptions = {

// TODO: Fix types of model
export interface ILivechatRoomsModel extends IBaseModel<IOmnichannelRoom> {
getUpdater(): Updater<IOmnichannelRoom>;

getQueueMetrics(params: { departmentId: any; agentId: any; includeOfflineAgents: any; options?: any }): any;

findAllNumberOfAbandonedRooms(params: Period & WithDepartment & WithOnlyCount & WithOptions): Promise<any>;
Expand Down Expand Up @@ -242,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
2 changes: 1 addition & 1 deletion packages/uikit-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@rocket.chat/fuselage": "0.58.0",
"@rocket.chat/fuselage-hooks": "^0.33.1",
"@rocket.chat/fuselage-polyfills": "~0.31.25",
"@rocket.chat/fuselage-toastbar": "^0.32.0",
"@rocket.chat/fuselage-toastbar": "^0.33.0",
"@rocket.chat/fuselage-tokens": "^0.33.1",
"@rocket.chat/fuselage-ui-kit": "workspace:~",
"@rocket.chat/icons": "^0.36.0",
Expand Down
23 changes: 17 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8876,17 +8876,19 @@ __metadata:
languageName: node
linkType: hard

"@rocket.chat/fuselage-toastbar@npm:^0.32.0":
version: 0.32.0
resolution: "@rocket.chat/fuselage-toastbar@npm:0.32.0"
"@rocket.chat/fuselage-toastbar@npm:^0.33.0":
version: 0.33.0
resolution: "@rocket.chat/fuselage-toastbar@npm:0.33.0"
dependencies:
react-timing-hooks: ~4.0.2
peerDependencies:
"@rocket.chat/fuselage": "*"
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/fuselage-polyfills": "*"
"@rocket.chat/styled": "*"
react: ^17.0.2
react-dom: ^17.0.2
checksum: 5e78516aee6446da4c76dac10ff83adb4deeb86d6111c42419f0629c35ec64b19ae6ab563f20b5efa2600c9c723b9096edc3c166e960fd25cfda1f07c4df3f3f
checksum: 97993ad2acdc5a742b71c94f9d321e090769c4116ab52208c2103ca41d4455bc4cd15c0cd0a1f8545144910a8c7f7de645ee150c0d8fc6b746001244690de2ed
languageName: node
linkType: hard

Expand Down Expand Up @@ -9385,7 +9387,7 @@ __metadata:
"@rocket.chat/fuselage": 0.58.0
"@rocket.chat/fuselage-hooks": ^0.33.1
"@rocket.chat/fuselage-polyfills": ~0.31.25
"@rocket.chat/fuselage-toastbar": ^0.32.0
"@rocket.chat/fuselage-toastbar": ^0.33.0
"@rocket.chat/fuselage-tokens": ^0.33.1
"@rocket.chat/fuselage-ui-kit": "workspace:^"
"@rocket.chat/gazzodown": "workspace:^"
Expand Down Expand Up @@ -10547,7 +10549,7 @@ __metadata:
"@rocket.chat/fuselage": 0.58.0
"@rocket.chat/fuselage-hooks": ^0.33.1
"@rocket.chat/fuselage-polyfills": ~0.31.25
"@rocket.chat/fuselage-toastbar": ^0.32.0
"@rocket.chat/fuselage-toastbar": ^0.33.0
"@rocket.chat/fuselage-tokens": ^0.33.1
"@rocket.chat/fuselage-ui-kit": "workspace:~"
"@rocket.chat/icons": ^0.36.0
Expand Down Expand Up @@ -35804,6 +35806,15 @@ __metadata:
languageName: node
linkType: hard

"react-timing-hooks@npm:~4.0.2":
version: 4.0.2
resolution: "react-timing-hooks@npm:4.0.2"
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
checksum: 95ebcaffe400f3e1af32bd82eb92258c5e1473e43a7edf65879692117946105bb21f4e91046fdc85c8c737997be1d8148bffacfde8a8a9ee835d81415048119e
languageName: node
linkType: hard

"react-virtuoso@npm:^4.7.1":
version: 4.7.1
resolution: "react-virtuoso@npm:4.7.1"
Expand Down

0 comments on commit bbadb0f

Please sign in to comment.