diff --git a/package.json b/package.json index 9da349a..a03fbdf 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "idb": "^7.1.1", "light-bolt11-decoder": "^3.0.0", "nano-markdown": "^1.2.2", - "nostr-tools": "^2.4.0", + "nostr-tools": "^2.7.0", "solid-element": "^1.7.1", "solid-js": "^1.8.5" } diff --git a/src/index.tsx b/src/index.tsx index d59cce7..05998ce 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -12,7 +12,7 @@ import { decode } from "nostr-tools/nip19"; import { finalizeEvent, getPublicKey } from "nostr-tools/pure"; import { Filter } from "nostr-tools/filter"; import { AggregateEvent, NoteEvent, eventToNoteEvent } from "./util/models.ts"; -import { SubCloser } from "nostr-tools"; +import { SubCloser } from "nostr-tools/pool"; const ZapThreads = (props: { [key: string]: string; }) => { createComputed(() => { @@ -211,12 +211,14 @@ const ZapThreads = (props: { [key: string]: string; }) => { console.log('[zapthreads] subscribing to', _anchor.value); - const since = await getRelayLatestForFilter(_anchor, _relays); + const relayToSince = await getRelayLatestForFilter(_anchor); + const request = (url: string) => [url, [{ ..._filter, kinds, since: relayToSince[url] || 0 }]]; const newLikeIds = new Set(); const newZaps: { [id: string]: string; } = {}; - sub = pool.subscribeMany(_relays, [{ ..._filter, kinds, since }], + sub = pool.subscribeManyMap( + Object.fromEntries(_relays.map(request)), { onevent(e) { if (e.kind === 1 || e.kind === 9802) { diff --git a/src/util/stores.ts b/src/util/stores.ts index 4751676..3741fab 100644 --- a/src/util/stores.ts +++ b/src/util/stores.ts @@ -6,6 +6,7 @@ import { createMutable } from "solid-js/store"; // Global data (for now) export const pool = new SimplePool(); +pool.trackRelays = true; export const store = createMutable({ rootEventIds: [], diff --git a/src/util/ui.ts b/src/util/ui.ts index 629a387..e5049fd 100644 --- a/src/util/ui.ts +++ b/src/util/ui.ts @@ -53,13 +53,9 @@ export const updateProfiles = async (pubkeys: string[], relays: string[], profil } }; -export const getRelayLatest = async (anchor: Anchor, relayNames: string[]) => { +export const getRelayLatest = async (anchor: Anchor) => { const relaysForAnchor = await findAll('relays', anchor.value, { index: 'a' }); - const relaysLatest = relaysForAnchor.filter(r => relayNames.includes(r.n)).map(t => t.l); - - // TODO Do not use the common minimum, pass each relay's latest as its since - // (but we need to stop using this pool) - return relaysLatest.length > 0 ? Math.min(...relaysLatest) + 1 : 0; + return Object.fromEntries(relaysForAnchor.map(r => [r.n, r.l + 1])); }; // Calculate and save latest created_at to be used as `since`