Refines user status flow and isExpired running
This commit is contained in:
+11
-3
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -62,12 +62,15 @@ class UserStatusCache : UserDependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun removeExpired() {
|
fun removeExpired() {
|
||||||
statuses.update { list ->
|
val hasExpired = statuses.value.any { it.event?.isExpired() == true }
|
||||||
val filtered = list.filter { it.event?.isExpired() != true }
|
if (hasExpired) {
|
||||||
if (filtered.size != list.size) {
|
statuses.update { list ->
|
||||||
filtered.toImmutableList()
|
val filtered = list.filter { it.event?.isExpired() != true }
|
||||||
} else {
|
if (filtered.size != list.size) {
|
||||||
list
|
filtered.toImmutableList()
|
||||||
|
} else {
|
||||||
|
list
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user