From 071165c55b7ca4744cbb89e31f76070a41d5c172 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 9 Mar 2026 13:50:39 +0300 Subject: [PATCH] android: apply delete action to full multi-selection --- android/CHANGELOG.md | 4 +++ .../messenger/ui/chat/ChatViewModel.kt | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/android/CHANGELOG.md b/android/CHANGELOG.md index 85b6c1f..11cd653 100644 --- a/android/CHANGELOG.md +++ b/android/CHANGELOG.md @@ -182,3 +182,7 @@ - Extended `ChatViewModel` forward flow: multi-select now forwards multiple source messages in one action. - Wired `ForwardMessageBulkUseCase` for multi-message forwarding (sequential safe execution with error short-circuit). - Updated chat action bar and forward sheet labels for multi-selection count. + +### Step 29 - Core base / multi-select delete execution +- Fixed multi-select delete behavior in `ChatViewModel`: `Delete` now applies to all selected messages, not only focused one. +- Added explicit guard for `Delete for all` in multi-select mode (single-message only). diff --git a/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt b/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt index 13060cb..ff3e9ed 100644 --- a/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt +++ b/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt @@ -184,6 +184,35 @@ class ChatViewModel @Inject constructor( } fun onDeleteSelected(forAll: Boolean = false) { + val actionState = uiState.value.actionState + if (actionState.mode == MessageSelectionMode.MULTI) { + if (forAll) { + _uiState.update { it.copy(errorMessage = "Delete for all is available only for single message selection.") } + return + } + val selectedIds = actionState.selectedMessageIds.toList().sorted() + if (selectedIds.isEmpty()) return + viewModelScope.launch { + for (messageId in selectedIds) { + when (val result = deleteMessageUseCase(messageId, forAll = false)) { + is AppResult.Success -> Unit + is AppResult.Error -> { + _uiState.update { it.copy(errorMessage = result.reason.toUiMessage()) } + return@launch + } + } + } + _uiState.update { + it.copy( + selectedMessage = null, + selectedCanEdit = false, + selectedCanDeleteForAll = false, + actionState = it.actionState.clearSelection(), + ) + } + } + return + } val selected = getFocusedSelectedMessage() ?: return if (forAll && !canDeleteForAll(selected)) { _uiState.update { it.copy(errorMessage = "Delete for all is available only for your own messages.") }