Unverified Commit a2535dd8 authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge pull request #1947 from RocketChat/fix-first-time-dm-dont-show-messages

[FIX] Insert ChatRoom on db for the direct message about to be displayed
parents 61318332 073ca90f
...@@ -132,6 +132,8 @@ class ChatRoomPresenter @Inject constructor( ...@@ -132,6 +132,8 @@ class ChatRoomPresenter @Inject constructor(
) { ) {
launch(CommonPool + strategy.jobs) { launch(CommonPool + strategy.jobs) {
try { try {
chatRoomId = roomId
chatRoomType = roomType
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) { chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName) client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
} else emptyList() } else emptyList()
...@@ -172,6 +174,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -172,6 +174,7 @@ class ChatRoomPresenter @Inject constructor(
} }
private suspend fun subscribeRoomChanges() { private suspend fun subscribeRoomChanges() {
withContext(CommonPool + strategy.jobs) {
chatRoomId?.let { chatRoomId?.let {
manager.addRoomChannel(it, roomChangesChannel) manager.addRoomChannel(it, roomChangesChannel)
for (room in roomChangesChannel) { for (room in roomChangesChannel) {
...@@ -180,6 +183,8 @@ class ChatRoomPresenter @Inject constructor( ...@@ -180,6 +183,8 @@ class ChatRoomPresenter @Inject constructor(
} }
} }
} }
}
} }
private fun unsubscribeRoomChanges() { private fun unsubscribeRoomChanges() {
......
...@@ -19,7 +19,6 @@ import android.view.Menu ...@@ -19,7 +19,6 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
...@@ -70,7 +69,6 @@ import chat.rocket.android.helper.MessageParser ...@@ -70,7 +69,6 @@ import chat.rocket.android.helper.MessageParser
import chat.rocket.android.util.extension.asObservable import chat.rocket.android.util.extension.asObservable
import chat.rocket.android.util.extension.createImageFile import chat.rocket.android.util.extension.createImageFile
import chat.rocket.android.util.extensions.circularRevealOrUnreveal 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.fadeIn
import chat.rocket.android.util.extensions.fadeOut import chat.rocket.android.util.extensions.fadeOut
import chat.rocket.android.util.extensions.getBitmpap import chat.rocket.android.util.extensions.getBitmpap
......
...@@ -168,7 +168,7 @@ class UiModelMapper @Inject constructor( ...@@ -168,7 +168,7 @@ class UiModelMapper @Inject constructor(
// TODO: move this to new interactor or FetchChatRoomsInteractor? // TODO: move this to new interactor or FetchChatRoomsInteractor?
private suspend fun getChatRoomAsync(roomId: String): ChatRoom? = withContext(CommonPool) { 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) { with(it.chatRoom) {
ChatRoom( ChatRoom(
id = id, id = id,
......
...@@ -2,6 +2,7 @@ package chat.rocket.android.userdetails.presentation ...@@ -2,6 +2,7 @@ package chat.rocket.android.userdetails.presentation
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.db.DatabaseManager 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.domain.GetConnectingServerInteractor
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import chat.rocket.android.util.extension.launchUI import chat.rocket.android.util.extension.launchUI
...@@ -97,8 +98,7 @@ class UserDetailsPresenter @Inject constructor( ...@@ -97,8 +98,7 @@ class UserDetailsPresenter @Inject constructor(
} }
if (userEntity != null) { if (userEntity != null) {
view.toDirectMessage( val chatRoom = ChatRoom(
chatRoom = ChatRoom(
id = result.id, id = result.id,
type = roomTypeOf(RoomType.DIRECT_MESSAGE), type = roomTypeOf(RoomType.DIRECT_MESSAGE),
name = userEntity.username ?: userEntity.name.orEmpty(), name = userEntity.username ?: userEntity.name.orEmpty(),
...@@ -127,13 +127,27 @@ class UserDetailsPresenter @Inject constructor( ...@@ -127,13 +127,27 @@ class UserDetailsPresenter @Inject constructor(
updatedAt = result.updatedAt, updatedAt = result.updatedAt,
user = null 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) { } catch (ex: Exception) {
Timber.e(ex) Timber.e(ex)
view.onOpenDirectMessageError() view.onOpenDirectMessageError()
} }
} }
private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) { private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) {
return@withContext dbManager.chatRoomDao().getAllSync().filter { return@withContext dbManager.chatRoomDao().getAllSync().filter {
if (name == null) { 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