From 543419c3ef79c6d26ca6a474f4cb3e8d36ff78b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 16 Jun 2026 13:04:14 +0000 Subject: [PATCH] refactor: let ThreadFilterSubAssembler own root resolution for reply preload Pass the reply's id straight to the thread subscription instead of resolving the root in composition. ThreadFilterSubAssembler already runs findRoot in updateFilter, so the extra compose-side findRoot was duplicate work; gate on replyTo so only replies (not roots or quotes) pre-load. --- .../ThreadFilterAssemblerSubscription.kt | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/datasources/ThreadFilterAssemblerSubscription.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/datasources/ThreadFilterAssemblerSubscription.kt index 75e206a528..78d03ffc58 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/datasources/ThreadFilterAssemblerSubscription.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/datasources/ThreadFilterAssemblerSubscription.kt @@ -22,10 +22,8 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.threadview.datasources import androidx.compose.runtime.Composable import androidx.compose.runtime.remember -import com.vitorpamplona.amethyst.commons.model.ThreadAssembler import com.vitorpamplona.amethyst.commons.relayClient.subscriptions.LifecycleAwareKeyDataSourceSubscription import com.vitorpamplona.amethyst.model.Account -import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.quartz.nip01Core.core.HexKey @@ -59,25 +57,20 @@ fun ThreadFilterAssemblerSubscription( /** * Eagerly pre-loads the whole thread of a reply that is visible in a feed. * - * When a reply shows up in `NoteCompose`, this resolves the thread root and opens - * the same root subscription the thread screen uses (a filter on the root's `e`/`a` - * tag, covering NIP-10 and NIP-22 event/addressable roots), so tapping into the - * conversation finds it already loaded. Keying on the resolved root id means every - * visible reply that shares a root collapses onto a single subscription, and a note - * that is itself a root (no parent) is skipped — nothing to pre-load. + * When a reply shows up in `NoteCompose`, this opens the same root subscription the + * thread screen uses: `ThreadFilterSubAssembler` resolves the thread root from this + * id and subscribes to the root's `e`/`a` tag (covering NIP-10 and NIP-22 event / + * addressable roots), so tapping into the conversation finds it already loaded. + * + * Only replies are pre-loaded — a root post (empty `replyTo`) has no ancestor thread + * to pull, and pure quotes are excluded because citations don't populate `replyTo`. */ @Composable fun PreloadThreadForReply( note: Note, accountViewModel: AccountViewModel, ) { - val rootId = - remember(note) { - val root = ThreadAssembler(LocalCache).findRoot(note.idHex) - if (root != null && root != note) root.idHex else null - } - - if (rootId != null) { - ThreadFilterAssemblerSubscription(rootId, accountViewModel) + if (note.replyTo?.isNotEmpty() == true) { + ThreadFilterAssemblerSubscription(note.idHex, accountViewModel) } }