Commit 29a7f307 authored by Lucio Maciel's avatar Lucio Maciel

Fix crash when the message list is empty when recovering from a network loss

parent 61cb7b9e
...@@ -188,7 +188,8 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -188,7 +188,8 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launch(parent = strategy.jobs) { launch(parent = strategy.jobs) {
if (chatRoomId != null && chatRoomType != null) { if (chatRoomId != null && chatRoomType != null) {
val roomType = roomTypeOf(chatRoomType!!) val roomType = roomTypeOf(chatRoomType!!)
val lastMessage = messagesRepository.getByRoomId(chatRoomId!!).sortedByDescending { it.timestamp }.first() messagesRepository.getByRoomId(chatRoomId!!)
.sortedByDescending { it.timestamp }.firstOrNull()?.let { lastMessage ->
val instant = Instant.ofEpochMilli(lastMessage.timestamp) val instant = Instant.ofEpochMilli(lastMessage.timestamp)
val messages = client.history(chatRoomId!!, roomType, count = 50, val messages = client.history(chatRoomId!!, roomType, count = 50,
oldest = instant.toString()) oldest = instant.toString())
...@@ -210,6 +211,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView, ...@@ -210,6 +211,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
} }
} }
} }
}
fun unsubscribeMessages(chatRoomId: String) { fun unsubscribeMessages(chatRoomId: String) {
manager.removeStatusChannel(stateChannel) manager.removeStatusChannel(stateChannel)
......
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