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 00000000..f0d2ae6d
--- /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 69077503..eca95b1c 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) {
@@ -470,16 +477,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))
}
}
@@ -1492,8 +1502,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 b93755c3..3f5e5b2c 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 5a10015c..35071dff 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 960b9b61..a0309c73 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 8e0314f3..984abd5f 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 2f9076ae..4fa0ce64 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 851d6a77..46478226 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 53852dd5..2b7be4b9 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 703bd685..6b3720e7 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 d9a5882e..627f2c0b 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 56365b72..1a4f75b2 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 a0df2030..cd4ee113 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 571f417e..0b129ab3 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 f1d9c541..38974e70 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 f3ce00c1..23e45b4a 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 45c37c8d..48393aac 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 00000000..2e8fdc28
--- /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 00000000..224056ea
--- /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 16311f8b..5eeb7940 160000
--- a/scripts
+++ b/scripts
@@ -1 +1 @@
-Subproject commit 16311f8bf780831d7895eca4ff0617a7754076d5
+Subproject commit 5eeb7940b7ddc65322192297a5e5c5922b80cb05