[FIX] Support DISABLE_PRESENCE_MONITOR env var in new DB watchers (#22257)

pull/22258/head^2
Diego Sampaio 5 years ago committed by GitHub
parent 1b568ca0ee
commit 8a1eb6ed6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      server/modules/watchers/watchers.module.ts

@ -66,6 +66,9 @@ type Watcher = <T extends IBaseData>(model: IBaseRaw<T>, fn: (event: IChange<T>)
type BroadcastCallback = <T extends keyof EventSignatures>(event: T, ...args: Parameters<EventSignatures[T]>) => Promise<void>;
const startMonitor = typeof process.env.DISABLE_PRESENCE_MONITOR === 'undefined'
|| !['true', 'yes'].includes(String(process.env.DISABLE_PRESENCE_MONITOR).toLowerCase());
export function initWatchers(models: IModelsParam, broadcast: BroadcastCallback, watch: Watcher): void {
const {
Messages,
@ -164,22 +167,24 @@ export function initWatchers(models: IModelsParam, broadcast: BroadcastCallback,
});
});
watch<IUserSession>(UsersSessions, async ({ clientAction, id, data }) => {
switch (clientAction) {
case 'inserted':
case 'updated':
data = data ?? await UsersSessions.findOneById(id);
if (!data) {
return;
}
if (startMonitor) {
watch<IUserSession>(UsersSessions, async ({ clientAction, id, data }) => {
switch (clientAction) {
case 'inserted':
case 'updated':
data = data ?? await UsersSessions.findOneById(id);
if (!data) {
return;
}
broadcast('watch.userSessions', { clientAction, userSession: data });
break;
case 'removed':
broadcast('watch.userSessions', { clientAction, userSession: { _id: id } });
break;
}
});
broadcast('watch.userSessions', { clientAction, userSession: data });
break;
case 'removed':
broadcast('watch.userSessions', { clientAction, userSession: { _id: id } });
break;
}
});
}
watch<IInquiry>(LivechatInquiry, async ({ clientAction, id, data, diff }) => {
switch (clientAction) {

Loading…
Cancel
Save