[FIX][Enterprise] Omnichannel simultaneous chat limit is not properly checking the limit by department (#21839)

pull/21841/head
Renato Becker 4 years ago committed by GitHub
parent 1af59d42cf
commit 18adf19063
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/server/raw/Users.js
  2. 2
      ee/app/livechat-enterprise/server/hooks/checkAgentBeforeTakeInquiry.js
  3. 12
      ee/app/livechat-enterprise/server/lib/Helper.js

@ -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 } },
];

@ -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;
}

@ -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;
}

Loading…
Cancel
Save