Commit 6df94252 authored by Kiryl Vashyla's avatar Kiryl Vashyla

finally updated ChatRoomAdapter#prependData code: order of merging chat history updated.

parent 88caa298
......@@ -158,15 +158,7 @@ class ChatRoomAdapter(
}
fun prependData(dataSet: List<BaseUiModel<*>>) {
val minAdditionDate = dataSet.minBy { it.message.timestamp } ?: return
//---1. In the most cases we will just add new elements to the top of messages heap
if (minAdditionDate.message.timestamp > this.dataSet[0].message.timestamp) {
this.dataSet.addAll(0, dataSet)
notifyItemRangeInserted(0, dataSet.size)
return
}
//---2. Else branch: merging messages---
//---2.1 At first we will update all already saved elements with received updated ones
//---At first we will update all already saved elements with received updated ones
val filteredDataSet = dataSet.filter { newItem ->
val matchedIndex = this.dataSet.indexOfFirst { it.messageId == newItem.messageId && it.viewType == newItem.viewType }
if (matchedIndex > -1) {
......@@ -175,7 +167,16 @@ class ChatRoomAdapter(
}
return@filter (matchedIndex < 0)
}
//---2.2 At the second stage we are inserting new received elements into set.
val minAdditionDate = dataSet.minBy { it.message.timestamp } ?: return
//---In the most cases we will just add new elements to the top of messages heap
if (minAdditionDate.message.timestamp > this.dataSet[0].message.timestamp) {
this.dataSet.addAll(0, dataSet)
notifyItemRangeInserted(0, dataSet.size)
return
}
//---Else branch: merging messages---
//---We are inserting new received elements into set. Sort them by time+type and show
if (filteredDataSet.isEmpty()) return
this.dataSet.addAll(0, filteredDataSet)
val tmp = this.dataSet.sortedWith(Comparator { t, t2 ->
......
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