android: apply delete action to full multi-selection
Some checks failed
CI / test (push) Failing after 2m10s

This commit is contained in:
Codex
2026-03-09 13:50:39 +03:00
parent 876d64d345
commit 071165c55b
2 changed files with 33 additions and 0 deletions

View File

@@ -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).

View File

@@ -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.") }