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

Commit fa1e416

Browse files
authored
Merge branch 'develop' into new_1055
2 parents 5ceabc6 + 391a936 commit fa1e416

41 files changed

Lines changed: 415 additions & 419 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
applicationId "chat.rocket.android"
1717
minSdkVersion versions.minSdk
1818
targetSdkVersion versions.targetSdk
19-
versionCode 2052
19+
versionCode 2054
2020
versionName "3.2.0"
2121
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2222
multiDexEnabled true

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

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,25 @@ class ChatRoomPresenter @Inject constructor(
123123
private var lastState = manager.state
124124
private var typingStatusList = arrayListOf<String>()
125125
private val roomChangesChannel = Channel<Room>(Channel.CONFLATED)
126+
private lateinit var draftKey: String
126127

127128
fun setupChatRoom(
128129
roomId: String,
129130
roomName: String,
130131
roomType: String,
131132
chatRoomMessage: String? = null
132133
) {
134+
draftKey = "${currentServer}_${LocalRepository.DRAFT_KEY}$roomId"
135+
chatRoomId = roomId
136+
chatRoomType = roomType
133137
launch(CommonPool + strategy.jobs) {
134138
try {
135139
chatRoles = if (roomTypeOf(roomType) !is RoomType.DirectMessage) {
136140
client.chatRoomRoles(roomType = roomTypeOf(roomType), roomName = roomName)
137-
} else emptyList()
138-
} catch (ex: RocketChatException) {
141+
} else {
142+
emptyList()
143+
}
144+
} catch (ex: Exception) {
139145
Timber.e(ex)
140146
chatRoles = emptyList()
141147
} finally {
@@ -172,18 +178,20 @@ class ChatRoomPresenter @Inject constructor(
172178
}
173179

174180
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))
181+
withContext(CommonPool + strategy.jobs) {
182+
chatRoomId?.let {
183+
manager.addRoomChannel(it, roomChangesChannel)
184+
for (room in roomChangesChannel) {
185+
dbManager.getRoom(room.id)?.let {
186+
view.onRoomUpdated(roomMapper.map(chatRoom = it, showLastMessage = true))
187+
}
180188
}
181189
}
182190
}
183191
}
184192

185193
private fun unsubscribeRoomChanges() {
186-
chatRoomId?.let { manager.removeRoomChannel(it) }
194+
chatRoomId?.let { manager.removeRoomChannel(it) }
187195
}
188196

189197
private fun isOwnerOrMod(): Boolean {
@@ -364,6 +372,7 @@ class ChatRoomPresenter @Inject constructor(
364372
client.updateMessage(chatRoomId, messageId, text)
365373
}
366374

375+
clearUnfinishedMessage()
367376
view.enableSendMessageButton()
368377
} catch (ex: Exception) {
369378
Timber.d(ex, "Error sending message...")
@@ -909,7 +918,7 @@ class ChatRoomPresenter @Inject constructor(
909918
navigator.toChatDetails(chatRoomId, chatRoomType, isSubscribed, isMenuDisabled)
910919
}
911920

912-
fun loadChatRooms() {
921+
fun loadChatRoomsSuggestions() {
913922
launchUI(strategy) {
914923
try {
915924
val chatRooms = getChatRoomsAsync()
@@ -939,32 +948,32 @@ class ChatRoomPresenter @Inject constructor(
939948
dbManager.chatRoomDao().getSync(roomId)?.let {
940949
with(it.chatRoom) {
941950
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
951+
id = id,
952+
subscriptionId = subscriptionId,
953+
type = roomTypeOf(type),
954+
unread = unread,
955+
broadcast = broadcast ?: false,
956+
alert = alert,
957+
fullName = fullname,
958+
name = name,
959+
favorite = favorite ?: false,
960+
default = isDefault ?: false,
961+
readonly = readonly,
962+
open = open,
963+
lastMessage = null,
964+
archived = false,
965+
status = null,
966+
user = null,
967+
userMentions = userMentions,
968+
client = client,
969+
announcement = null,
970+
description = null,
971+
groupMentions = groupMentions,
972+
roles = null,
973+
topic = null,
974+
lastSeen = this.lastSeen,
975+
timestamp = timestamp,
976+
updatedAt = updatedAt
968977
)
969978
}
970979
}
@@ -982,32 +991,32 @@ class ChatRoomPresenter @Inject constructor(
982991
}.map {
983992
with(it.chatRoom) {
984993
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
994+
id = id,
995+
subscriptionId = subscriptionId,
996+
type = roomTypeOf(type),
997+
unread = unread,
998+
broadcast = broadcast ?: false,
999+
alert = alert,
1000+
fullName = fullname,
1001+
name = name ?: "",
1002+
favorite = favorite ?: false,
1003+
default = isDefault ?: false,
1004+
readonly = readonly,
1005+
open = open,
1006+
lastMessage = null,
1007+
archived = false,
1008+
status = null,
1009+
user = null,
1010+
userMentions = userMentions,
1011+
client = client,
1012+
announcement = null,
1013+
description = null,
1014+
groupMentions = groupMentions,
1015+
roles = null,
1016+
topic = null,
1017+
lastSeen = this.lastSeen,
1018+
timestamp = timestamp,
1019+
updatedAt = updatedAt
10111020
)
10121021
}
10131022
}
@@ -1281,31 +1290,26 @@ class ChatRoomPresenter @Inject constructor(
12811290
}
12821291

12831292
/**
1284-
* Save unfinished message, when user left chat room without sending a message. It also clears
1285-
* saved message from local repository when unfinishedMessage is blank.
1293+
* Save unfinished message, when user left chat room without sending a message.
12861294
*
1287-
* @param chatRoomId Chat room Id.
12881295
* @param unfinishedMessage The unfinished message to save.
12891296
*/
1290-
fun saveUnfinishedMessage(chatRoomId: String, unfinishedMessage: String) {
1291-
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId"
1297+
fun saveUnfinishedMessage(unfinishedMessage: String) {
12921298
if (unfinishedMessage.isNotBlank()) {
1293-
localRepository.save(key, unfinishedMessage)
1294-
} else {
1295-
localRepository.clear(key)
1299+
localRepository.save(draftKey, unfinishedMessage)
12961300
}
12971301
}
12981302

1303+
fun clearUnfinishedMessage() {
1304+
localRepository.clear(draftKey)
1305+
}
12991306
/**
13001307
* Get unfinished message from local repository, when user left chat room without
13011308
* sending a message and now the user is back.
13021309
*
1303-
* @param chatRoomId Chat room Id.
1304-
*
1305-
* @return Returns the unfinished message.
1310+
* @return Returns the unfinished message, null otherwise.
13061311
*/
1307-
fun getUnfinishedMessage(chatRoomId: String): String {
1308-
val key = "${currentServer}_${LocalRepository.UNFINISHED_MSG_KEY}$chatRoomId"
1309-
return localRepository.get(key) ?: ""
1312+
fun getUnfinishedMessage(): String? {
1313+
return localRepository.get(draftKey)
13101314
}
13111315
}

0 commit comments

Comments
 (0)