android: apply delete action to full multi-selection
Some checks failed
CI / test (push) Failing after 2m10s
Some checks failed
CI / test (push) Failing after 2m10s
This commit is contained in:
@@ -182,3 +182,7 @@
|
|||||||
- Extended `ChatViewModel` forward flow: multi-select now forwards multiple source messages in one action.
|
- 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).
|
- 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.
|
- 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).
|
||||||
|
|||||||
@@ -184,6 +184,35 @@ class ChatViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onDeleteSelected(forAll: Boolean = false) {
|
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
|
val selected = getFocusedSelectedMessage() ?: return
|
||||||
if (forAll && !canDeleteForAll(selected)) {
|
if (forAll && !canDeleteForAll(selected)) {
|
||||||
_uiState.update { it.copy(errorMessage = "Delete for all is available only for your own messages.") }
|
_uiState.update { it.copy(errorMessage = "Delete for all is available only for your own messages.") }
|
||||||
|
|||||||
Reference in New Issue
Block a user