mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-11 00:37:41 +00:00
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.
This commit is contained in:
+9
-16
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user