From fe2740c00e84e150fab2c49938f22d05e21f03dc Mon Sep 17 00:00:00 2001 From: Jure <44338+hoornet@users.noreply.github.com> Date: Thu, 26 Mar 2026 10:40:12 +0100 Subject: [PATCH] Always include focused note in thread tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When relay doesn't return the clicked note in the thread fetch results, the user sees only the root note with 'No replies yet' — making it look like the wrong thread opened. Now the focused event and its ancestors are always injected into the thread tree since we already have them in memory. --- src/components/thread/ThreadView.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/thread/ThreadView.tsx b/src/components/thread/ThreadView.tsx index a95a4f2..4ca804d 100644 --- a/src/components/thread/ThreadView.tsx +++ b/src/components/thread/ThreadView.tsx @@ -56,6 +56,7 @@ export function ThreadView() { const rootId = getRootEventId(focusedEvent); let root: NDKEvent; + let fetchedAncestors: NDKEvent[] = []; if (!rootId || rootId === focusedEvent.id) { root = focusedEvent; @@ -63,8 +64,9 @@ export function ThreadView() { const fetched = await fetchNoteById(rootId); if (fetched) { root = fetched; - const anc = await fetchAncestors(focusedEvent); - if (!cancelled) setAncestors(anc.filter((a) => a.id !== root.id)); + fetchedAncestors = await fetchAncestors(focusedEvent); + fetchedAncestors = fetchedAncestors.filter((a) => a.id !== root.id); + if (!cancelled) setAncestors(fetchedAncestors); } else { root = focusedEvent; if (!cancelled) setLoadError("Could not fetch the root note — relay may be slow."); @@ -77,7 +79,18 @@ export function ThreadView() { const events = await fetchThreadEvents(root.id); if (cancelled) return; + // Build event list: root + thread replies + focused event + ancestors + // Always include focused event — relay may not return it in thread fetch const allEvents = [root, ...events.filter((e) => e.id !== root.id)]; + if (focusedEvent.id !== root.id && !allEvents.some((e) => e.id === focusedEvent.id)) { + allEvents.push(focusedEvent); + } + for (const anc of fetchedAncestors) { + if (!allEvents.some((e) => e.id === anc.id)) { + allEvents.push(anc); + } + } + const built = buildThreadTree(root.id, allEvents); setTree(built);