diff --git a/packages/app/src/Pages/Notifications.tsx b/packages/app/src/Pages/Notifications.tsx index 6e9b9032..30cef0c6 100644 --- a/packages/app/src/Pages/Notifications.tsx +++ b/packages/app/src/Pages/Notifications.tsx @@ -1,12 +1,14 @@ -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import Timeline from "Element/Timeline"; import { TaskList } from "Tasks/TaskList"; import useLogin from "Hooks/useLogin"; import { markNotificationsRead } from "Login"; +import { unixNow } from "Util"; export default function NotificationsPage() { const login = useLogin(); + const [now] = useState(unixNow()); useEffect(() => { markNotificationsRead(login); @@ -24,6 +26,8 @@ export default function NotificationsPage() { items: [login.publicKey], discriminator: login.publicKey.slice(0, 12), }} + now={now} + window={60 * 60 * 12} postsOnly={false} method={"TIME_RANGE"} /> diff --git a/packages/app/src/System/ProfileCache.ts b/packages/app/src/System/ProfileCache.ts index bd549638..9add0168 100644 --- a/packages/app/src/System/ProfileCache.ts +++ b/packages/app/src/System/ProfileCache.ts @@ -65,19 +65,23 @@ class ProfileLoaderService { const q = System.Query(PubkeyReplaceableNoteStore, sub); // never release this callback, it will stop firing anyway after eose - const releaseOnEvent = q.onEvent(e => this.onProfileEvent(e)); + const releaseOnEvent = q.onEvent(async e => { + await this.onProfileEvent(e); + }); const results = await new Promise>>(resolve => { let timeout: ReturnType | undefined = undefined; const release = q.hook(() => { if (!q.loading) { clearTimeout(timeout); resolve(q.getSnapshotData() ?? []); + console.debug("Profiles finished: ", sub.id); + release(); } - release(); }); timeout = setTimeout(() => { release(); resolve(q.getSnapshotData() ?? []); + console.debug("Profiles timeout: ", sub.id); }, 5_000); }); diff --git a/packages/app/src/System/Query.test.ts b/packages/app/src/System/Query.test.ts index 3771e2d6..3fece031 100644 --- a/packages/app/src/System/Query.test.ts +++ b/packages/app/src/System/Query.test.ts @@ -1,18 +1,23 @@ import { Connection } from "@snort/nostr"; import { Query } from "./Query"; import { getRandomValues } from "crypto"; +import { FlatNoteStore } from "./NoteCollection"; window.crypto = {} as any; window.crypto.getRandomValues = getRandomValues as any; describe("query", () => { test("progress", () => { - const q = new Query("test", [ - { - kinds: [1], - authors: ["test"], - }, - ]); + const q = new Query( + "test", + [ + { + kinds: [1], + authors: ["test"], + }, + ], + new FlatNoteStore() + ); const opt = { read: true, write: true, @@ -38,12 +43,16 @@ describe("query", () => { q.eose(q.id, c3); expect(q.progress).toBe(1); - const qs = new Query("test-1", [ - { - kinds: [1], - authors: ["test-sub"], - }, - ]); + const qs = new Query( + "test-1", + [ + { + kinds: [1], + authors: ["test-sub"], + }, + ], + new FlatNoteStore() + ); q.subQueries.push(qs); qs.sendToRelay(c1); diff --git a/packages/app/src/System/Query.ts b/packages/app/src/System/Query.ts index 088681a1..9b9f7a3e 100644 --- a/packages/app/src/System/Query.ts +++ b/packages/app/src/System/Query.ts @@ -121,9 +121,9 @@ export class Query { /** * Feed object which collects events */ - #feed?: NoteStore; + #feed: NoteStore; - constructor(id: string, filters: Array, feed?: NoteStore) { + constructor(id: string, filters: Array, feed: NoteStore) { this.id = id; this.filters = filters; this.#feed = feed; @@ -190,14 +190,12 @@ export class Query { } eose(sub: string, conn: Readonly) { - const qt = this.#tracing.filter(a => a.subId === sub && a.connId === conn.Id); + const qt = this.#tracing.find(a => a.subId === sub && a.connId === conn.Id); + qt?.gotEose(); if (sub === this.id) { console.debug(`[EOSE][${sub}] ${conn.Address}`); - qt.forEach(a => a.gotEose()); - if (this.#feed) { - this.#feed.loading = this.progress < 1; - } - if (!this.leaveOpen) { + this.#feed.loading = this.progress < 1; + if (!this.leaveOpen && !this.#feed.loading) { this.sendClose(); } } else { diff --git a/packages/app/src/System/index.ts b/packages/app/src/System/index.ts index e65defe1..b4546173 100644 --- a/packages/app/src/System/index.ts +++ b/packages/app/src/System/index.ts @@ -212,14 +212,13 @@ export class NostrSystem { this.#changed(); return unwrap(q.feed) as Readonly; } else { - const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters); + const subQ = new Query(`${q.id}-${q.subQueries.length + 1}`, filters, q.feed); q.subQueries.push(subQ); q.filters = filters; - const f = unwrap(q.feed); - f.loading = true; + q.feed.loading = true; this.SendQuery(subQ); this.#changed(); - return f as Readonly; + return q.feed as Readonly; } } else { return this.AddQuery(type, req);