Правка чата

This commit is contained in:
Халимов Рустам
2026-04-14 11:31:20 +03:00
parent d8b0d86534
commit 3310a3c4a4
18 changed files with 665 additions and 104 deletions
@@ -58,13 +58,19 @@ class ChatListViewModel @Inject constructor(
_state.update { it.copy(isLoading = true) }
try {
val chats = repository.getChats()
_state.update { it.copy(chats = chats, isLoading = false) }
_state.update { it.copy(chats = sortChats(chats), isLoading = false) }
} catch (e: Exception) {
_state.update { it.copy(isLoading = false, error = e.message) }
}
}
}
private fun sortChats(chats: List<Chat>): List<Chat> {
return chats.sortedWith(compareByDescending<Chat> {
it.name.equals("Избранное", ignoreCase = true) || it.name.equals("Saved Messages", ignoreCase = true)
}.thenByDescending { it.lastMessage?.createdAt })
}
private fun observeSignalREvents() {
signalrClient.events
.onEach { event ->
@@ -94,9 +100,9 @@ class ChatListViewModel @Inject constructor(
unreadCount = chat.unreadCount + 1
)
} else chat
}.sortedByDescending { it.lastMessage?.createdAt }
}
currentState.copy(chats = updatedChats)
currentState.copy(chats = sortChats(updatedChats))
}
}
}