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

Fix message editing

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