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()
|
.fillMaxHeight()
|
||||||
.background(PrimaryBlue)
|
.background(PrimaryBlue)
|
||||||
.clickable {
|
.clickable {
|
||||||
onDelete()
|
// Закрываем свайп мгновенно перед удалением
|
||||||
offsetX = 0f
|
offsetX = 0f
|
||||||
|
onDelete()
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -176,6 +176,9 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
|
|||||||
if (currentAccount.isEmpty()) return
|
if (currentAccount.isEmpty()) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 🚀 Сразу обновляем UI - удаляем диалог из локального списка
|
||||||
|
_dialogs.value = _dialogs.value.filter { it.opponentKey != opponentKey }
|
||||||
|
|
||||||
// Вычисляем правильный dialog_key (отсортированная комбинация ключей)
|
// Вычисляем правильный dialog_key (отсортированная комбинация ключей)
|
||||||
val dialogKey = if (currentAccount < opponentKey) {
|
val dialogKey = if (currentAccount < opponentKey) {
|
||||||
"$currentAccount:$opponentKey"
|
"$currentAccount:$opponentKey"
|
||||||
@@ -205,6 +208,8 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
|
|||||||
android.util.Log.d("ChatsListViewModel", "Dialog deleted successfully: $opponentKey")
|
android.util.Log.d("ChatsListViewModel", "Dialog deleted successfully: $opponentKey")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.e("ChatsListViewModel", "Error deleting dialog", e)
|
android.util.Log.e("ChatsListViewModel", "Error deleting dialog", e)
|
||||||
|
// В случае ошибки - возвращаем диалог обратно (откатываем оптимистичное обновление)
|
||||||
|
// Flow обновится автоматически из БД
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user