Skip to content

Commit

Permalink
Got it loading on refresh
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Nov 25, 2024
1 parent f90822b commit 70eb6bd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ------------")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.nextcloud.talk.chat.data.network.ChatNetworkDataSource
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.participants.TalkBan
import com.nextcloud.talk.repositories.conversations.ConversationsRepository
import com.nextcloud.talk.utils.ApiUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<InvitationsModel> {
Expand Down

0 comments on commit 70eb6bd

Please sign in to comment.