Skip to content
Snippets Groups Projects
Unverified Commit e4839357 authored by Diego Sampaio's avatar Diego Sampaio
Browse files

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

parent 55457025
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment