Unverified Commit 0b5dce3a authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge branch 'develop' into fix/increase-db-retry

parents 0e4c9cee a2535dd8
...@@ -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,18 +174,21 @@ class ChatRoomPresenter @Inject constructor( ...@@ -172,18 +174,21 @@ class ChatRoomPresenter @Inject constructor(
} }
private suspend fun subscribeRoomChanges() { private suspend fun subscribeRoomChanges() {
chatRoomId?.let { withContext(CommonPool + strategy.jobs) {
manager.addRoomChannel(it, roomChangesChannel) chatRoomId?.let {
for (room in roomChangesChannel) { manager.addRoomChannel(it, roomChangesChannel)
dbManager.getRoom(room.id)?.let { for (room in roomChangesChannel) {
view.onRoomUpdated(roomMapper.map(chatRoom = it, showLastMessage = true)) dbManager.getRoom(room.id)?.let {
view.onRoomUpdated(roomMapper.map(chatRoom = it, showLastMessage = true))
}
} }
} }
} }
} }
private fun unsubscribeRoomChanges() { private fun unsubscribeRoomChanges() {
chatRoomId?.let { manager.removeRoomChannel(it) } chatRoomId?.let { manager.removeRoomChannel(it) }
} }
private fun isOwnerOrMod(): Boolean { private fun isOwnerOrMod(): Boolean {
...@@ -939,32 +944,32 @@ class ChatRoomPresenter @Inject constructor( ...@@ -939,32 +944,32 @@ class ChatRoomPresenter @Inject constructor(
dbManager.chatRoomDao().getSync(roomId)?.let { dbManager.chatRoomDao().getSync(roomId)?.let {
with(it.chatRoom) { with(it.chatRoom) {
ChatRoom( ChatRoom(
id = id, id = id,
subscriptionId = subscriptionId, subscriptionId = subscriptionId,
type = roomTypeOf(type), type = roomTypeOf(type),
unread = unread, unread = unread,
broadcast = broadcast ?: false, broadcast = broadcast ?: false,
alert = alert, alert = alert,
fullName = fullname, fullName = fullname,
name = name, name = name,
favorite = favorite ?: false, favorite = favorite ?: false,
default = isDefault ?: false, default = isDefault ?: false,
readonly = readonly, readonly = readonly,
open = open, open = open,
lastMessage = null, lastMessage = null,
archived = false, archived = false,
status = null, status = null,
user = null, user = null,
userMentions = userMentions, userMentions = userMentions,
client = client, client = client,
announcement = null, announcement = null,
description = null, description = null,
groupMentions = groupMentions, groupMentions = groupMentions,
roles = null, roles = null,
topic = null, topic = null,
lastSeen = this.lastSeen, lastSeen = this.lastSeen,
timestamp = timestamp, timestamp = timestamp,
updatedAt = updatedAt updatedAt = updatedAt
) )
} }
} }
...@@ -982,32 +987,32 @@ class ChatRoomPresenter @Inject constructor( ...@@ -982,32 +987,32 @@ class ChatRoomPresenter @Inject constructor(
}.map { }.map {
with(it.chatRoom) { with(it.chatRoom) {
ChatRoom( ChatRoom(
id = id, id = id,
subscriptionId = subscriptionId, subscriptionId = subscriptionId,
type = roomTypeOf(type), type = roomTypeOf(type),
unread = unread, unread = unread,
broadcast = broadcast ?: false, broadcast = broadcast ?: false,
alert = alert, alert = alert,
fullName = fullname, fullName = fullname,
name = name ?: "", name = name ?: "",
favorite = favorite ?: false, favorite = favorite ?: false,
default = isDefault ?: false, default = isDefault ?: false,
readonly = readonly, readonly = readonly,
open = open, open = open,
lastMessage = null, lastMessage = null,
archived = false, archived = false,
status = null, status = null,
user = null, user = null,
userMentions = userMentions, userMentions = userMentions,
client = client, client = client,
announcement = null, announcement = null,
description = null, description = null,
groupMentions = groupMentions, groupMentions = groupMentions,
roles = null, roles = null,
topic = null, topic = null,
lastSeen = this.lastSeen, lastSeen = this.lastSeen,
timestamp = timestamp, timestamp = timestamp,
updatedAt = updatedAt updatedAt = updatedAt
) )
} }
} }
......
...@@ -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,43 +98,56 @@ class UserDetailsPresenter @Inject constructor( ...@@ -97,43 +98,56 @@ 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(), fullName = userEntity.name,
fullName = userEntity.name, favorite = false,
favorite = false, open = false,
open = false, alert = false,
alert = false, status = userStatusOf(userEntity.status),
status = userStatusOf(userEntity.status), client = client,
client = client, broadcast = false,
broadcast = false, archived = false,
archived = false, default = false,
default = false, description = null,
description = null, groupMentions = null,
groupMentions = null, userMentions = null,
userMentions = null, lastMessage = null,
lastMessage = null, lastSeen = null,
lastSeen = null, topic = null,
topic = null, announcement = null,
announcement = null, roles = null,
roles = null, unread = 0,
unread = 0, readonly = false,
readonly = false, muted = null,
muted = null, subscriptionId = "",
subscriptionId = "", timestamp = null,
timestamp = null, 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