From 851e2e7f1087ca215237526b6fb34cf1e4385d82 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Tue, 10 Dec 2024 20:04:43 +0100 Subject: [PATCH] DROID-2966 v0.34.11-beta --- .../anytypeio/anytype/domain/chats/ChatContainer.kt | 12 +++++------- .../presentation/DiscussionViewModel.kt | 6 ++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt b/domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt index 46452760d3..03a35da054 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt @@ -16,6 +16,7 @@ import kotlin.collections.isNotEmpty import kotlin.collections.toList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.emitAll @@ -32,13 +33,11 @@ class ChatContainer @Inject constructor( ) { private val payloads = MutableSharedFlow>() - private val attachments = MutableSharedFlow>(replay = 0) - private val replies = MutableSharedFlow>(replay = 0) + private val attachments = MutableStateFlow>(emptySet()) + private val replies = MutableStateFlow>(emptySet()) - @Deprecated("Naive implementation. Add caching logic - maybe store for wrappers") fun fetchAttachments(space: Space) : Flow> { return attachments - .distinctUntilChanged() .map { ids -> if (ids.isNotEmpty()) { repo.searchObjects( @@ -68,7 +67,6 @@ class ChatContainer @Inject constructor( @Deprecated("Naive implementation. Add caching logic") fun fetchReplies(chat: Id) : Flow> { return replies - .distinctUntilChanged() .map { ids -> if (ids.isNotEmpty()) { repo.getChatMessagesByIds( @@ -96,8 +94,8 @@ class ChatContainer @Inject constructor( repliesIds.add(msg.replyToMessageId.orEmpty()) } } - attachments.emit(attachmentsIds) - replies.emit(repliesIds) + attachments.value = attachmentsIds + replies.value = repliesIds } } diff --git a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionViewModel.kt b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionViewModel.kt index 4219512b64..b54f287ed8 100644 --- a/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionViewModel.kt +++ b/feature-discussions/src/main/java/com/anytypeio/anytype/feature_discussions/presentation/DiscussionViewModel.kt @@ -38,6 +38,9 @@ import javax.inject.Inject import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.combineLatest +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.launch import timber.log.Timber @@ -108,7 +111,6 @@ class DiscussionViewModel @Inject constructor( } } - // TODO move to IO thread. private suspend fun proceedWithObservingChatMessages( account: Id, chat: Id @@ -219,7 +221,7 @@ class DiscussionViewModel @Inject constructor( ) }.reversed() } -// .flowOn(dispatchers.io) + .flowOn(dispatchers.io) .collect { result -> messages.value = result }