From d54c60f19f706e6d01c83ac2c517689df92d361b Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Wed, 20 Mar 2019 15:25:37 -0300 Subject: [PATCH 1/2] Several improvements regarding Guest Pool routing method. --- app/livechat/server/api/lib/livechat.js | 4 +++- app/livechat/server/lib/Livechat.js | 7 +------ app/livechat/server/lib/QueueMethods.js | 12 +++++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/livechat/server/api/lib/livechat.js b/app/livechat/server/api/lib/livechat.js index d4fa9ac5599f..24b906dfdec9 100644 --- a/app/livechat/server/api/lib/livechat.js +++ b/app/livechat/server/api/lib/livechat.js @@ -3,9 +3,11 @@ import { Random } from 'meteor/random'; import { Users, Rooms, LivechatVisitors, LivechatDepartment, LivechatTrigger } from '../../../../models'; import _ from 'underscore'; import { Livechat } from '../../lib/Livechat'; +import { settings as rcSettings } from '../../../../settings'; export function online() { - return Users.findOnlineAgents().count() > 0; + const onlineAgents = Livechat.getOnlineAgents(); + return (onlineAgents && onlineAgents.count() > 0) || rcSettings.get('Livechat_guest_pool_with_no_agents'); } export function findTriggers() { diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index 82f5214d921a..24e54648a095 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -533,12 +533,7 @@ export const Livechat = { const agentIds = []; // get the agents of the department if (departmentId) { - let agents = Livechat.getOnlineAgents(departmentId); - - if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) { - agents = Livechat.getAgents(departmentId); - } - + const agents = Livechat.getAgents(departmentId); if (agents.count() === 0) { return false; } diff --git a/app/livechat/server/lib/QueueMethods.js b/app/livechat/server/lib/QueueMethods.js index e03aa2c93e36..457d9d5f8aff 100644 --- a/app/livechat/server/lib/QueueMethods.js +++ b/app/livechat/server/lib/QueueMethods.js @@ -91,14 +91,16 @@ export const QueueMethods = { * only the client until paired with an agent */ 'Guest_Pool'(guest, message, roomInfo) { - let agents = Livechat.getOnlineAgents(guest.department); - - if (agents.count() === 0 && settings.get('Livechat_guest_pool_with_no_agents')) { - agents = Livechat.getAgents(guest.department); + if (settings.get('Livechat_guest_pool_with_no_agents') === false) { + const onlineAgents = Livechat.getOnlineAgents(guest.department); + if (!onlineAgents || onlineAgents.count() === 0) { + throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); + } } + const agents = Livechat.getAgents(guest.department); if (agents.count() === 0) { - throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); + throw new Meteor.Error('no-agent-available', 'Sorry, no available agents.'); } Rooms.updateLivechatRoomCount(); From 411551909737bfc19085ad7d182ef9707f623d22 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 22 Mar 2019 12:10:39 -0300 Subject: [PATCH 2/2] rename const `agents` to `allAgents`. --- app/livechat/server/lib/QueueMethods.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/livechat/server/lib/QueueMethods.js b/app/livechat/server/lib/QueueMethods.js index dd50e2ac8f64..6dd4642913c2 100644 --- a/app/livechat/server/lib/QueueMethods.js +++ b/app/livechat/server/lib/QueueMethods.js @@ -98,8 +98,8 @@ export const QueueMethods = { } } - const agents = Livechat.getAgents(guest.department); - if (agents.count() === 0) { + const allAgents = Livechat.getAgents(guest.department); + if (allAgents.count() === 0) { throw new Meteor.Error('no-agent-available', 'Sorry, no available agents.'); } @@ -107,7 +107,7 @@ export const QueueMethods = { const agentIds = []; - agents.forEach((agent) => { + allAgents.forEach((agent) => { if (guest.department) { agentIds.push(agent.agentId); } else {