mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
load conversation from DB first, then update by request if connection is available
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
818a843143
commit
b1d6086684
@ -225,7 +225,7 @@ class ChatViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun getRoom(user: User, token: String) {
|
fun getRoom(user: User, token: String) {
|
||||||
_getRoomViewState.value = GetRoomStartState
|
_getRoomViewState.value = GetRoomStartState
|
||||||
conversationRepository.getConversationSettings(token)
|
conversationRepository.getRoom(token)
|
||||||
|
|
||||||
// chatNetworkDataSource.getRoom(user, token)
|
// chatNetworkDataSource.getRoom(user, token)
|
||||||
// .subscribeOn(Schedulers.io())
|
// .subscribeOn(Schedulers.io())
|
||||||
|
@ -35,5 +35,5 @@ interface OfflineConversationsRepository {
|
|||||||
* Called once onStart to emit a conversation to [conversationFlow]
|
* Called once onStart to emit a conversation to [conversationFlow]
|
||||||
* to be handled asynchronously.
|
* to be handled asynchronously.
|
||||||
*/
|
*/
|
||||||
fun getConversationSettings(roomToken: String): Job
|
fun getRoom(roomToken: String): Job
|
||||||
}
|
}
|
||||||
|
@ -56,17 +56,19 @@ class OfflineFirstConversationsRepository @Inject constructor(
|
|||||||
|
|
||||||
override fun getRooms(): Job =
|
override fun getRooms(): Job =
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val resultsFromSync = sync()
|
val initialConversationModels = getListOfConversations(user.id!!)
|
||||||
if (!resultsFromSync.isNullOrEmpty()) {
|
_roomListFlow.emit(initialConversationModels)
|
||||||
val conversations = resultsFromSync.map(ConversationEntity::asModel)
|
|
||||||
_roomListFlow.emit(conversations)
|
if (monitor.isOnline.first()) {
|
||||||
} else {
|
val conversationEntitiesFromSync = getRoomsFromServer()
|
||||||
val conversationsFromDb = getListOfConversations(user.id!!)
|
if (!conversationEntitiesFromSync.isNullOrEmpty()) {
|
||||||
_roomListFlow.emit(conversationsFromDb)
|
val conversationModelsFromSync = conversationEntitiesFromSync.map(ConversationEntity::asModel)
|
||||||
|
_roomListFlow.emit(conversationModelsFromSync)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationSettings(roomToken: String): Job =
|
override fun getRoom(roomToken: String): Job =
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val id = user.id!!
|
val id = user.id!!
|
||||||
val model = getConversation(id, roomToken)
|
val model = getConversation(id, roomToken)
|
||||||
@ -100,7 +102,7 @@ class OfflineFirstConversationsRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun sync(): List<ConversationEntity>? {
|
private suspend fun getRoomsFromServer(): List<ConversationEntity>? {
|
||||||
var conversationsFromSync: List<ConversationEntity>? = null
|
var conversationsFromSync: List<ConversationEntity>? = null
|
||||||
|
|
||||||
if (!monitor.isOnline.first()) {
|
if (!monitor.isOnline.first()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user