Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions server/modules/watchers/watchers.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down