From 44988db72f619a6dfe855788dfeecc8d623cb08e Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Mon, 28 Oct 2024 08:27:34 -0500 Subject: [PATCH] User now knows if no offline messages are saved Signed-off-by: rapterjet2004 --- .../com/nextcloud/talk/chat/ChatActivity.kt | 25 ++++++++++++++----- .../talk/chat/data/ChatMessageRepository.kt | 6 +++++ .../network/OfflineFirstChatRepository.kt | 7 ++++++ .../talk/chat/viewmodels/ChatViewModel.kt | 2 ++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index df0adc0ecc..0a7832628a 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -91,13 +91,13 @@ import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder import com.nextcloud.talk.adapters.messages.MessagePayload +import com.nextcloud.talk.adapters.messages.OutcomingDeckCardViewHolder import com.nextcloud.talk.adapters.messages.OutcomingLinkPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingLocationMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingPollMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingVoiceMessageViewHolder -import com.nextcloud.talk.adapters.messages.OutcomingDeckCardViewHolder import com.nextcloud.talk.adapters.messages.PreviewMessageInterface import com.nextcloud.talk.adapters.messages.PreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.SystemMessageInterface @@ -910,6 +910,22 @@ class ChatActivity : .collect() } + this.lifecycleScope.launch { + chatViewModel.getGeneralUIFlow.onEach { key -> + when (key) { + NO_OFFLINE_MESSAGES_FOUND -> { + Snackbar.make( + binding.root, + getString(R.string.no_offline_messages_saved), + Snackbar.LENGTH_LONG + ).show() + } + + else -> {} + } + }.collect() + } + chatViewModel.reactionDeletedViewState.observe(this) { state -> when (state) { is ChatViewModel.ReactionDeletedSuccessState -> { @@ -2767,14 +2783,10 @@ class ChatActivity : message1.timestamp ) val isLessThan5Min = timeDifference > FIVE_MINUTES_IN_SECONDS - if (isSameDayMessages(message2, message1) && + return isSameDayMessages(message2, message1) && (message2.actorId == message1.actorId) && (!isLessThan5Min) && (message2.lastEditTimestamp == 0L || message1.lastEditTimestamp == 0L) - ) { - return true - } - return false } private fun determinePreviousMessageIds(chatMessageList: List) { @@ -3835,5 +3847,6 @@ class ChatActivity : private const val RESUME_AUDIO_TAG = "RESUME_AUDIO_TAG" private const val DELAY_TO_SHOW_PROGRESS_BAR = 1000L private const val FIVE_MINUTES_IN_SECONDS: Long = 300 + const val NO_OFFLINE_MESSAGES_FOUND = "NO_OFFLINE_MESSAGES_FOUND" } } diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt index a55a458031..7980fdcc5e 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/ChatMessageRepository.kt @@ -34,6 +34,12 @@ interface ChatMessageRepository : LifecycleAwareManager { val lastReadMessageFlow: Flow + /** + * Used for informing the user of the underlying processing behind offline support, [String] is the key + * which is handled in a switch statement in ChatActivity. + */ + val generalUIFlow: Flow + fun setData(conversationModel: ConversationModel, credentials: String, urlForChatting: String) fun loadInitialMessages(withNetworkParams: Bundle): Job diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt index 4c52f7f315..287736016b 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt @@ -10,6 +10,7 @@ package com.nextcloud.talk.chat.data.network import android.os.Bundle import android.util.Log +import com.nextcloud.talk.chat.ChatActivity import com.nextcloud.talk.chat.data.ChatMessageRepository import com.nextcloud.talk.chat.data.model.ChatMessage import com.nextcloud.talk.data.database.dao.ChatBlocksDao @@ -89,6 +90,11 @@ class OfflineFirstChatRepository @Inject constructor( private val _lastReadMessageFlow: MutableSharedFlow = MutableSharedFlow() + override val generalUIFlow: Flow + get() = _generalUIFlow + + private val _generalUIFlow: MutableSharedFlow = MutableSharedFlow() + private var newXChatLastCommonRead: Int? = null private var itIsPaused = false private val scope = CoroutineScope(Dispatchers.IO) @@ -131,6 +137,7 @@ class OfflineFirstChatRepository @Inject constructor( } else { if (!weAlreadyHaveSomeOfflineMessages) { Log.d(TAG, "An online request for newest 100 messages is made because offline chat is empty") + _generalUIFlow.emit(ChatActivity.NO_OFFLINE_MESSAGES_FOUND) } else { Log.d( TAG, diff --git a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt index 39a09bdcb0..fb725102bd 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt @@ -131,6 +131,8 @@ class ChatViewModel @Inject constructor( _getRoomViewState.value = GetRoomErrorState } + val getGeneralUIFlow = chatRepository.generalUIFlow + sealed interface ViewState object GetReminderStartState : ViewState diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 63e6ffd844..3ca462c73c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -817,4 +817,5 @@ How to translate with transifex: Show ban reason Error occurred when unbanning participant Connection lost + No offline messages saved