Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/livechat/server/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import './livechat';
import './config';
import './startup';
import './visitorStatus';
import './agentStatus';
import '../lib/messageTypes';
import './config';
import './roomType';
import './hooks/beforeCloseRoom';
import './hooks/beforeDelegateAgent';
Expand Down
26 changes: 18 additions & 8 deletions app/livechat/server/lib/RoutingManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';

import { settings } from '../../../settings/server';
import {
createLivechatSubscription,
dispatchAgentDelegated,
Expand All @@ -13,7 +12,7 @@ import {
allowAgentSkipQueue,
} from './Helper';
import { callbacks } from '../../../callbacks/server';
import { Logger } from '../../../logger';
import { Logger } from '../../../../server/lib/logger/Logger';
import { LivechatRooms, Rooms, Messages, Users, LivechatInquiry, Subscriptions } from '../../../models/server';
import { Apps, AppEvents } from '../../../apps/server';

Expand All @@ -23,9 +22,24 @@ export const RoutingManager = {
methodName: null,
methods: {},

setMethodName(name) {
startQueue() {
// queue shouldn't start on CE
},

isMethodSet() {
return !!this.methodName;
},

setMethodNameAndStartQueue(name) {
logger.debug(`Changing default routing method from ${ this.methodName } to ${ name }`);
this.methodName = name;
if (!this.methods[name]) {
logger.warn(`Cannot change routing method to ${ name }. Selected Routing method does not exists. Defaulting to Manual_Selection`);
this.methodName = 'Manual_Selection';
} else {
this.methodName = name;
}

this.startQueue();
},

registerMethod(name, Method) {
Expand Down Expand Up @@ -217,7 +231,3 @@ export const RoutingManager = {
});
},
};

settings.get('Livechat_Routing_Method', function(key, value) {
RoutingManager.setMethodName(value);
});
5 changes: 5 additions & 0 deletions app/livechat/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { businessHourManager } from './business-hour';
import { createDefaultBusinessHourIfNotExists } from './business-hour/Helper';
import { hasPermission } from '../../authorization/server';
import { Livechat } from './lib/Livechat';
import { RoutingManager } from './lib/RoutingManager';

import './roomAccessValidator.internalService';

Expand Down Expand Up @@ -57,5 +58,9 @@ Meteor.startup(async () => {
return businessHourManager.stopManager();
});

settings.get('Livechat_Routing_Method', function(key, value) {
RoutingManager.setMethodNameAndStartQueue(value);
});

Accounts.onLogout(({ user }) => user?.roles?.includes('livechat-agent') && !user?.roles?.includes('bot') && Livechat.setUserStatusLivechat(user._id, 'not-available'));
});
16 changes: 12 additions & 4 deletions ee/app/livechat-enterprise/server/lib/LivechatEnterprise.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,27 @@ const queueWorker = {
},
};

let omnichannelIsEnabled = false;

function shouldQueueStart() {
if (!omnichannelIsEnabled) {
queueWorker.stop();
return;
}

const routingSupportsAutoAssign = RoutingManager.getConfig().autoAssignAgent;
queueLogger.debug(`Routing method ${ RoutingManager.methodName } supports auto assignment: ${ routingSupportsAutoAssign }. ${
routingSupportsAutoAssign
? 'Starting'
: 'Stopping'
} queue`);

routingSupportsAutoAssign && settings.get('Livechat_enabled') ? queueWorker.start() : queueWorker.stop();
routingSupportsAutoAssign ? queueWorker.start() : queueWorker.stop();
}

RoutingManager.startQueue = shouldQueueStart;

settings.get('Livechat_enabled', (_, value) => {
value && settings.get('Livechat_Routing_Method') ? shouldQueueStart() : queueWorker.stop();
omnichannelIsEnabled = value;
omnichannelIsEnabled && RoutingManager.isMethodSet() ? shouldQueueStart() : queueWorker.stop();
});

settings.onload('Livechat_Routing_Method', shouldQueueStart);
2 changes: 1 addition & 1 deletion server/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '../ee/server/broker';
import './lib/logger/startup';
import './importPackages';
import '../imports/startup/server';

import './services/startup';

import '../ee/server';
import './lib/logger/startup';
import './lib/pushConfig';
import './startup/migrations';
import './startup/appcache';
Expand Down