Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions app/models/server/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ export class UsersRaw extends BaseRaw {
return result.value;
}

async getAgentAndAmountOngoingChats(userId) {
async getAgentAndAmountOngoingChats(userId, department) {
const aggregate = [
{ $match: { _id: userId, status: { $exists: true, $ne: 'offline' }, statusLivechat: 'available', roles: 'livechat-agent' } },
{ $lookup: { from: 'rocketchat_subscription', localField: '_id', foreignField: 'u._id', as: 'subs' } },
{ $project: { agentId: '$_id', username: 1, lastAssignTime: 1, lastRoutingTime: 1, 'queueInfo.chats': { $size: { $filter: { input: '$subs', as: 'sub', cond: { $and: [{ $eq: ['$$sub.t', 'l'] }, { $eq: ['$$sub.open', true] }, { $ne: ['$$sub.onHold', true] }] } } } } } },
{ $project: { agentId: '$_id', username: 1, lastAssignTime: 1, lastRoutingTime: 1, 'queueInfo.chats': { $size: { $filter: { input: '$subs', as: 'sub', cond: { $and: [{ $eq: ['$$sub.t', 'l'] }, { $eq: ['$$sub.open', true] }, { $ne: ['$$sub.onHold', true] }, { ...department && { $eq: ['$$sub.department', department] } }] } } } } } },
{ $sort: { 'queueInfo.chats': 1, lastAssignTime: 1, lastRoutingTime: 1, username: 1 } },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ callbacks.add('livechat.checkAgentBeforeTakeInquiry', async ({ agent, inquiry, o
return agent;
}

const user = await Users.getAgentAndAmountOngoingChats(agentId);
const user = await Users.getAgentAndAmountOngoingChats(agentId, departmentId);
if (!user) {
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions ee/app/livechat-enterprise/server/lib/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import { dispatchAgentDelegated } from '../../../../../app/livechat/server/lib/H
import notifications from '../../../../../app/notifications/server/lib/Notifications';

export const getMaxNumberSimultaneousChat = ({ agentId, departmentId }) => {
if (agentId) {
const user = Users.getAgentInfo(agentId);
const { livechat: { maxNumberSimultaneousChat } = {} } = user || {};
if (departmentId) {
const department = LivechatDepartment.findOneById(departmentId);
const { maxNumberSimultaneousChat } = department || {};
if (maxNumberSimultaneousChat > 0) {
return maxNumberSimultaneousChat;
}
}

if (departmentId) {
const department = LivechatDepartment.findOneById(departmentId);
const { maxNumberSimultaneousChat } = department || {};
if (agentId) {
const user = Users.getAgentInfo(agentId);
const { livechat: { maxNumberSimultaneousChat } = {} } = user || {};
if (maxNumberSimultaneousChat > 0) {
return maxNumberSimultaneousChat;
}
Expand Down