Skip to content

Commit

Permalink
notifyUserStatusChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 12, 2023
1 parent b7ef80b commit 6d7b756
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
16 changes: 1 addition & 15 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dns from 'dns';
import util from 'util';

import { Message, api } from '@rocket.chat/core-services';
import { Message } from '@rocket.chat/core-services';
import { Logger } from '@rocket.chat/logger';
import {
LivechatVisitors,
Expand Down Expand Up @@ -891,20 +891,6 @@ export const Livechat = {
});
},

async notifyAgentStatusChanged(userId, status) {
callbacks.runAsync('livechat.agentStatusChanged', { userId, status });
if (!settings.get('Livechat_show_agent_info')) {
return;
}

await LivechatRooms.findOpenByAgent(userId).forEach((room) => {
void api.broadcast('omnichannel.room', room._id, {
type: 'agentStatus',
status,
});
});
},

async allowAgentChangeServiceStatus(statusLivechat, agentId) {
if (statusLivechat !== 'available') {
return true;
Expand Down
18 changes: 18 additions & 0 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,24 @@ class LivechatClass {

return LivechatRooms.findOneById(room._id);
}

async notifyAgentStatusChanged(userId: string, status?: UserStatus) {
if (!status) {
return;
}

void callbacks.runAsync('livechat.agentStatusChanged', { userId, status });
if (!settings.get('Livechat_show_agent_info')) {
return;
}

await LivechatRooms.findOpenByAgent(userId).forEach((room) => {
void api.broadcast('omnichannel.room', room._id, {
type: 'agentStatus',
status,
});
});
}
}

export const Livechat = new LivechatClass();
3 changes: 2 additions & 1 deletion apps/meteor/lib/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ILivechatTagRecord,
TransferData,
AtLeast,
UserStatus,
} from '@rocket.chat/core-typings';
import type { FilterOperators } from 'mongodb';

Expand Down Expand Up @@ -52,7 +53,7 @@ interface EventLikeCallbackSignatures {
'livechat.saveRoom': (room: IRoom) => void;
'livechat:afterReturnRoomAsInquiry': (params: { room: IRoom }) => void;
'livechat.setUserStatusLivechat': (params: { userId: IUser['_id']; status: OmnichannelAgentStatus }) => void;
'livechat.agentStatusChanged': (params: { userId: IUser['_id']; status: OmnichannelAgentStatus }) => void;
'livechat.agentStatusChanged': (params: { userId: IUser['_id']; status: UserStatus }) => void;
'livechat.onNewAgentCreated': (agentId: string) => void;
'livechat.afterTakeInquiry': (inq: InquiryWithAgentInfo, agent: { agentId: string; username: string }) => void;
'livechat.afterAgentRemoved': (params: { agent: Pick<IUser, '_id' | 'username'> }) => void;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/omnichannel/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ServiceClassInternal } from '@rocket.chat/core-services';
import type { IOmnichannelService } from '@rocket.chat/core-services';
import type { IOmnichannelQueue } from '@rocket.chat/core-typings';

import { Livechat } from '../../../app/livechat/server';
import { Livechat } from '../../../app/livechat/server/lib/LivechatTyped';
import { RoutingManager } from '../../../app/livechat/server/lib/RoutingManager';
import { settings } from '../../../app/settings/server';
import { OmnichannelQueue } from './queue';
Expand Down

0 comments on commit 6d7b756

Please sign in to comment.