move filtering of "not your drafts" to ThreadFeedFilter

This commit is contained in:
David Kaspar 2024-11-17 10:48:03 +01:00
parent 6c3200a9cc
commit 4a590d67a6
2 changed files with 12 additions and 4 deletions

View File

@ -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<Note>() {
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)
}
}

View File

@ -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 =