android: fix bug in chat list (#630)

This commit is contained in:
Evgeny Poberezkin
2022-05-10 15:00:59 +01:00
committed by GitHub
parent 058c0f5895
commit 3d8ccdaa9f

View File

@@ -128,8 +128,8 @@ class ChatModel(val controller: ChatController) {
val res: Boolean
if (i >= 0) {
chat = chats[i]
val pItem = chat.chatItems.last()
if (pItem.id == cItem.id) {
val pItem = chat.chatItems.lastOrNull()
if (pItem?.id == cItem.id) {
chats[i] = chat.copy(chatItems = arrayListOf(cItem))
}
res = false
@@ -158,8 +158,8 @@ class ChatModel(val controller: ChatController) {
val chat: Chat
if (i >= 0) {
chat = chats[i]
val pItem = chat.chatItems.last()
if (pItem.id == cItem.id) {
val pItem = chat.chatItems.lastOrNull()
if (pItem?.id == cItem.id) {
chats[i] = chat.copy(chatItems = arrayListOf(cItem))
}
}
@@ -180,17 +180,17 @@ class ChatModel(val controller: ChatController) {
while (i < chatItems.count()) {
val item = chatItems[i]
if (item.meta.itemStatus is CIStatus.RcvNew) {
chatItems[i] = item.copy(meta=item.meta.copy(itemStatus = CIStatus.RcvRead()))
chatItems[i] = item.withStatus(CIStatus.RcvRead())
}
i += 1
}
val chat = chats[chatIdx]
val pItem = chat.chatItems.lastOrNull()
chats[chatIdx] = chat.copy(
chatItems = chatItems,
chatItems = if (pItem == null) arrayListOf() else arrayListOf(pItem.withStatus(CIStatus.RcvRead())),
chatStats = chat.chatStats.copy(unreadCount = 0, minUnreadItemId = chat.chatItems.last().id + 1)
)
}
}
// func popChat(_ id: String) {
@@ -670,6 +670,8 @@ data class ChatItem (
else -> false
}
fun withStatus(status: CIStatus): ChatItem = this.copy(meta = meta.copy(itemStatus = status))
companion object {
fun getSampleData(
id: Long = 1,