Commit 2f5473a4 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Merge branch 'develop' of github.com:RocketChat/Rocket.Chat.Android into patch-1

parents 54e7b800 27b10078
......@@ -132,6 +132,8 @@ class ChatRoomPresenter @Inject constructor(
) {
launch(CommonPool + strategy.jobs) {
try {
chatRoomId = roomId
chatRoomType = roomType
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList()
......@@ -172,6 +174,7 @@ class ChatRoomPresenter @Inject constructor(
}
private suspend fun subscribeRoomChanges() {
withContext(CommonPool + strategy.jobs) {
chatRoomId?.let {
manager.addRoomChannel(it, roomChangesChannel)
for (room in roomChangesChannel) {
......@@ -180,6 +183,8 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
}
}
private fun unsubscribeRoomChanges() {
......
......@@ -19,7 +19,6 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageView
......@@ -70,7 +69,6 @@ import chat.rocket.android.helper.MessageParser
import chat.rocket.android.util.extension.asObservable
import chat.rocket.android.util.extension.createImageFile
import chat.rocket.android.util.extensions.circularRevealOrUnreveal
import chat.rocket.android.util.extensions.content
import chat.rocket.android.util.extensions.fadeIn
import chat.rocket.android.util.extensions.fadeOut
import chat.rocket.android.util.extensions.getBitmpap
......
......@@ -168,7 +168,7 @@ class UiModelMapper @Inject constructor(
// TODO: move this to new interactor or FetchChatRoomsInteractor?
private suspend fun getChatRoomAsync(roomId: String): ChatRoom? = withContext(CommonPool) {
return@withContext dbManager.chatRoomDao().getSync(roomId)?.let {
return@withContext dbManager.getRoom(id = roomId)?.let {
with(it.chatRoom) {
ChatRoom(
id = id,
......
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
import chat.rocket.android.server.domain.GetConnectingServerInteractor
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.util.extension.launchUI
......@@ -27,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) {
......@@ -39,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,
......@@ -92,13 +65,14 @@ class UserDetailsPresenter @Inject constructor(
client.createDirectMessage(username = id)
}
interactor.refreshChatRooms()
val userEntity = withContext(CommonPool) {
dbManager.userDao().getUser(id = id)
}
if (userEntity != null) {
view.toDirectMessage(
chatRoom = ChatRoom(
val chatRoom = ChatRoom(
id = result.id,
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = userEntity.username ?: userEntity.name.orEmpty(),
......@@ -127,13 +101,27 @@ class UserDetailsPresenter @Inject constructor(
updatedAt = result.updatedAt,
user = null
)
)
withContext(CommonPool + strategy.jobs) {
dbManager.chatRoomDao().insertOrReplace(chatRoom = ChatRoomEntity(
id = chatRoom.id,
name = chatRoom.name,
description = chatRoom.description,
type = chatRoom.type.toString(),
fullname = chatRoom.fullName,
subscriptionId = chatRoom.subscriptionId,
updatedAt = chatRoom.updatedAt
))
}
view.toDirectMessage(chatRoom = chatRoom)
}
} catch (ex: Exception) {
Timber.e(ex)
view.onOpenDirectMessageError()
}
}
private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) {
return@withContext dbManager.chatRoomDao().getAllSync().filter {
if (name == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment