Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions apps/meteor/app/apps/server/bridges/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ export class AppLivechatBridge extends LivechatBridge {
return true;
}

protected async findRoomsByAgentId(agentId: string, appId: string): Promise<ILivechatRoom[]> {
Comment thread
lmauromb marked this conversation as resolved.
Resolved
Comment thread
lmauromb marked this conversation as resolved.
Resolved
this.orch.debugLog(`The App ${appId} is looking for livechat rooms associated with agent ${agentId}`);

if (!agentId) {
Comment thread
lmauromb marked this conversation as resolved.
Resolved
return [];
}

const result = await LivechatRooms.findOpenByAgent(agentId).toArray();
Comment thread
lmauromb marked this conversation as resolved.
Resolved

return Promise.all((result as unknown as ILivechatRoom[]).map((room) => this.orch.getConverters()?.get('rooms').convertRoom(room)));
}

protected async countRoomsByAgentId(agentId: string, appId: string): Promise<number> {
this.orch.debugLog(`The App ${appId} is counting livechat rooms associated with agent ${agentId}`);

if (!agentId) {
Comment thread
lmauromb marked this conversation as resolved.
Resolved
return 0;
}

return LivechatRooms.countOpenByAgent(agentId);
}

protected async findRooms(visitor: IVisitor, departmentId: string | null, appId: string): Promise<Array<ILivechatRoom>> {
this.orch.debugLog(`The App ${appId} is looking for livechat visitors.`);

Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,17 @@ export class LivechatRoomsRaw extends BaseRaw<IOmnichannelRoom> implements ILive
);
}

countOpenByAgent(userId: string, extraQuery: Filter<IOmnichannelRoom> = {}) {
Comment thread
lmauromb marked this conversation as resolved.
Resolved
const query: Filter<IOmnichannelRoom> = {
't': 'l',
'open': true,
'servedBy._id': userId,
...extraQuery,
};

return this.col.countDocuments(query);
}

findOpenByAgent(userId: string, extraQuery: Filter<IOmnichannelRoom> = {}) {
const query: Filter<IOmnichannelRoom> = {
't': 'l',
Expand Down
1 change: 1 addition & 0 deletions packages/model-typings/src/models/ILivechatRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export interface ILivechatRoomsModel extends IBaseModel<IOmnichannelRoom> {
data?: { departmentId: string },
): AggregationCursor<Pick<IOmnichannelRoom, 'ts' | 'departmentId' | 'open' | 'servedBy' | 'metrics' | 'msgs' | 'onHold'>>;
findOpenByAgent(userId: string, extraQuery?: Filter<IOmnichannelRoom>): FindCursor<IOmnichannelRoom>;
countOpenByAgent(userId: string, extraQuery?: Filter<IOmnichannelRoom>): Promise<number>;
changeAgentByRoomId(roomId: string, newAgent: { agentId: string; username: string }): Promise<UpdateResult>;
changeDepartmentIdByRoomId(roomId: string, departmentId: string): Promise<UpdateResult>;
saveCRMDataByRoomId(roomId: string, crmData: unknown): Promise<UpdateResult>;
Expand Down