diff --git a/UI/event_syncer.ts b/UI/event_syncer.ts index 3678ae8..478d60d 100644 --- a/UI/event_syncer.ts +++ b/UI/event_syncer.ts @@ -8,26 +8,15 @@ export class EventSyncer { constructor(private readonly pool: ConnectionPool, private readonly db: Database_Contextual_View) {} syncEvent(id: NoteID) { + const subID = EventSyncer.name + ":syncEvent"; for (const e of this.db.events) { if (e.id == id.hex) { return e; } } return (async () => { - let events: Error | { - filter: NostrFilters; - chan: Channel<{ - res: RelayResponse_REQ_Message; - url: string; - }>; - } = await this.pool.newSub("EventSyncer", { - ids: [id.hex], - }); - if (events instanceof SubscriptionAlreadyExist) { - events = await this.pool.updateSub("EventSyncer", { - ids: [id.hex], - }); - } + await this.pool.closeSub(subID); + let events = await this.pool.newSub(subID, { ids: [id.hex] }); if (events instanceof Error) { return events; } @@ -35,11 +24,6 @@ export class EventSyncer { if (res.type != "EVENT") { continue; } - const ok = await verifyEvent(res.event); - if (!ok) { - console.warn(res.event, url, "not valid"); - continue; - } await this.db.addEvent(res.event); return; // just need to read from 1 relay } @@ -47,16 +31,8 @@ export class EventSyncer { } async syncEvents(filter: NostrFilters) { - let events: Error | { - filter: NostrFilters; - chan: Channel<{ - res: RelayResponse_REQ_Message; - url: string; - }>; - } = await this.pool.newSub("syncEvents", filter); - if (events instanceof SubscriptionAlreadyExist) { - events = await this.pool.updateSub("syncEvents", filter); - } + await this.pool.closeSub(EventSyncer.name); + let events = await this.pool.newSub(EventSyncer.name, filter); if (events instanceof Error) { return events; } @@ -64,11 +40,6 @@ export class EventSyncer { if (res.type != "EVENT") { continue; } - const ok = await verifyEvent(res.event); - if (!ok) { - console.warn(res.event, url, "not valid"); - continue; - } await this.db.addEvent(res.event); } } diff --git a/features/profile.ts b/features/profile.ts index 83747d9..c78b90e 100644 --- a/features/profile.ts +++ b/features/profile.ts @@ -11,7 +11,8 @@ export class ProfilesSyncer { constructor( private readonly database: Database_Contextual_View, private readonly pool: ConnectionPool, - ) {} + ) { + } async add(...users: string[]) { const size = this.userSet.size; @@ -21,13 +22,11 @@ export class ProfilesSyncer { if (this.userSet.size == size) { return; } - const resp = await this.pool.updateSub( - "profilesStream", - { - authors: Array.from(this.userSet), - kinds: [NostrKind.META_DATA], - }, - ); + await this.pool.closeSub(ProfilesSyncer.name); + const resp = await this.pool.newSub(ProfilesSyncer.name, { + authors: Array.from(this.userSet), + kinds: [NostrKind.META_DATA], + }); if (resp instanceof Error) { console.error(resp.message); return; diff --git a/lib/nostr-ts b/lib/nostr-ts index c1047e8..95603f6 160000 --- a/lib/nostr-ts +++ b/lib/nostr-ts @@ -1 +1 @@ -Subproject commit c1047e8348d89be7934516e1f5ddda26eb14b75c +Subproject commit 95603f6c6cca8b4affba80502a7906cca1f92bb3