Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit 0b5dce3

Browse files
Merge branch 'develop' into fix/increase-db-retry
2 parents 0e4c9ce + a2535dd commit 0b5dce3

4 files changed

Lines changed: 108 additions & 91 deletions

File tree

app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class ChatRoomPresenter @Inject constructor(
132132
) {
133133
launch(CommonPool + strategy.jobs) {
134134
try {
135+
chatRoomId = roomId
136+
chatRoomType = roomType
135137
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
136138
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
137139
} else emptyList()
@@ -172,18 +174,21 @@ class ChatRoomPresenter @Inject constructor(
172174
}
173175

174176
private suspend fun subscribeRoomChanges() {
175-
chatRoomId?.let {
176-
manager.addRoomChannel(it, roomChangesChannel)
177-
for (room in roomChangesChannel) {
178-
dbManager.getRoom(room.id)?.let {
179-
view.onRoomUpdated(roomMapper.map(chatRoom = it, showLastMessage = true))
177+
withContext(CommonPool + strategy.jobs) {
178+
chatRoomId?.let {
179+
manager.addRoomChannel(it, roomChangesChannel)
180+
for (room in roomChangesChannel) {
181+
dbManager.getRoom(room.id)?.let {
182+
view.onRoomUpdated(roomMapper.map(chatRoom = it, showLastMessage = true))
183+
}
180184
}
181185
}
186+
182187
}
183188
}
184189

185190
private fun unsubscribeRoomChanges() {
186-
chatRoomId?.let { manager.removeRoomChannel(it) }
191+
chatRoomId?.let { manager.removeRoomChannel(it) }
187192
}
188193

189194
private fun isOwnerOrMod(): Boolean {
@@ -939,32 +944,32 @@ class ChatRoomPresenter @Inject constructor(
939944
dbManager.chatRoomDao().getSync(roomId)?.let {
940945
with(it.chatRoom) {
941946
ChatRoom(
942-
id = id,
943-
subscriptionId = subscriptionId,
944-
type = roomTypeOf(type),
945-
unread = unread,
946-
broadcast = broadcast ?: false,
947-
alert = alert,
948-
fullName = fullname,
949-
name = name,
950-
favorite = favorite ?: false,
951-
default = isDefault ?: false,
952-
readonly = readonly,
953-
open = open,
954-
lastMessage = null,
955-
archived = false,
956-
status = null,
957-
user = null,
958-
userMentions = userMentions,
959-
client = client,
960-
announcement = null,
961-
description = null,
962-
groupMentions = groupMentions,
963-
roles = null,
964-
topic = null,
965-
lastSeen = this.lastSeen,
966-
timestamp = timestamp,
967-
updatedAt = updatedAt
947+
id = id,
948+
subscriptionId = subscriptionId,
949+
type = roomTypeOf(type),
950+
unread = unread,
951+
broadcast = broadcast ?: false,
952+
alert = alert,
953+
fullName = fullname,
954+
name = name,
955+
favorite = favorite ?: false,
956+
default = isDefault ?: false,
957+
readonly = readonly,
958+
open = open,
959+
lastMessage = null,
960+
archived = false,
961+
status = null,
962+
user = null,
963+
userMentions = userMentions,
964+
client = client,
965+
announcement = null,
966+
description = null,
967+
groupMentions = groupMentions,
968+
roles = null,
969+
topic = null,
970+
lastSeen = this.lastSeen,
971+
timestamp = timestamp,
972+
updatedAt = updatedAt
968973
)
969974
}
970975
}
@@ -982,32 +987,32 @@ class ChatRoomPresenter @Inject constructor(
982987
}.map {
983988
with(it.chatRoom) {
984989
ChatRoom(
985-
id = id,
986-
subscriptionId = subscriptionId,
987-
type = roomTypeOf(type),
988-
unread = unread,
989-
broadcast = broadcast ?: false,
990-
alert = alert,
991-
fullName = fullname,
992-
name = name ?: "",
993-
favorite = favorite ?: false,
994-
default = isDefault ?: false,
995-
readonly = readonly,
996-
open = open,
997-
lastMessage = null,
998-
archived = false,
999-
status = null,
1000-
user = null,
1001-
userMentions = userMentions,
1002-
client = client,
1003-
announcement = null,
1004-
description = null,
1005-
groupMentions = groupMentions,
1006-
roles = null,
1007-
topic = null,
1008-
lastSeen = this.lastSeen,
1009-
timestamp = timestamp,
1010-
updatedAt = updatedAt
990+
id = id,
991+
subscriptionId = subscriptionId,
992+
type = roomTypeOf(type),
993+
unread = unread,
994+
broadcast = broadcast ?: false,
995+
alert = alert,
996+
fullName = fullname,
997+
name = name ?: "",
998+
favorite = favorite ?: false,
999+
default = isDefault ?: false,
1000+
readonly = readonly,
1001+
open = open,
1002+
lastMessage = null,
1003+
archived = false,
1004+
status = null,
1005+
user = null,
1006+
userMentions = userMentions,
1007+
client = client,
1008+
announcement = null,
1009+
description = null,
1010+
groupMentions = groupMentions,
1011+
roles = null,
1012+
topic = null,
1013+
lastSeen = this.lastSeen,
1014+
timestamp = timestamp,
1015+
updatedAt = updatedAt
10111016
)
10121017
}
10131018
}

app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import android.view.Menu
1919
import android.view.MenuItem
2020
import android.view.View
2121
import android.view.ViewGroup
22-
import android.widget.Button
2322
import android.widget.EditText
2423
import android.widget.FrameLayout
2524
import android.widget.ImageView
@@ -70,7 +69,6 @@ import chat.rocket.android.helper.MessageParser
7069
import chat.rocket.android.util.extension.asObservable
7170
import chat.rocket.android.util.extension.createImageFile
7271
import chat.rocket.android.util.extensions.circularRevealOrUnreveal
73-
import chat.rocket.android.util.extensions.content
7472
import chat.rocket.android.util.extensions.fadeIn
7573
import chat.rocket.android.util.extensions.fadeOut
7674
import chat.rocket.android.util.extensions.getBitmpap

app/src/main/java/chat/rocket/android/chatroom/uimodel/UiModelMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class UiModelMapper @Inject constructor(
168168

169169
// TODO: move this to new interactor or FetchChatRoomsInteractor?
170170
private suspend fun getChatRoomAsync(roomId: String): ChatRoom? = withContext(CommonPool) {
171-
return@withContext dbManager.chatRoomDao().getSync(roomId)?.let {
171+
return@withContext dbManager.getRoom(id = roomId)?.let {
172172
with(it.chatRoom) {
173173
ChatRoom(
174174
id = id,

app/src/main/java/chat/rocket/android/userdetails/presentation/UserDetailsPresenter.kt

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package chat.rocket.android.userdetails.presentation
22

33
import chat.rocket.android.core.lifecycle.CancelStrategy
44
import chat.rocket.android.db.DatabaseManager
5+
import chat.rocket.android.db.model.ChatRoomEntity
56
import chat.rocket.android.server.domain.GetConnectingServerInteractor
67
import chat.rocket.android.server.infraestructure.ConnectionManagerFactory
78
import chat.rocket.android.util.extension.launchUI
@@ -97,43 +98,56 @@ class UserDetailsPresenter @Inject constructor(
9798
}
9899

99100
if (userEntity != null) {
100-
view.toDirectMessage(
101-
chatRoom = ChatRoom(
102-
id = result.id,
103-
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
104-
name = userEntity.username ?: userEntity.name.orEmpty(),
105-
fullName = userEntity.name,
106-
favorite = false,
107-
open = false,
108-
alert = false,
109-
status = userStatusOf(userEntity.status),
110-
client = client,
111-
broadcast = false,
112-
archived = false,
113-
default = false,
114-
description = null,
115-
groupMentions = null,
116-
userMentions = null,
117-
lastMessage = null,
118-
lastSeen = null,
119-
topic = null,
120-
announcement = null,
121-
roles = null,
122-
unread = 0,
123-
readonly = false,
124-
muted = null,
125-
subscriptionId = "",
126-
timestamp = null,
127-
updatedAt = result.updatedAt,
128-
user = null
129-
)
101+
val chatRoom = ChatRoom(
102+
id = result.id,
103+
type = roomTypeOf(RoomType.DIRECT_MESSAGE),
104+
name = userEntity.username ?: userEntity.name.orEmpty(),
105+
fullName = userEntity.name,
106+
favorite = false,
107+
open = false,
108+
alert = false,
109+
status = userStatusOf(userEntity.status),
110+
client = client,
111+
broadcast = false,
112+
archived = false,
113+
default = false,
114+
description = null,
115+
groupMentions = null,
116+
userMentions = null,
117+
lastMessage = null,
118+
lastSeen = null,
119+
topic = null,
120+
announcement = null,
121+
roles = null,
122+
unread = 0,
123+
readonly = false,
124+
muted = null,
125+
subscriptionId = "",
126+
timestamp = null,
127+
updatedAt = result.updatedAt,
128+
user = null
130129
)
130+
131+
withContext(CommonPool + strategy.jobs) {
132+
dbManager.chatRoomDao().insertOrReplace(chatRoom = ChatRoomEntity(
133+
id = chatRoom.id,
134+
name = chatRoom.name,
135+
description = chatRoom.description,
136+
type = chatRoom.type.toString(),
137+
fullname = chatRoom.fullName,
138+
subscriptionId = chatRoom.subscriptionId,
139+
updatedAt = chatRoom.updatedAt
140+
))
141+
}
142+
143+
view.toDirectMessage(chatRoom = chatRoom)
131144
}
132145
} catch (ex: Exception) {
133146
Timber.e(ex)
134147
view.onOpenDirectMessageError()
135148
}
136149
}
150+
137151
private suspend fun chatRoomByName(name: String? = null): List<ChatRoom> = withContext(CommonPool) {
138152
return@withContext dbManager.chatRoomDao().getAllSync().filter {
139153
if (name == null) {

0 commit comments

Comments
 (0)