feat: Improve dialog deletion process by updating UI immediately and handling errors gracefully
This commit is contained in:
@@ -1038,8 +1038,9 @@ fun SwipeableDialogItem(
|
||||
.fillMaxHeight()
|
||||
.background(PrimaryBlue)
|
||||
.clickable {
|
||||
onDelete()
|
||||
// Закрываем свайп мгновенно перед удалением
|
||||
offsetX = 0f
|
||||
onDelete()
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
|
||||
@@ -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 обновится автоматически из БД
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user