|
|
|
|
@ -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) { |
|
|
|
|
|