Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package chat.rocket.android.userdetails.presentation

import chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManager
import chat.rocket.android.db.model.ChatRoomEntity
Expand Down Expand Up @@ -28,6 +29,7 @@ class UserDetailsPresenter @Inject constructor(
private var currentServer = serverInteractor.get()!!
private val manager = factory.create(currentServer)
private val client = manager.client
private val interactor = FetchChatRoomsInteractor(client,dbManager)

fun loadUserDetails(userId: String) {
launchUI(strategy) {
Expand All @@ -40,37 +42,7 @@ class UserDetailsPresenter @Inject constructor(
val openedChatRooms = chatRoomByName(name = u.name)
val avatarUrl = u.username?.let { currentServer.avatarUrl(avatar = it) }

val chatRoom: ChatRoom? = if (openedChatRooms.isEmpty()) {
ChatRoom(
id = "",
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = u.username ?: u.name.orEmpty(),
fullName = u.name,
favorite = false,
open = false,
alert = false,
status = userStatusOf(u.status),
client = client,
broadcast = false,
archived = false,
default = false,
description = null,
groupMentions = null,
userMentions = null,
lastMessage = null,
lastSeen = null,
topic = null,
announcement = null,
roles = null,
unread = 0,
readonly = false,
muted = null,
subscriptionId = "",
timestamp = null,
updatedAt = null,
user = null
)
} else openedChatRooms.firstOrNull()
val chatRoom: ChatRoom? = openedChatRooms.firstOrNull()

view.showUserDetails(
avatarUrl = avatarUrl,
Expand All @@ -93,6 +65,8 @@ class UserDetailsPresenter @Inject constructor(
client.createDirectMessage(username = id)
}

interactor.refreshChatRooms()

val userEntity = withContext(CommonPool) {
dbManager.userDao().getUser(id = id)
}
Expand Down