Refines user status flow and isExpired running

This commit is contained in:
Vitor Pamplona
2026-03-13 13:45:22 -04:00
parent 99eaa37d4c
commit 00f2d46b53
2 changed files with 20 additions and 9 deletions
@@ -38,7 +38,6 @@ import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent import com.vitorpamplona.quartz.nip51Lists.bookmarkList.BookmarkListEvent
import com.vitorpamplona.quartz.nip51Lists.hashtagList.HashtagListEvent import com.vitorpamplona.quartz.nip51Lists.hashtagList.HashtagListEvent
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.FlowPreview
@@ -501,7 +500,15 @@ fun observeUserStatuses(
// Subscribe in the relay for changes in the metadata of this user. // Subscribe in the relay for changes in the metadata of this user.
UserFinderFilterAssemblerSubscription(user, accountViewModel) UserFinderFilterAssemblerSubscription(user, accountViewModel)
return user.statusState().statuses.collectAsStateWithLifecycle(persistentListOf()) val flow =
remember(user) {
user.statusState().statuses.onStart {
user.statusState().removeExpired()
}
}
@SuppressLint("StateFlowValueCalledInComposition")
return flow.collectAsStateWithLifecycle(user.statusState().statuses.value)
} }
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@@ -520,5 +527,6 @@ fun observeUserRelayIntoList(
.flowOn(Dispatchers.IO) .flowOn(Dispatchers.IO)
} }
return flow.collectAsStateWithLifecycle(false) @SuppressLint("StateFlowValueCalledInComposition")
return flow.collectAsStateWithLifecycle(relayUrl in accountViewModel.account.trustedRelays.flow.value)
} }
@@ -62,6 +62,8 @@ class UserStatusCache : UserDependencies {
} }
fun removeExpired() { fun removeExpired() {
val hasExpired = statuses.value.any { it.event?.isExpired() == true }
if (hasExpired) {
statuses.update { list -> statuses.update { list ->
val filtered = list.filter { it.event?.isExpired() != true } val filtered = list.filter { it.event?.isExpired() != true }
if (filtered.size != list.size) { if (filtered.size != list.size) {
@@ -71,4 +73,5 @@ class UserStatusCache : UserDependencies {
} }
} }
} }
}
} }