From 4a590d67a640ed2c34ef18d494bb8054c874f3d3 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Sun, 17 Nov 2024 10:48:03 +0100 Subject: [PATCH] move filtering of "not your drafts" to ThreadFeedFilter --- .../amethyst/ui/dal/ThreadFeedFilter.kt | 14 +++++++++++--- .../screen/loggedIn/threadview/ThreadFeedView.kt | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ThreadFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ThreadFeedFilter.kt index 21374035d..bc80e6fb2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ThreadFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ThreadFeedFilter.kt @@ -27,11 +27,12 @@ import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.ThreadAssembler import com.vitorpamplona.amethyst.model.ThreadLevelCalculator import com.vitorpamplona.quartz.utils.TimeUtils +import kotlinx.collections.immutable.toImmutableSet @Immutable class ThreadFeedFilter( val account: Account, - val noteId: String, + private val noteId: String, ) : FeedFilter() { override fun feedKey(): String = noteId @@ -40,7 +41,14 @@ class ThreadFeedFilter( val followingKeySet = account.liveKind3Follows.value.authors val eventsToWatch = ThreadAssembler().findThreadFor(noteId) ?: return emptyList() - val eventsInHex = eventsToWatch.allNotes.map { it.idHex }.toSet() + // Filter out drafts made by other accounts on device + val filteredEvents = + eventsToWatch.allNotes + .filter { !it.isDraft() || (it.author?.pubkeyHex == account.userProfile().pubkeyHex) } + .toImmutableSet() + val filteredThreadInfo = ThreadAssembler.ThreadInfo(eventsToWatch.root, filteredEvents) + + val eventsInHex = filteredThreadInfo.allNotes.map { it.idHex }.toSet() val now = TimeUtils.now() // Currently orders by date of each event, descending, at each level of the reply stack @@ -57,6 +65,6 @@ class ThreadFeedFilter( ).signature } - return eventsToWatch.allNotes.sortedWith(order) + return filteredThreadInfo.allNotes.sortedWith(order) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt index d79a6974b..da2f81c48 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt @@ -268,7 +268,7 @@ fun RenderThreadFeed( contentPadding = FeedPadding, state = listState, ) { - itemsIndexed(items.list.filter { !it.isDraft() || (it.author?.pubkeyHex == accountViewModel.account.userProfile().pubkeyHex) }, key = { _, item -> item.idHex }) { index, item -> + itemsIndexed(items.list, key = { _, item -> item.idHex }) { index, item -> val level = viewModel.levelFlowForItem(item).collectAsStateWithLifecycle(0) val modifier =