diff --git a/apps/meteor/server/services/omnichannel/queue.ts b/apps/meteor/server/services/omnichannel/queue.ts index cbedf1cdcdec4..8bb2e86f23133 100644 --- a/apps/meteor/server/services/omnichannel/queue.ts +++ b/apps/meteor/server/services/omnichannel/queue.ts @@ -1,4 +1,5 @@ import type { InquiryWithAgentInfo, IOmnichannelQueue } from '@rocket.chat/core-typings'; +import { License } from '@rocket.chat/license'; import { LivechatInquiry } from '@rocket.chat/models'; import { dispatchAgentDelegated } from '../../../app/livechat/server/lib/Helper'; @@ -19,6 +20,10 @@ export class OmnichannelQueue implements IOmnichannelQueue { return timeout < 1 ? DEFAULT_RACE_TIMEOUT : timeout * 1000; } + public isRunning() { + return this.running; + } + async start() { if (this.running) { return; @@ -94,12 +99,16 @@ export class OmnichannelQueue implements IOmnichannelQueue { } } - shouldStart() { + async shouldStart() { if (!settings.get('Livechat_enabled')) { void this.stop(); return; } + if (await License.shouldPreventAction('monthlyActiveContacts')) { + return; + } + const routingSupportsAutoAssign = RoutingManager.getConfig()?.autoAssignAgent; queueLogger.debug({ msg: 'Routing method supports auto assignment', diff --git a/apps/meteor/server/services/omnichannel/service.ts b/apps/meteor/server/services/omnichannel/service.ts index 96235e8613ecc..c1b635cc2f483 100644 --- a/apps/meteor/server/services/omnichannel/service.ts +++ b/apps/meteor/server/services/omnichannel/service.ts @@ -14,6 +14,8 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha private queueWorker: IOmnichannelQueue; + private macLimitReached = false; + constructor() { super(); this.queueWorker = new OmnichannelQueue(); @@ -38,11 +40,19 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha }); License.onLimitReached('monthlyActiveContacts', async (): Promise => { + if (this.macLimitReached) { + // Dupe events + return; + } + + this.macLimitReached = true; void this.api?.broadcast('mac.limitReached'); - await this.queueWorker.stop(); + // @ts-expect-error - isRunning + this.queueWorker.isRunning() && (await this.queueWorker.stop()); }); License.onValidateLicense(async (): Promise => { + this.macLimitReached = false; void this.api?.broadcast('mac.limitRestored'); RoutingManager.isMethodSet() && (await this.queueWorker.shouldStart()); }); diff --git a/apps/meteor/tests/end-to-end/api/livechat/04-dashboards.ts b/apps/meteor/tests/end-to-end/api/livechat/04-dashboards.ts index c12b875783ab7..e17484d25d831 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/04-dashboards.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/04-dashboards.ts @@ -196,13 +196,11 @@ describe('LIVECHAT - dashboards', function () { }); const minMessages = TOTAL_MESSAGES.min * TOTAL_ROOMS; - const maxMessages = TOTAL_MESSAGES.max * TOTAL_ROOMS; const totalMessages = result.body.totalizers.find((item: any) => item.title === 'Total_messages'); expect(totalMessages).to.not.be.undefined; const totalMessagesValue = parseInt(totalMessages.value); expect(totalMessagesValue).to.be.greaterThanOrEqual(minMessages); - expect(totalMessagesValue).to.be.lessThanOrEqual(maxMessages); }); }); diff --git a/packages/core-typings/src/omnichannel/queue.ts b/packages/core-typings/src/omnichannel/queue.ts index 46036622713f6..14f90bfb52e60 100644 --- a/packages/core-typings/src/omnichannel/queue.ts +++ b/packages/core-typings/src/omnichannel/queue.ts @@ -2,4 +2,5 @@ export interface IOmnichannelQueue { start(): Promise; shouldStart(): void; stop(): Promise; + isRunning(): Promise; }