Skip to content

Commit

Permalink
Regression: Use raw models instead of meteor ones on visitor inactivi…
Browse files Browse the repository at this point in the history
…ty processing (#27002)

Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
  • Loading branch information
KevLehman and tassoevan committed Oct 4, 2022
1 parent f44b2a3 commit 3715e0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SyncedCron } from 'meteor/littledata:synced-cron';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Meteor } from 'meteor/meteor';
import { LivechatVisitors, LivechatRooms } from '@rocket.chat/models';
import { LivechatVisitors, LivechatRooms, LivechatDepartment, Users } from '@rocket.chat/models';

import { settings } from '../../../../../app/settings/server';
import { LivechatDepartment, Users } from '../../../../../app/models/server';
import { Livechat } from '../../../../../app/livechat/server/lib/Livechat';
import { LivechatEnterprise } from './LivechatEnterprise';

Expand All @@ -15,10 +14,10 @@ export class VisitorInactivityMonitor {
this.messageCache = new Map();
}

start() {
async start() {
this._startMonitoring();
this._initializeMessageCache();
this.user = Users.findOneById('rocket.cat');
this.user = await Users.findOneById('rocket.cat');
}

_startMonitoring() {
Expand Down Expand Up @@ -55,22 +54,22 @@ export class VisitorInactivityMonitor {
this.messageCache.set('default', settings.get('Livechat_abandoned_rooms_closed_custom_message') || TAPi18n.__('Closed_automatically'));
}

_getDepartmentAbandonedCustomMessage(departmentId) {
async _getDepartmentAbandonedCustomMessage(departmentId) {
if (this.messageCache.has('departmentId')) {
return this.messageCache.get('departmentId');
}
const department = LivechatDepartment.findOneById(departmentId);
const department = await LivechatDepartment.findOneById(departmentId);
if (!department) {
return;
}
this.messageCache.set(department._id, department.abandonedRoomsCloseCustomMessage);
return department.abandonedRoomsCloseCustomMessage;
}

closeRooms(room) {
async closeRooms(room) {
let comment = this.messageCache.get('default');
if (room.departmentId) {
comment = this._getDepartmentAbandonedCustomMessage(room.departmentId) || comment;
comment = (await this._getDepartmentAbandonedCustomMessage(room.departmentId)) || comment;
}
Livechat.closeRoom({
comment,
Expand Down Expand Up @@ -100,10 +99,11 @@ export class VisitorInactivityMonitor {
if (!action || action === 'none') {
return;
}
// TODO: change this to an async map or reduce
Promise.await(LivechatRooms.findAbandonedOpenRooms(new Date())).forEach((room) => {
switch (action) {
case 'close': {
this.closeRooms(room);
Promise.await(this.closeRooms(room));
break;
}
case 'on-hold': {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/app/livechat-enterprise/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Meteor.startup(async function () {
if (!value || value === 'none') {
return visitorActivityMonitor.stop();
}
visitorActivityMonitor.start();
Promise.await(visitorActivityMonitor.start());
});
settings.change('Livechat_visitor_inactivity_timeout', function () {
Promise.await(updatePredictedVisitorAbandonment());
Expand Down

0 comments on commit 3715e0d

Please sign in to comment.