diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-06-05 12:54:58 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-09 11:02:36 -0400 |
| commit | 1f2742ddd7ba462b715a4fe2ae25d3dedebec3e0 (patch) | |
| tree | f17a97b0d9debd9229acde1c6edd7de043ad032d | |
| parent | implement QuantumKVCache (diff) | |
| download | sharkey-1f2742ddd7ba462b715a4fe2ae25d3dedebec3e0.tar.gz sharkey-1f2742ddd7ba462b715a4fe2ae25d3dedebec3e0.tar.bz2 sharkey-1f2742ddd7ba462b715a4fe2ae25d3dedebec3e0.zip | |
add ignoreRemote filter to InternalEventService
| -rw-r--r-- | packages/backend/src/core/InternalEventService.ts | 7 | ||||
| -rw-r--r-- | packages/backend/test/misc/FakeInternalEventService.ts | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/packages/backend/src/core/InternalEventService.ts b/packages/backend/src/core/InternalEventService.ts index 375ee928c4..5b164b605e 100644 --- a/packages/backend/src/core/InternalEventService.ts +++ b/packages/backend/src/core/InternalEventService.ts @@ -10,10 +10,11 @@ import { GlobalEventService } from '@/core/GlobalEventService.js'; import type { GlobalEvents, InternalEventTypes } from '@/core/GlobalEventService.js'; import { bindThis } from '@/decorators.js'; -export type Listener<K extends keyof InternalEventTypes> = (value: InternalEventTypes[K], key: K) => void | Promise<void>; +export type Listener<K extends keyof InternalEventTypes> = (value: InternalEventTypes[K], key: K, isLocal: boolean) => void | Promise<void>; export interface ListenerProps { ignoreLocal?: boolean, + ignoreRemote?: boolean, } @Injectable() @@ -61,8 +62,8 @@ export class InternalEventService implements OnApplicationShutdown { const promises: Promise<void>[] = []; for (const [listener, props] of listeners) { - if (!isLocal || !props.ignoreLocal) { - const promise = Promise.resolve(listener(value, type)); + if ((isLocal && !props.ignoreLocal) || (!isLocal && !props.ignoreRemote)) { + const promise = Promise.resolve(listener(value, type, isLocal)); promises.push(promise); } } diff --git a/packages/backend/test/misc/FakeInternalEventService.ts b/packages/backend/test/misc/FakeInternalEventService.ts index ffe8b81d78..d18a080eaf 100644 --- a/packages/backend/test/misc/FakeInternalEventService.ts +++ b/packages/backend/test/misc/FakeInternalEventService.ts @@ -70,8 +70,8 @@ export class FakeInternalEventService extends InternalEventService { public async emit<K extends keyof InternalEventTypes>(type: K, value: InternalEventTypes[K], isLocal = true): Promise<void> { for (const listener of this._listeners) { if (listener[0] === type) { - if (!isLocal || !listener[2].ignoreLocal) { - await listener[1](value, type); + if ((isLocal && !listener[2].ignoreLocal) || (!isLocal && !listener[2].ignoreRemote)) { + await listener[1](value, type, isLocal); } } } |