Commit c8ec586b authored by Kiryl Vashyla's avatar Kiryl Vashyla

loadMissingMessages() improved: unused messages polling from local repository removed

parent 7760bd1a
...@@ -503,14 +503,11 @@ class ChatRoomPresenter @Inject constructor( ...@@ -503,14 +503,11 @@ class ChatRoomPresenter @Inject constructor(
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!!)
messagesRepository.getByRoomId(chatRoomId!!)
.sortedByDescending { it.timestamp }.firstOrNull()?.let { lastMessage ->
val lastSyncDate = messagesRepository.getLastSyncDate() val lastSyncDate = messagesRepository.getLastSyncDate()
// lastSyncDate or 0. LastSyncDate could be in case when we sent some messages offline(and saved them locally), // lastSyncDate or 0. LastSyncDate could be in case when we sent some messages offline(and saved them locally),
// but never has obtained chatMessages(or history) from remote. In this case we should sync all chat history from beginning // but never has obtained chatMessages(or history) from remote. In this case we should sync all chat history from beginning
val instant = Instant.ofEpochMilli(lastSyncDate ?: 0).toString() val instant = Instant.ofEpochMilli(lastSyncDate ?: 0).toString()
//
try { try {
val messages = val messages =
retryIO(description = "history($chatRoomId, $roomType, $instant)") { retryIO(description = "history($chatRoomId, $roomType, $instant)") {
...@@ -550,7 +547,6 @@ class ChatRoomPresenter @Inject constructor( ...@@ -550,7 +547,6 @@ class ChatRoomPresenter @Inject constructor(
} }
} }
} }
}
/** /**
* Delete the message with the given id. * Delete the message with the given id.
......
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