Skip to content

Commit

Permalink
Service events
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 6, 2023
1 parent 9730dd0 commit ecc6882
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions apps/meteor/ee/app/license/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ callbacks.add('workspaceLicenseChanged', async (updatedLicense) => {
});

const getCurrentPeriod = () => {
moment.utc().format('YYYY-MM');
return moment.utc().format('YYYY-MM');
};

License.setLicenseLimitCounter('activeUsers', () => Users.getActiveLocalUserCount());
License.setLicenseLimitCounter('guestUsers', () => Users.getActiveLocalGuestCount());
License.setLicenseLimitCounter('roomsPerGuest', async (context) => (context?.userId ? Subscriptions.countByUserId(context.userId) : 0));
License.setLicenseLimitCounter('privateApps', () => getAppCount('private'));
License.setLicenseLimitCounter('marketplaceApps', () => getAppCount('marketplace'));
// #TODO: Get real value
License.setLicenseLimitCounter('monthlyActiveContacts', async () => LivechatVisitors.countVisitorsOnPeriod(getCurrentPeriod()));
16 changes: 7 additions & 9 deletions apps/meteor/server/services/omnichannel/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha
await Livechat.notifyAgentStatusChanged(user._id, user.status);
}
});
}

async started() {
settings.watch<boolean>('Livechat_enabled', (enabled) => {
void (enabled && RoutingManager.isMethodSet() ? this.queueWorker.shouldStart() : this.queueWorker.stop());
});

License.onLimitReached('monthlyActiveContacts', async (): Promise<void> => {
void this.api?.broadcast('mac.limitReached');
Expand All @@ -38,13 +44,7 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha

License.onValidateLicense(async (): Promise<void> => {
void this.api?.broadcast('mac.limitRestored');
await this.queueWorker.shouldStart();
});
}

async started() {
settings.watch<boolean>('Livechat_enabled', (enabled) => {
void (enabled && RoutingManager.isMethodSet() ? this.queueWorker.shouldStart() : this.queueWorker.stop());
RoutingManager.isMethodSet() && (await this.queueWorker.shouldStart());
});
}

Expand All @@ -54,12 +54,10 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha

async isRoomEnabled(room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean> {
const currentMonth = moment.utc().format('YYYY-MM');
// @ts-expect-error - v.activity
return room.v?.activity?.includes(currentMonth) || !(await License.shouldPreventAction('monthlyActiveContacts'));
}

async checkMACLimit(): Promise<boolean> {
// return license.isMacOnLimit();
return !(await License.shouldPreventAction('monthlyActiveContacts'));
}
}

0 comments on commit ecc6882

Please sign in to comment.