From 97e92728d27660becc80ee3e64a353c3606eaf90 Mon Sep 17 00:00:00 2001 From: Anindra Date: Sun, 6 Dec 2026 09:38:02 +0530 Subject: [PATCH] fix(#610): a bulk delete says what it actually did Deleting a selection goes through the same call as deleting one chat, so it already followed the permanent-delete setting. The bar afterwards said "%d conversations moved to trash" and offered an Undo that called restoreFromTrash on rows that no longer existed, which made an erased batch look like a Trash move. BulkDelete.undoable() now holds that decision in one place. The redesigned list reports an erased batch as "%d conversations deleted" through showNotice (same single snackbar, no action button), and the legacy list mirrors it. convo_deleted_count is in all 14 values directories. Tests: BulkDeleteTest and BulkDeleteWiringTest; test-610-bulk-delete-permanent.sh was red 12/2 on the old build and is green 14/0 now. --- .../com/anindra/messages/ui/BulkDelete.kt | 15 ++++++ .../messages/ui/ConversationsScreen.kt | 30 ++++++++---- .../ui/legacy/LegacyConversationsScreen.kt | 18 +++++-- app/src/main/res/values-ar/strings_main.xml | 1 + app/src/main/res/values-de/strings_main.xml | 1 + app/src/main/res/values-es/strings_main.xml | 1 + app/src/main/res/values-fa/strings_main.xml | 1 + app/src/main/res/values-fr/strings_main.xml | 1 + app/src/main/res/values-hi/strings_main.xml | 1 + app/src/main/res/values-ja/strings_main.xml | 1 + app/src/main/res/values-ko/strings_main.xml | 1 + app/src/main/res/values-pl/strings_main.xml | 1 + .../main/res/values-pt-rBR/strings_main.xml | 1 + app/src/main/res/values-ru/strings_main.xml | 1 + .../main/res/values-zh-rCN/strings_main.xml | 1 + .../main/res/values-zh-rTW/strings_main.xml | 1 + app/src/main/res/values/strings_main.xml | 1 + .../com/anindra/messages/ui/BulkDeleteTest.kt | 23 +++++++++ .../messages/ui/BulkDeleteWiringTest.kt | 48 +++++++++++++++++++ scripts | 2 +- 20 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/anindra/messages/ui/BulkDelete.kt create mode 100644 app/src/test/java/com/anindra/messages/ui/BulkDeleteTest.kt create mode 100644 app/src/test/java/com/anindra/messages/ui/BulkDeleteWiringTest.kt diff --git a/app/src/main/java/com/anindra/messages/ui/BulkDelete.kt b/app/src/main/java/com/anindra/messages/ui/BulkDelete.kt new file mode 100644 index 000000000..f0d2ae6d4 --- /dev/null +++ b/app/src/main/java/com/anindra/messages/ui/BulkDelete.kt @@ -0,0 +1,15 @@ +package com.anindra.messages.ui + +/** + * What deleting a multi-conversation selection actually does (#610). + * + * The batch goes through the same view-model call as a single chat's delete, so + * it follows the permanent-delete setting. The selection bar must not promise a + * Trash move and an Undo it cannot deliver, which is what it did while this + * decision lived only in the snackbar code. + */ +object BulkDelete { + + /** True when the batch can still be restored from Trash afterwards. */ + fun undoable(permanentDeleteEnabled: Boolean): Boolean = !permanentDeleteEnabled +} diff --git a/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt b/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt index d2a1e9aee..61add5024 100644 --- a/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt @@ -337,14 +337,15 @@ fun ConversationsScreen( showing?.cancelAndJoin() val entry = undoStack.peek() ?: continue showing = launch { + val undo = entry.undo val result = snackbarHostState.showSnackbar( message = entry.message, - actionLabel = undoLabel, + actionLabel = if (undo == null) null else undoLabel, duration = SnackbarDuration.Long ) - if (result == SnackbarResult.ActionPerformed) { + if (undo != null && result == SnackbarResult.ActionPerformed) { undoStack.pop() - entry.undo() + undo() // Reveal the next entry so repeated Undo keeps walking back. undoRequests.trySend(Unit) } else { @@ -359,6 +360,12 @@ fun ConversationsScreen( undoRequests.trySend(Unit) } + /** Reports a result that has nothing to undo, so no action button is drawn. */ + fun showNotice(message: String) { + undoStack.push(UndoEntry(message, null)) + undoRequests.trySend(Unit) + } + fun moveToTrash(convo: Conversation) { if (vm.settings.permanentDeleteEnabled) { if (vm.settings.permanentDeleteWarn) { @@ -468,16 +475,19 @@ fun ConversationsScreen( selectedIds = ConversationSelection.toggle(selectedIds, convo.id) } - /** Bulk delete is always recoverable: it moves to Trash with one undo for - * the whole batch. Permanent deletion stays a per-conversation choice, - * because its confirmation dialog names the single thread it will erase. */ + /** The batch follows the permanent-delete setting like any other delete, so + * it may only offer an Undo when it really went to Trash (#610). */ fun trashSelection() { val ids = ConversationSelection.trashTargets(selectedIds, displayed.map { it.id }) if (ids.isEmpty()) return selectedIds = emptySet() ids.forEach { vm.deleteConversation(it) } - showUndo(context.getString(R.string.convo_moved_to_trash_count, ids.size)) { - ids.forEach { vm.restoreFromTrash(it) } + if (BulkDelete.undoable(vm.settings.permanentDeleteEnabled)) { + showUndo(context.getString(R.string.convo_moved_to_trash_count, ids.size)) { + ids.forEach { vm.restoreFromTrash(it) } + } + } else { + showNotice(context.getString(R.string.convo_deleted_count, ids.size)) } } @@ -1489,8 +1499,8 @@ internal fun StartChatFab( } -/** One recoverable inbox action; [message] is what the snackbar says it did. */ -private class UndoEntry(val message: String, val undo: () -> Unit) +/** One inbox result; [undo] is null when the action cannot be taken back. */ +private class UndoEntry(val message: String, val undo: (() -> Unit)?) /** Home-search scopes (#394). All/Unread filter conversations; Starred lists diff --git a/app/src/main/java/com/anindra/messages/ui/legacy/LegacyConversationsScreen.kt b/app/src/main/java/com/anindra/messages/ui/legacy/LegacyConversationsScreen.kt index b93755c31..3f5e5b2c2 100644 --- a/app/src/main/java/com/anindra/messages/ui/legacy/LegacyConversationsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/legacy/LegacyConversationsScreen.kt @@ -370,21 +370,29 @@ fun ConversationsScreen( selectedIds = com.anindra.messages.ui.ConversationSelection.toggle(selectedIds, convo.id) } - /** Bulk delete is always recoverable: it moves to Trash with one undo for the - * whole batch. Permanent deletion stays a per-conversation choice. */ + /** The batch follows the permanent-delete setting like any other delete, so + * it may only offer an Undo when it really went to Trash (#610). */ fun trashSelection() { val ids = com.anindra.messages.ui.ConversationSelection .trashTargets(selectedIds, displayed.map { it.id }) if (ids.isEmpty()) return selectedIds = emptySet() ids.forEach { vm.deleteConversation(it) } + val undoable = com.anindra.messages.ui.BulkDelete + .undoable(vm.settings.permanentDeleteEnabled) scope.launch { val result = snackbarHostState.showSnackbar( - message = context.getString(R.string.convo_moved_to_trash_count, ids.size), - actionLabel = context.getString(R.string.action_undo), + message = context.getString( + if (undoable) R.string.convo_moved_to_trash_count + else R.string.convo_deleted_count, + ids.size + ), + actionLabel = if (undoable) context.getString(R.string.action_undo) else null, duration = SnackbarDuration.Long ) - if (result == SnackbarResult.ActionPerformed) ids.forEach { vm.restoreFromTrash(it) } + if (undoable && result == SnackbarResult.ActionPerformed) { + ids.forEach { vm.restoreFromTrash(it) } + } } } diff --git a/app/src/main/res/values-ar/strings_main.xml b/app/src/main/res/values-ar/strings_main.xml index 5a10015c9..35071dffe 100644 --- a/app/src/main/res/values-ar/strings_main.xml +++ b/app/src/main/res/values-ar/strings_main.xml @@ -101,6 +101,7 @@ تم الحفظ في Downloads/Messages تقرير أعطال تطبيق Messages تم نقل %1$d محادثات إلى سلة المحذوفات + تم حذف %1$d محادثات تمت أرشفة %1$d محادثات تحديد المزيد diff --git a/app/src/main/res/values-de/strings_main.xml b/app/src/main/res/values-de/strings_main.xml index 960b9b612..a0309c73c 100644 --- a/app/src/main/res/values-de/strings_main.xml +++ b/app/src/main/res/values-de/strings_main.xml @@ -97,6 +97,7 @@ In Downloads/Messages gespeichert Absturzbericht von Messages %1$d Unterhaltungen in den Papierkorb verschoben + %1$d Unterhaltungen gelöscht %1$d Unterhaltungen archiviert Mehr auswählen diff --git a/app/src/main/res/values-es/strings_main.xml b/app/src/main/res/values-es/strings_main.xml index 8e0314f30..984abd5f8 100644 --- a/app/src/main/res/values-es/strings_main.xml +++ b/app/src/main/res/values-es/strings_main.xml @@ -101,6 +101,7 @@ Guardado en Downloads/Messages Informe de errores de Messages %1$d conversaciones movidas a la papelera + %1$d conversaciones eliminadas %1$d conversaciones archivadas Seleccionar más diff --git a/app/src/main/res/values-fa/strings_main.xml b/app/src/main/res/values-fa/strings_main.xml index 2f9076ae9..4fa0ce649 100644 --- a/app/src/main/res/values-fa/strings_main.xml +++ b/app/src/main/res/values-fa/strings_main.xml @@ -96,6 +96,7 @@ در Downloads/Messages ذخیره شد گزارش خرابی پیام‌ها %1$d گفتگو به سطل زباله منتقل شد + %1$d گفتگو حذف شد %1$d گفتگو بایگانی شد انتخاب بیشتر diff --git a/app/src/main/res/values-fr/strings_main.xml b/app/src/main/res/values-fr/strings_main.xml index 851d6a771..464782263 100644 --- a/app/src/main/res/values-fr/strings_main.xml +++ b/app/src/main/res/values-fr/strings_main.xml @@ -97,6 +97,7 @@ Enregistré dans Downloads/Messages Rapport d\'incident de Messages %1$d conversations déplacées dans la corbeille + %1$d conversations supprimées %1$d conversations archivées Sélectionner plus diff --git a/app/src/main/res/values-hi/strings_main.xml b/app/src/main/res/values-hi/strings_main.xml index 53852dd51..2b7be4b99 100644 --- a/app/src/main/res/values-hi/strings_main.xml +++ b/app/src/main/res/values-hi/strings_main.xml @@ -101,6 +101,7 @@ Downloads/Messages में सहेजा गया Messages क्रैश रिपोर्ट %1$d संवाद कूड़े में ले जाए गए + %1$d संवाद हटाए गए %1$d संवाद संग्रहीत किए गए और चुनें diff --git a/app/src/main/res/values-ja/strings_main.xml b/app/src/main/res/values-ja/strings_main.xml index 703bd685e..6b3720e7d 100644 --- a/app/src/main/res/values-ja/strings_main.xml +++ b/app/src/main/res/values-ja/strings_main.xml @@ -101,6 +101,7 @@ Downloads/Messages に保存しました Messages のクラッシュレポート %1$d 件の会話をゴミ箱に移動しました + %1$d 件の会話を削除しました %1$d 件の会話をアーカイブしました さらに選択 diff --git a/app/src/main/res/values-ko/strings_main.xml b/app/src/main/res/values-ko/strings_main.xml index d9a5882e7..627f2c0b2 100644 --- a/app/src/main/res/values-ko/strings_main.xml +++ b/app/src/main/res/values-ko/strings_main.xml @@ -101,6 +101,7 @@ Downloads/Messages에 저장했습니다 Messages 크래시 보고서 %1$d개의 대화가 휴지통으로 이동되었습니다 + %1$d개의 대화가 삭제되었습니다 %1$d개의 대화가 보관되었습니다 더 선택 diff --git a/app/src/main/res/values-pl/strings_main.xml b/app/src/main/res/values-pl/strings_main.xml index 56365b729..1a4f75b2a 100644 --- a/app/src/main/res/values-pl/strings_main.xml +++ b/app/src/main/res/values-pl/strings_main.xml @@ -101,6 +101,7 @@ Zapisano w Downloads/Messages Raport awarii Messages Przeniesiono %1$d rozmów do kosza + Usunięto %1$d rozmów Zarchiwizowano %1$d rozmów Wybierz więcej diff --git a/app/src/main/res/values-pt-rBR/strings_main.xml b/app/src/main/res/values-pt-rBR/strings_main.xml index a0df20308..cd4ee1133 100644 --- a/app/src/main/res/values-pt-rBR/strings_main.xml +++ b/app/src/main/res/values-pt-rBR/strings_main.xml @@ -101,6 +101,7 @@ Salvo em Downloads/Messages Relatório de falha do Messages %1$d conversas movidas para a lixeira + %1$d conversas excluídas %1$d conversas arquivadas Selecionar mais diff --git a/app/src/main/res/values-ru/strings_main.xml b/app/src/main/res/values-ru/strings_main.xml index 571f417e4..0b129ab30 100644 --- a/app/src/main/res/values-ru/strings_main.xml +++ b/app/src/main/res/values-ru/strings_main.xml @@ -101,6 +101,7 @@ Сохранено в Downloads/Messages Отчёт о сбое Messages %1$d переписок перемещено в корзину + %1$d переписок удалено %1$d переписок заархивировано Выбрать ещё diff --git a/app/src/main/res/values-zh-rCN/strings_main.xml b/app/src/main/res/values-zh-rCN/strings_main.xml index f1d9c541e..38974e700 100644 --- a/app/src/main/res/values-zh-rCN/strings_main.xml +++ b/app/src/main/res/values-zh-rCN/strings_main.xml @@ -97,6 +97,7 @@ 已保存到 Downloads/Messages Messages 崩溃报告 %1$d 个对话已移至回收站 + %1$d 个对话已删除 %1$d 个对话已封存 选择更多 diff --git a/app/src/main/res/values-zh-rTW/strings_main.xml b/app/src/main/res/values-zh-rTW/strings_main.xml index f3ce00c1d..23e45b4a4 100644 --- a/app/src/main/res/values-zh-rTW/strings_main.xml +++ b/app/src/main/res/values-zh-rTW/strings_main.xml @@ -97,6 +97,7 @@ 已儲存至 Downloads/Messages Messages 當機報告 %1$d 個對話已移至垃圾桶 + %1$d 個對話已刪除 %1$d 個對話已封存 選擇更多 diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 45c37c8df..48393aaca 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -103,6 +103,7 @@ Saved to Downloads/Messages Messages crash report %1$d conversations moved to trash + %1$d conversations deleted %1$d conversations archived Select more diff --git a/app/src/test/java/com/anindra/messages/ui/BulkDeleteTest.kt b/app/src/test/java/com/anindra/messages/ui/BulkDeleteTest.kt new file mode 100644 index 000000000..2e8fdc28f --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/BulkDeleteTest.kt @@ -0,0 +1,23 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * #610: the selection bar promised "moved to trash" and an Undo after a batch + * delete that the permanent-delete setting had erased. The batch follows the + * setting, so the bar's message and its Undo must follow it too. + */ +class BulkDeleteTest { + + @Test + fun aDefaultDeleteStillGoesToTrashAndCanBeUndone() { + assertTrue(BulkDelete.undoable(permanentDeleteEnabled = false)) + } + + @Test + fun permanentDeleteErasesTheBatchSoThereIsNothingToUndo() { + assertFalse(BulkDelete.undoable(permanentDeleteEnabled = true)) + } +} diff --git a/app/src/test/java/com/anindra/messages/ui/BulkDeleteWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/BulkDeleteWiringTest.kt new file mode 100644 index 000000000..224056eaa --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/BulkDeleteWiringTest.kt @@ -0,0 +1,48 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * #610 both conversation lists carried the same unconditional "moved to trash" + * snackbar, so the fix has to land in both. Reading the source keeps a rename + * from silently restoring the lie on one of them. + */ +class BulkDeleteWiringTest { + + private fun read(path: String): String { + val main = generateSequence(File("").absoluteFile) { it.parentFile } + .map { File(it, "app/src/main") } + .firstOrNull { File(it, "java").isDirectory } + ?: error("app/src/main not found") + return File(main, "java/com/anindra/messages/ui/$path").readText() + } + + private fun selectionBody(source: String): String = + Regex("fun trashSelection\\(\\) \\{([\\s\\S]*?)\\n \\}") + .find(source)?.groupValues?.get(1) + ?: error("trashSelection not found") + + @Test + fun theRedesignedListDecidesBeforePromisingAnUndo() { + val body = selectionBody(read("ConversationsScreen.kt")) + assertTrue("bulk delete must ask BulkDelete", body.contains("BulkDelete.undoable(")) + assertTrue( + "an erased batch must not be called a Trash move", + body.contains("R.string.convo_deleted_count") && + body.contains("R.string.convo_moved_to_trash_count") + ) + } + + @Test + fun theLegacyListDecidesBeforePromisingAnUndo() { + val body = selectionBody(read("legacy/LegacyConversationsScreen.kt")) + assertTrue("bulk delete must ask BulkDelete", body.contains("BulkDelete")) + assertTrue( + "an erased batch must not be called a Trash move", + body.contains("R.string.convo_deleted_count") && + body.contains("R.string.convo_moved_to_trash_count") + ) + } +} diff --git a/scripts b/scripts index 2e8817987..b07e74141 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 2e881798743d64c25f63c520aa6510aac828c465 +Subproject commit b07e741413c04d75ccd1859318944a38821c44da