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 860da6c21fb..82e6b73a963 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 @@ -53,6 +53,8 @@ interface ChatMessageRepository : LifecycleAwareManager { withNetworkParams: Bundle ): Job + fun updateRoomMessages(roomToken: String, limit: Int) + /** * Long polls the server for any updates to the chat, if found, it synchronizes * the database with the server and emits the new messages to [messageFlow], 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 361f40ce096..6bb71be88af 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 androidx.core.os.bundleOf import com.nextcloud.talk.chat.data.ChatMessageRepository import com.nextcloud.talk.chat.data.model.ChatMessage import com.nextcloud.talk.data.database.dao.ChatBlocksDao @@ -250,6 +251,27 @@ class OfflineFirstChatRepository @Inject constructor( updateUiForLastCommonRead() } + override fun updateRoomMessages(roomToken: String, limit: Int) { + scope.launch { + Log.d(TAG, "---- updateRoomMessages ------------") + + delay(200) + + val fieldMap = getFieldMap( + lookIntoFuture = false, + timeout = 0, + includeLastKnown = false, + setReadMarker = true, + lastKnown = null, + limit = limit + ) + + val networkParams = bundleOf() + networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap) + sync(networkParams) + } + } + override fun initMessagePolling(initialMessageId: Long): Job = scope.launch { Log.d(TAG, "---- initMessagePolling ------------") diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index 0efc4d97dc7..5e1b5a236d5 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -476,17 +476,17 @@ class ConversationsListActivity : unreadMessages } - val result = current.map { (model, unreadMessages) -> + val result = current.map { (model, unreadMessages) -> val previousUnreadMessages = previous[model.token] // Check if this conversation exists in last list previousUnreadMessages?.let { Pair(model, unreadMessages - previousUnreadMessages) } }.filterNotNull() - val url = userManager.currentUser.blockingGet().baseUrl!! + val baseUrl = userManager.currentUser.blockingGet().baseUrl!! for (pair in result) { if (pair.second > 0) { - conversationsListViewModel.updateRoomMessages(pair.first, pair.second, credentials!!, url) + conversationsListViewModel.updateRoomMessages(pair.first, pair.second, credentials!!, baseUrl) } } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt index c6c599afd68..a80ddf824a3 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt @@ -16,6 +16,7 @@ import com.nextcloud.talk.invitation.data.InvitationsModel import com.nextcloud.talk.invitation.data.InvitationsRepository import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.users.UserManager +import com.nextcloud.talk.utils.ApiUtils import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -88,7 +89,9 @@ class ConversationsListViewModel @Inject constructor( } fun updateRoomMessages(model: ConversationModel, limit: Int, credentials: String, baseUrl: String) { - // TODO need to edit fetch init messages to include a limit this is rough + val urlForChatting = ApiUtils.getUrlForChat(1, baseUrl, model.token) // FIXME v1? + chatRepository.setData(model, credentials, urlForChatting) + chatRepository.updateRoomMessages(model.token, limit) } inner class FederatedInvitationsObserver : Observer {