[FIX] Omnichannel status being changed on page refresh (#23587)

* fix omnichannel status being changed on page refresh

* rename key missing

* Remove duplicated function from models
pull/23380/head
Kevin Aleman 4 years ago committed by GitHub
parent 2291b80cda
commit 55fafd0eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/livechat/server/business-hour/AbstractBusinessHour.ts
  2. 7
      app/livechat/server/lib/Livechat.js
  3. 2
      app/livechat/server/startup.js
  4. 1
      app/models/server/models/Users.js
  5. 4
      app/models/server/raw/Users.js

@ -47,7 +47,7 @@ export abstract class AbstractBusinessHourBehavior {
}
async changeAgentActiveStatus(agentId: string, status: string): Promise<any> {
return this.UsersRepository.setLivechatStatus(agentId, status);
return this.UsersRepository.setLivechatStatusIf(agentId, status, { livechatStatusSystemModified: true }, { livechatStatusSystemModified: true });
}
}

@ -40,6 +40,7 @@ import { normalizeTransferredByData, parseAgentCustomFields, updateDepartmentAge
import { Apps, AppEvents } from '../../../apps/server';
import { businessHourManager } from '../business-hour';
import notifications from '../../../notifications/server/lib/Notifications';
import { Users as UsersRaw } from '../../../models/server/raw';
const logger = new Logger('Livechat');
@ -886,6 +887,12 @@ export const Livechat = {
return user;
},
setUserStatusLivechatIf(userId, status, condition, fields) {
const user = Promise.await(UsersRaw.setLivechatStatusIf(userId, status, condition, fields));
callbacks.runAsync('livechat.setUserStatusLivechat', { userId, status });
return user;
},
cleanGuestHistory(_id) {
const guest = LivechatVisitors.findOneById(_id);
if (!guest) {

@ -62,5 +62,5 @@ Meteor.startup(async () => {
RoutingManager.setMethodNameAndStartQueue(value);
});
Accounts.onLogout(({ user }) => user?.roles?.includes('livechat-agent') && !user?.roles?.includes('bot') && Livechat.setUserStatusLivechat(user._id, 'not-available'));
Accounts.onLogout(({ user }) => user?.roles?.includes('livechat-agent') && !user?.roles?.includes('bot') && Livechat.setUserStatusLivechatIf(user._id, 'not-available', {}, { livechatStatusSystemModified: true }));
});

@ -262,6 +262,7 @@ export class Users extends Base {
const update = {
$set: {
statusLivechat: status,
livechatStatusSystemModified: false,
},
};

@ -259,14 +259,16 @@ export class UsersRaw extends BaseRaw {
return result.value;
}
setLivechatStatus(userId, status) { // TODO: Create class Agent
setLivechatStatusIf(userId, status, conditions = {}, extraFields = {}) { // TODO: Create class Agent
const query = {
_id: userId,
...conditions,
};
const update = {
$set: {
statusLivechat: status,
...extraFields,
},
};

Loading…
Cancel
Save