diff --git a/src/app/core/requests.ts b/src/app/core/requests.ts index abfecfc6..6c45ec70 100644 --- a/src/app/core/requests.ts +++ b/src/app/core/requests.ts @@ -131,8 +131,55 @@ export const makeFeed = ({ insertEvent(event) } + const reveal = (id: string, targetEvent?: TrustedEvent) => { + const current = get(events) + + if (current.find(e => e.id === id)) { + return true + } + + const queued = get(buffer) + const index = queued.findIndex(e => e.id === id) + + if (index === -1) { + const event = targetEvent || repository.getEvent(id) + + if (event && matchFilters(filters, event)) { + insertEvent(event) + + const next = get(events) + + if (next.find(e => e.id === id)) { + return true + } + + const queuedNext = get(buffer) + const queuedIndex = queuedNext.findIndex(e => e.id === id) + + if (queuedIndex > -1) { + const count = Math.max(30, queuedIndex + 1) + const chunk = queuedNext.splice(0, count) + + events.update($events => [...$events, ...chunk]) + + return true + } + } + + return false + } + + const count = Math.max(30, index + 1) + const chunk = queued.splice(0, count) + + events.update($events => [...$events, ...chunk]) + + return true + } + return { events, + reveal, cleanup: () => { scroller.stop() controller.abort() diff --git a/src/lib/html.ts b/src/lib/html.ts index adfd6aca..cc8e1b4f 100644 --- a/src/lib/html.ts +++ b/src/lib/html.ts @@ -118,6 +118,10 @@ export const scrollToEvent = async (id: string, attempts = 3): Promise return true } else if (elements.length > 0) { + if (attempts <= 0) { + return false + } + const lastElement = last(elements) if (lastElement && !isIntersecting(lastElement)) { @@ -126,11 +130,7 @@ export const scrollToEvent = async (id: string, attempts = 3): Promise await sleep(300) - if (attempts > 0) { - return scrollToEvent(id, attempts - 1) - } else { - return false - } + return scrollToEvent(id, attempts - 1) } return false diff --git a/src/routes/spaces/[relay]/[h]/+page.svelte b/src/routes/spaces/[relay]/[h]/+page.svelte index 53dd5624..957159b3 100644 --- a/src/routes/spaces/[relay]/[h]/+page.svelte +++ b/src/routes/spaces/[relay]/[h]/+page.svelte @@ -1,56 +1,73 @@