diff --git a/src/engine/index.ts b/src/engine/index.ts index 6efc9634..fa942f6c 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -3,4 +3,3 @@ export * from "src/engine/utils" export * from "src/engine/state" export * from "src/engine/requests" export * from "src/engine/commands" -export * from "src/engine/projections" diff --git a/src/engine/projections.ts b/src/engine/projections.ts deleted file mode 100644 index 8ee94dc0..00000000 --- a/src/engine/projections.ts +++ /dev/null @@ -1,29 +0,0 @@ -import {ensurePlaintext, repository} from "@welshman/app" -import type {TrustedEvent} from "@welshman/util" -import { - APP_DATA, - FOLLOWS, - MUTES, - SEEN_CONTEXT, - SEEN_CONVERSATION, - SEEN_GENERAL, -} from "@welshman/util" -import {projections} from "src/engine/state" - -// Synchronize repository with projections. All events should be published to the -// repository, and when accepted, be propagated to projections. This avoids processing -// the same event multiple times, since repository deduplicates -repository.on("update", ({added}: {added: TrustedEvent[]}) => { - for (const event of added) { - projections.push(event) - } -}) - -// Decrypt encrypted events eagerly - -projections.addHandler(SEEN_GENERAL, ensurePlaintext) -projections.addHandler(SEEN_CONTEXT, ensurePlaintext) -projections.addHandler(SEEN_CONVERSATION, ensurePlaintext) -projections.addHandler(APP_DATA, ensurePlaintext) -projections.addHandler(FOLLOWS, ensurePlaintext) -projections.addHandler(MUTES, ensurePlaintext) diff --git a/src/engine/state.ts b/src/engine/state.ts index 7d30e8ae..6b95bdea 100644 --- a/src/engine/state.ts +++ b/src/engine/state.ts @@ -3,6 +3,7 @@ import { subscribe as baseSubscribe, db, displayProfileByPubkey, + ensurePlaintext, followsByPubkey, freshness, getDefaultAppContext, @@ -71,6 +72,7 @@ import { HANDLER_RECOMMENDATION, LABEL, LOCAL_RELAY_URL, + MUTES, NAMED_BOOKMARKS, SEEN_CONTEXT, SEEN_CONVERSATION, @@ -156,6 +158,21 @@ export const projections = new Worker({ getKey: prop("kind"), }) +projections.addGlobalHandler(ensurePlaintext) + +const decryptKinds = [SEEN_GENERAL, SEEN_CONTEXT, SEEN_CONVERSATION, APP_DATA, FOLLOWS, MUTES] + +// Synchronize repository with projections. All events should be published to the +// repository, and when accepted, be propagated to projections. This avoids processing +// the same event multiple times, since repository deduplicates +repository.on("update", ({added}: {added: TrustedEvent[]}) => { + for (const event of added) { + if (decryptKinds.includes(event.kind)) { + projections.push(event) + } + } +}) + // Plaintext export const ensureMessagePlaintext = async (e: TrustedEvent) => {