feat: Improve dialog deletion process by updating UI immediately and handling errors gracefully

This commit is contained in:
k1ngsterr1
2026-01-16 04:33:43 +05:00
parent c605148fa4
commit 306e854646
2 changed files with 7 additions and 1 deletions

View File

@@ -1038,8 +1038,9 @@ fun SwipeableDialogItem(
.fillMaxHeight()
.background(PrimaryBlue)
.clickable {
onDelete()
// Закрываем свайп мгновенно перед удалением
offsetX = 0f
onDelete()
},
contentAlignment = Alignment.Center
) {

View File

@@ -176,6 +176,9 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
if (currentAccount.isEmpty()) return
try {
// 🚀 Сразу обновляем UI - удаляем диалог из локального списка
_dialogs.value = _dialogs.value.filter { it.opponentKey != opponentKey }
// Вычисляем правильный dialog_key (отсортированная комбинация ключей)
val dialogKey = if (currentAccount < opponentKey) {
"$currentAccount:$opponentKey"
@@ -205,6 +208,8 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
android.util.Log.d("ChatsListViewModel", "Dialog deleted successfully: $opponentKey")
} catch (e: Exception) {
android.util.Log.e("ChatsListViewModel", "Error deleting dialog", e)
// В случае ошибки - возвращаем диалог обратно (откатываем оптимистичное обновление)
// Flow обновится автоматически из БД
}
}