Commit 71313bc3 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix message editing

parent 0855cd9c
......@@ -87,11 +87,13 @@ class ChatRoomAdapter(
}
fun prependData(dataSet: List<BaseViewModel<*>>) {
val lastMessage = this.dataSet.first()
val lastId = lastMessage.messageId
val lastType = lastMessage.viewType
this.dataSet.addAll(0, dataSet.filterNot { lastType == it.viewType && lastId == it.messageId })
notifyItemRangeInserted(0, dataSet.size)
val item = dataSet.firstOrNull { newItem ->
this.dataSet.indexOfFirst { it.messageId == newItem.messageId && it.viewType == newItem.viewType } > -1
}
if (item == null) {
this.dataSet.addAll(0, dataSet)
notifyItemRangeInserted(0, dataSet.size)
}
}
fun updateItem(message: BaseViewModel<*>) {
......
......@@ -213,9 +213,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
}
override fun dispatchUpdateMessage(index: Int, message: List<BaseViewModel<*>>) {
if (message.size == 1) {
adapter.updateItem(message.last())
} else {
adapter.updateItem(message.last())
if (message.size > 1) {
adapter.updateItem(message.last())
adapter.prependData(listOf(message.first()))
}
......
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