Skip to content

Commit

Permalink
if only statusdefault was documented somewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Jun 24, 2023
1 parent 5bd2491 commit 9585969
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export abstract class AbstractBusinessHourBehavior {
return this.UsersRepository.setLivechatStatusIf(
agentId,
status,
{ livechatStatusSystemModified: true, status: { $ne: 'offline' } },
// Why this works: statusDefault is the property set when a user manually changes their status
// So if it's set to offline, we can be sure the user will be offline after login and we can skip the update
{ livechatStatusSystemModified: true, statusDefault: { $ne: 'offline' } },
{ livechatStatusSystemModified: true },
);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/business-hour/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Meteor } from 'meteor/meteor';
import { cronJobs } from '@rocket.chat/cron';
import type { IUser } from '@rocket.chat/core-typings';
import { Accounts } from 'meteor/accounts-base';

import { BusinessHourManager } from './BusinessHourManager';
import { SingleBusinessHourBehavior } from './Single';
import { callbacks } from '../../../../lib/callbacks';
import { DefaultBusinessHour } from './Default';
import { presenceEvents } from '../../../../lib/localEvents';

export const businessHourManager = new BusinessHourManager(cronJobs);

Expand All @@ -17,7 +17,7 @@ Meteor.startup(async () => {
businessHourManager.registerBusinessHourBehavior(new BusinessHourBehaviorClass());
businessHourManager.registerBusinessHourType(new DefaultBusinessHour());

presenceEvents.on('user-login', (user: IUser) => {
Accounts.onLogin((user: IUser) => {
void (user?.roles?.includes('livechat-agent') && !user?.roles?.includes('bot') && businessHourManager.onLogin(user._id));
});
});
4 changes: 0 additions & 4 deletions apps/meteor/ee/server/startup/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Meteor } from 'meteor/meteor';
import { InstanceStatus } from '@rocket.chat/instance-status';
import { Presence } from '@rocket.chat/core-services';

import { presenceEvents } from '../../../lib/localEvents';

// update connections count every 30 seconds
const updateConns = throttle(function _updateConns() {
void InstanceStatus.updateConnections(Meteor.server.sessions.size);
Expand Down Expand Up @@ -38,8 +36,6 @@ Meteor.startup(function () {
void (async function () {
await Presence.newConnection(login.user._id, login.connection.id, nodeId);
updateConns();
// User-login event fires after user is logged in & connection status is set
presenceEvents.emit('user-login', login.user);
})();
});

Expand Down
3 changes: 0 additions & 3 deletions apps/meteor/lib/localEvents.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export class UsersRaw extends BaseRaw {
setLivechatStatusActiveBasedOnBusinessHours(userId) {
const query = {
_id: userId,
status: { $ne: 'offline' },
statusDefault: { $ne: 'offline' },
openBusinessHours: {
$exists: true,
$not: { $size: 0 },
Expand Down

0 comments on commit 9585969

Please sign in to comment.