From 55d5d58f8fa84a8fed193f5d1651ca5ff05d660f Mon Sep 17 00:00:00 2001 From: Anindra Date: Fri, 4 Dec 2026 01:11:41 +0530 Subject: [PATCH] feat: remove reply nudges (#604 follow-up) The feature was not requested by any user (#484 was maintainer-filed), its Google Messages counterpart had already been removed, and it produced reminders for months-old threads in #604. Delete ReplyNudge, ReplyNudgePolicy and ReplyNudgeScheduler, the settings row, its interval dialog and search entry, the strings in all 14 locales, the send-path cancel and the row query. The notification channel goes with it. An install that had the switch on keeps the old worker, card and channel otherwise, and the worker class no longer exists to run: MessagesApplication cancels messages-reply-nudge and messages-reply-nudge-check, drops any nudge-tagged card and deletes the messages_nudge channel. Tests: ReplyNudgeRemovalTest (sources, settings, upgrade cleanup); scripts/test-reply-nudge-removed.sh seeds the old preference and a two-day-old read thread and asserts no card, no active channel and a running app (7/7 on emulator-5558). --- .../anindra/messages/MessagesApplication.kt | 19 +- .../anindra/messages/data/ReplyNudgePolicy.kt | 78 ------- .../messages/data/ReplyNudgeScheduler.kt | 87 ------- .../com/anindra/messages/data/Repository.kt | 41 ---- .../anindra/messages/data/SettingsStore.kt | 24 -- .../com/anindra/messages/sms/ReplyNudge.kt | 140 ----------- .../anindra/messages/ui/AdvancedSubScreens.kt | 67 ------ .../com/anindra/messages/ui/SettingsSearch.kt | 1 - app/src/main/res/values-ar/strings_main.xml | 5 - .../main/res/values-ar/strings_settings.xml | 6 - app/src/main/res/values-de/strings_main.xml | 5 - .../main/res/values-de/strings_settings.xml | 6 - app/src/main/res/values-es/strings_main.xml | 5 - .../main/res/values-es/strings_settings.xml | 6 - app/src/main/res/values-fa/strings_main.xml | 5 - .../main/res/values-fa/strings_settings.xml | 6 - app/src/main/res/values-fr/strings_main.xml | 5 - .../main/res/values-fr/strings_settings.xml | 6 - app/src/main/res/values-hi/strings_main.xml | 5 - .../main/res/values-hi/strings_settings.xml | 6 - app/src/main/res/values-ja/strings_main.xml | 5 - .../main/res/values-ja/strings_settings.xml | 6 - app/src/main/res/values-ko/strings_main.xml | 5 - .../main/res/values-ko/strings_settings.xml | 6 - app/src/main/res/values-pl/strings_main.xml | 5 - .../main/res/values-pl/strings_settings.xml | 6 - .../main/res/values-pt-rBR/strings_main.xml | 5 - .../res/values-pt-rBR/strings_settings.xml | 6 - app/src/main/res/values-ru/strings_main.xml | 5 - .../main/res/values-ru/strings_settings.xml | 6 - .../main/res/values-zh-rCN/strings_main.xml | 5 - .../res/values-zh-rCN/strings_settings.xml | 6 - .../main/res/values-zh-rTW/strings_main.xml | 5 - .../res/values-zh-rTW/strings_settings.xml | 6 - app/src/main/res/values/strings_main.xml | 5 - app/src/main/res/values/strings_settings.xml | 6 - .../messages/data/ReplyNudgePolicyTest.kt | 219 ------------------ .../messages/data/ReplyNudgeRemovalTest.kt | 72 ++++++ scripts | 2 +- 39 files changed, 84 insertions(+), 820 deletions(-) delete mode 100644 app/src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt delete mode 100644 app/src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt delete mode 100644 app/src/main/java/com/anindra/messages/sms/ReplyNudge.kt delete mode 100644 app/src/test/java/com/anindra/messages/data/ReplyNudgePolicyTest.kt create mode 100644 app/src/test/java/com/anindra/messages/data/ReplyNudgeRemovalTest.kt diff --git a/app/src/main/java/com/anindra/messages/MessagesApplication.kt b/app/src/main/java/com/anindra/messages/MessagesApplication.kt index f80675a53..306c677af 100644 --- a/app/src/main/java/com/anindra/messages/MessagesApplication.kt +++ b/app/src/main/java/com/anindra/messages/MessagesApplication.kt @@ -139,14 +139,17 @@ class MessagesApplication : Application(), SingletonImageLoader.Factory { // import the names may have changed — and drops those of chats that // are gone. com.anindra.messages.sms.NotificationHelper.syncNotificationChannels(this@MessagesApplication) - // The nudge's schedule has to follow its switch, and an app start is - // also the moment a nudge that became due while the app was closed - // gets posted (#484). - com.anindra.messages.data.ReplyNudgeScheduler.apply( - this@MessagesApplication, s.replyNudgeEnabled - ) - if (s.replyNudgeEnabled) { - com.anindra.messages.data.ReplyNudgeScheduler.checkNow(this@MessagesApplication) + // Reply nudges were removed. An install that had them keeps the + // queued work, its card and its channel otherwise, and the worker + // class no longer exists to run it. + androidx.work.WorkManager.getInstance(this@MessagesApplication).apply { + cancelUniqueWork("messages-reply-nudge") + cancelUniqueWork("messages-reply-nudge-check") + } + getSystemService(android.app.NotificationManager::class.java)?.let { nm -> + nm.activeNotifications.filter { it.tag == "nudge" } + .forEach { nm.cancel(it.tag, it.id) } + nm.deleteNotificationChannel("messages_nudge") } // A queued message's countdown card outlives neither a restart of // the app nor a killed shade entry, so the pending rows are diff --git a/app/src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt b/app/src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt deleted file mode 100644 index 5c5884f62..000000000 --- a/app/src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.anindra.messages.data - -/** - * One conversation as the nudge rule sees it (#484): whatever the row says, the - * decision is made in [ReplyNudgePolicy] so a nudge can be reasoned about — and - * tested — without a database, a channel or a clock. - */ -data class ReplyNudgeRow( - val conversationId: Long, - val address: String, - val snippet: String, - /** Timestamp of the newest message in the thread. */ - val newest: Long, - val lastIsMine: Boolean, - val unread: Int, - val archived: Boolean, - val blocked: Boolean, - val deleted: Boolean -) - -/** - * When a thread is worth reminding about. - * - * The gap this fills is the opposite of unread: the message was read, the reply - * was meant, and then it was forgotten. An unread thread already has its own - * notification, so nudging it too would only double the noise — and a nudge is - * only a reminder, so everything that asked not to be disturbed (archive, - * block, trash, a muted channel, the master switch) wins over it. - */ -object ReplyNudgePolicy { - - /** Hours after the unanswered message, offered in Settings. */ - val INTERVAL_CHOICES = listOf(24, 48, 72) - - const val DEFAULT_INTERVAL_HOURS = 24 - - /** A nudge per conversation per day at most, even if the thread stays open. */ - const val REPEAT_HOURS = 24L - - /** - * Past this age the thread is history, not a reply still owed (#604). - * - * The rule above only says how long to wait before reminding, so without a - * ceiling every read-but-unanswered conversation ever — including one from - * three months ago — came due on the first run with the switch on. - */ - const val MAX_AGE_HOURS = 24 * 7 - - val MAX_AGE_MILLIS: Long = MAX_AGE_HOURS * HOUR_MILLIS - - fun intervalMillis(hours: Int): Long = - hours.coerceIn(1, 24 * 7).toLong() * HOUR_MILLIS - - fun shouldNudge( - row: ReplyNudgeRow, - muted: Boolean, - lastNudgedAt: Long, - now: Long, - intervalMillis: Long, - maxAgeMillis: Long = MAX_AGE_MILLIS - ): Boolean { - // A thread whose newest message is ours is answered by definition. - if (row.lastIsMine) return false - // Unread gets the ordinary message notification instead. - if (row.unread > 0) return false - if (row.archived || row.blocked || row.deleted || muted) return false - if (row.newest <= 0L) return false - // Not old enough yet: the reply may still be on its way. - if (now - row.newest < intervalMillis) return false - // Too old to be a reminder: the moment has passed, and a card for it is - // noise rather than a nudge. - if (now - row.newest > maxAgeMillis) return false - if (lastNudgedAt > 0 && now - lastNudgedAt < REPEAT_HOURS * HOUR_MILLIS) return false - return true - } - - private const val HOUR_MILLIS = 3_600_000L -} diff --git a/app/src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt b/app/src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt deleted file mode 100644 index 3e745eb81..000000000 --- a/app/src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.anindra.messages.data - -import android.content.Context -import androidx.work.Constraints -import androidx.work.CoroutineWorker -import androidx.work.ExistingPeriodicWorkPolicy -import androidx.work.ExistingWorkPolicy -import androidx.work.NetworkType -import androidx.work.OneTimeWorkRequestBuilder -import androidx.work.PeriodicWorkRequestBuilder -import androidx.work.WorkManager -import androidx.work.WorkerParameters -import com.anindra.messages.MessagesApplication -import com.anindra.messages.sms.ReplyNudge -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import java.util.concurrent.TimeUnit - -/** - * Arms and disarms the unanswered-reply nudge (#484). - * - * `apply` runs on every app start and whenever the setting changes, so the - * Worker's schedule can never outlive the preference that describes it. The - * periodic job is WorkManager's minimum period: it only asks a cheap question - * ("is anything due?") and does nothing at all unless a thread has been - * unanswered for a day or more. - */ -object ReplyNudgeScheduler { - - const val WORK_NAME = "messages-reply-nudge" - const val CHECK_WORK_NAME = "messages-reply-nudge-check" - - /** WorkManager's floor for periodic work; the policy decides what is due. */ - const val PERIOD_MINUTES = 15L - - fun apply(context: Context, enabled: Boolean) { - val workManager = WorkManager.getInstance(context) - if (!enabled) { - workManager.cancelUniqueWork(WORK_NAME) - workManager.cancelUniqueWork(CHECK_WORK_NAME) - // A reminder that is already in the shade has to go with the - // switch; no worker is left to reconcile it. - ReplyNudge.cancelAll(context) - return - } - val request = PeriodicWorkRequestBuilder( - PERIOD_MINUTES, TimeUnit.MINUTES - ).setConstraints( - Constraints.Builder().setRequiredNetworkType(NetworkType.NOT_REQUIRED).build() - ).build() - workManager.enqueueUniquePeriodicWork( - WORK_NAME, ExistingPeriodicWorkPolicy.UPDATE, request - ) - } - - /** - * One check outside the period: switching the feature on, and every app - * start, reconcile immediately instead of waiting for the next tick. KEEP, - * so a burst of starts cannot stack checks. - */ - fun checkNow(context: Context) { - val request = OneTimeWorkRequestBuilder() - .setConstraints( - Constraints.Builder().setRequiredNetworkType(NetworkType.NOT_REQUIRED).build() - ).build() - WorkManager.getInstance(context).enqueueUniqueWork( - CHECK_WORK_NAME, ExistingWorkPolicy.KEEP, request - ) - } -} - -/** - * Asks [ReplyNudge] to reconcile the shade. Safe to run at any time: the policy - * is the only thing that decides, and it does not care how it was woken. - */ -class ReplyNudgeWorker( - context: Context, - params: WorkerParameters -) : CoroutineWorker(context, params) { - - override suspend fun doWork(): Result { - val app = applicationContext as? MessagesApplication ?: return Result.success() - if (!app.repository.settings.replyNudgeEnabled) return Result.success() - withContext(Dispatchers.IO) { ReplyNudge.reconcile(applicationContext) } - return Result.success() - } -} diff --git a/app/src/main/java/com/anindra/messages/data/Repository.kt b/app/src/main/java/com/anindra/messages/data/Repository.kt index 22bdde5ba..feb6f6136 100644 --- a/app/src/main/java/com/anindra/messages/data/Repository.kt +++ b/app/src/main/java/com/anindra/messages/data/Repository.kt @@ -1894,9 +1894,6 @@ class Repository(private val context: Context) { "UPDATE conversations SET snippet=?,timestamp=?,unread_count=0,last_is_me=?,deleted_at=0 WHERE id=?", arrayOf(snippet, ts, if (isMe) 1 else 0, conversationId) ) - // A message of ours is the answer a nudge was waiting for (#484), and - // every send path ends here, so the card cannot outlive the reply. - if (isMe) com.anindra.messages.sms.ReplyNudge.cancel(context, conversationId) notifyChanged() } @@ -2909,44 +2906,6 @@ class Repository(private val context: Context) { return out } - /** - * Threads a nudge could apply to (#484): read, unanswered, and not archived, - * blocked or trashed. The age test and the once-a-day cap are - * [ReplyNudgePolicy]'s, so the rule is one function and not a SQL string. - * Read outside a flow — the nudge runs in a background worker. - */ - fun replyNudgeRowsBlocking(): List { - val out = mutableListOf() - // The policy owns the age ceiling; this only keeps a long history from - // being loaded to reach it. - val oldest = System.currentTimeMillis() - ReplyNudgePolicy.MAX_AGE_MILLIS - db.readableDatabase.rawQuery( - """SELECT id,address,snippet,timestamp,last_is_me,unread_count,archived,blocked,deleted_at - FROM conversations - WHERE deleted_at=0 AND archived=0 AND blocked=0 - AND unread_count=0 AND last_is_me=0 AND timestamp>=? - ORDER BY timestamp DESC""", - arrayOf(oldest.toString()) - ).use { c -> - while (c.moveToNext()) { - out.add( - ReplyNudgeRow( - conversationId = c.getLong(0), - address = c.getString(1), - snippet = c.getString(2) ?: "", - newest = c.getLong(3), - lastIsMine = c.getInt(4) == 1, - unread = c.getInt(5), - archived = c.getInt(6) == 1, - blocked = c.getInt(7) == 1, - deleted = c.getLong(8) != 0L - ) - ) - } - } - return out - } - fun addScheduledMessage(address: String, body: String, timestamp: Long, conversationId: Long, subId: Int): Long { require(address.isNotBlank()) { "Address must not be blank" } require(body.isNotBlank()) { "Message body must not be blank" } diff --git a/app/src/main/java/com/anindra/messages/data/SettingsStore.kt b/app/src/main/java/com/anindra/messages/data/SettingsStore.kt index 0a86e2c74..eac0b623b 100644 --- a/app/src/main/java/com/anindra/messages/data/SettingsStore.kt +++ b/app/src/main/java/com/anindra/messages/data/SettingsStore.kt @@ -87,9 +87,6 @@ class SettingsStore(context: Context) { const val KEY_NOTIF_ACTION_REPLY = "notif_action_reply" const val KEY_NOTIF_ACTION_MARK_READ = "notif_action_mark_read" const val KEY_NOTIF_ACTION_DELETE = "notif_action_delete" - const val KEY_REPLY_NUDGE = "reply_nudge_enabled" - const val KEY_REPLY_NUDGE_HOURS = "reply_nudge_hours" - const val KEY_REPLY_NUDGE_AT_PREFIX = "reply_nudge_at_" const val KEY_BUBBLE_BACK_CLOSES = "bubble_back_closes" const val KEY_SUGGESTED_REPLIES = "suggested_replies_enabled" const val KEY_SHOW_SIM_INDICATOR = "show_sim_indicator" @@ -414,27 +411,6 @@ class SettingsStore(context: Context) { get() = prefs.getBoolean(KEY_NOTIF_ACTION_DELETE, true) set(v) { prefs.edit().putBoolean(KEY_NOTIF_ACTION_DELETE, v).apply(); _revision.value++ } - /** - * Whether an unanswered thread is nudged after a while (#484). Off by - * default: a reminder the user did not ask for is just another notification. - */ - var replyNudgeEnabled: Boolean - get() = prefs.getBoolean(KEY_REPLY_NUDGE, false) - set(v) { prefs.edit().putBoolean(KEY_REPLY_NUDGE, v).apply(); _revision.value++ } - - /** How long the message sits unanswered before the nudge. */ - var replyNudgeHours: Int - get() = prefs.getInt(KEY_REPLY_NUDGE_HOURS, ReplyNudgePolicy.DEFAULT_INTERVAL_HOURS) - set(v) { prefs.edit().putInt(KEY_REPLY_NUDGE_HOURS, v).apply(); _revision.value++ } - - /** When this conversation was last nudged, so one thread is not re-nudged all day. */ - fun replyNudgedAt(conversationId: Long): Long = - prefs.getLong(KEY_REPLY_NUDGE_AT_PREFIX + conversationId, 0L) - - fun markReplyNudged(conversationId: Long, at: Long) { - prefs.edit().putLong(KEY_REPLY_NUDGE_AT_PREFIX + conversationId, at).apply() - } - /** * Whether Back closes a conversation bubble (#354 follow-up). Off by * default: Back inside a bubble returns to the conversation list and leaves diff --git a/app/src/main/java/com/anindra/messages/sms/ReplyNudge.kt b/app/src/main/java/com/anindra/messages/sms/ReplyNudge.kt deleted file mode 100644 index c0d24cbb2..000000000 --- a/app/src/main/java/com/anindra/messages/sms/ReplyNudge.kt +++ /dev/null @@ -1,140 +0,0 @@ -package com.anindra.messages.sms - -import android.app.NotificationChannel -import android.app.NotificationManager -import android.app.PendingIntent -import android.content.Context -import android.content.Intent -import androidx.core.app.NotificationCompat -import com.anindra.messages.MainActivity -import com.anindra.messages.MessagesApplication -import com.anindra.messages.R -import com.anindra.messages.data.ReplyNudgePolicy -import com.anindra.messages.data.ReplyNudgeRow - -/** - * The reminder for a message that was read and then forgotten (#484). - * - * An unread thread already has its own notification; this is for the thread the - * user opened, meant to answer, and left. One card per conversation, tagged - * `nudge`, on its own quiet channel — it is a reminder, so it never rings, - * buzzes, badges, or wakes the screen. Tapping it opens the chat, and the card - * is dropped the moment a message of ours lands in that thread. - */ -object ReplyNudge { - - /** Tag namespace, so a conversation id can never collide with a message id. */ - const val TAG = "nudge" - - const val CHANNEL_ID = "messages_nudge" - - fun idOf(conversationId: Long): Int = (conversationId and 0x7FFFFFFFL).toInt() - - fun cancel(context: Context, conversationId: Long) { - try { - androidx.core.app.NotificationManagerCompat.from(context) - .cancel(TAG, idOf(conversationId)) - } catch (_: SecurityException) { - } - } - - fun cancelAll(context: Context) { - val nm = context.getSystemService(NotificationManager::class.java) ?: return - nm.activeNotifications.filter { it.tag == TAG } - .forEach { nm.cancel(it.tag, it.id) } - } - - /** - * Posts what is due and drops what no longer is. One pass is the whole - * state: a thread that got its reply, went unread, was archived, blocked, - * muted or trashed simply stops qualifying, so the card goes with it. - */ - fun reconcile(context: Context) { - val app = context.applicationContext as MessagesApplication - val settings = app.repository.settings - if (!settings.replyNudgeEnabled || !NotificationHelper.canPost(context)) { - cancelAll(context) - return - } - ensureChannel(context) - val now = System.currentTimeMillis() - val interval = ReplyNudgePolicy.intervalMillis(settings.replyNudgeHours) - val due = mutableListOf() - for (row in app.repository.replyNudgeRowsBlocking()) { - val muted = NotificationHelper.channelImportanceFor( - context, NotificationHelper.messageChannelFor(app, context, row.conversationId, row.address) - ) == NotificationManager.IMPORTANCE_NONE - if (ForegroundTracker.isConversationOpen(row.address)) continue - if (!ReplyNudgePolicy.shouldNudge( - row, muted, settings.replyNudgedAt(row.conversationId), now, interval - ) - ) continue - due.add(row) - } - val live = due.map { idOf(it.conversationId) }.toHashSet() - val nm = context.getSystemService(NotificationManager::class.java) - nm?.activeNotifications?.filter { it.tag == TAG && it.id !in live } - ?.forEach { nm.cancel(it.tag, it.id) } - due.forEach { post(context, it, now) } - } - - private fun ensureChannel(context: Context) { - val nm = context.getSystemService(NotificationManager::class.java) ?: return - if (nm.getNotificationChannel(CHANNEL_ID) != null) return - nm.createNotificationChannel( - NotificationChannel( - CHANNEL_ID, - context.getString(R.string.notif_nudge_channel_title), - NotificationManager.IMPORTANCE_LOW - ).apply { - description = context.getString(R.string.notif_nudge_channel_desc) - setSound(null, null) - enableVibration(false) - setShowBadge(false) - } - ) - } - - private fun post(context: Context, row: ReplyNudgeRow, now: Long) { - val app = context.applicationContext as MessagesApplication - val label = app.repository.contactNameFor(row.address) ?: row.address - val open = Intent(context, MainActivity::class.java).apply { - putExtra("open_conversation_address", row.address) - setPackage(context.packageName) - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - } - val tap = PendingIntent.getActivity( - context, idOf(row.conversationId), open, PendingIntent.FLAG_IMMUTABLE - ) - val builder = NotificationCompat.Builder(context, CHANNEL_ID) - .setSmallIcon(R.drawable.ic_stat_message) - .setContentTitle( - if (app.repository.settings.privacyModeEnabled) { - context.getString(R.string.notif_nudge_title) - } else { - String.format(context.getString(R.string.notif_nudge_title_to), label) - } - ) - .setContentText( - if (app.repository.settings.privacyModeEnabled) { - context.getString(R.string.notif_nudge_private) - } else { - row.snippet - } - ) - .setCategory(NotificationCompat.CATEGORY_REMINDER) - .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) - .setAutoCancel(true) - .setOnlyAlertOnce(true) - .setSilent(true) - .setShowWhen(false) - .setContentIntent(tap) - try { - androidx.core.app.NotificationManagerCompat.from(context) - .notify(TAG, idOf(row.conversationId), builder.build()) - app.repository.settings.markReplyNudged(row.conversationId, now) - } catch (_: SecurityException) { - } - } -} diff --git a/app/src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt b/app/src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt index d6a88e90d..faf65b126 100644 --- a/app/src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt +++ b/app/src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt @@ -42,8 +42,6 @@ import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R import com.anindra.messages.data.MmsVerdict -import com.anindra.messages.data.ReplyNudgePolicy -import com.anindra.messages.data.ReplyNudgeScheduler import com.anindra.messages.data.SettingsStore import com.anindra.messages.data.SimMmsCheck import com.anindra.messages.sms.NotificationHelper @@ -72,9 +70,6 @@ fun NotificationSettingsScreen(vm: AppViewModel, onBack: () -> Unit) { var actionMarkRead by remember(revision) { mutableStateOf(vm.settings.notifActionMarkRead) } var actionDelete by remember(revision) { mutableStateOf(vm.settings.notifActionDelete) } var bubbleBackCloses by remember(revision) { mutableStateOf(vm.settings.bubbleBackCloses) } - var replyNudge by remember(revision) { mutableStateOf(vm.settings.replyNudgeEnabled) } - var nudgeHours by remember(revision) { mutableStateOf(vm.settings.replyNudgeHours) } - var nudgeDialog by remember { mutableStateOf(false) } var suggestedReplies by remember(revision) { mutableStateOf(vm.settings.suggestedRepliesEnabled) } SettingsScaffold( @@ -126,26 +121,6 @@ fun NotificationSettingsScreen(vm: AppViewModel, onBack: () -> Unit) { checked = actionDelete, onChecked = { actionDelete = it; vm.settings.notifActionDelete = it } ) - SettingsRow( - position = RowPosition.MIDDLE, - title = stringResource(R.string.settings_reply_nudge_title), - subtitle = stringResource(R.string.settings_reply_nudge_subtitle), - checked = replyNudge, - onChecked = { - replyNudge = it - vm.settings.replyNudgeEnabled = it - ReplyNudgeScheduler.apply(context, it) - if (it) ReplyNudgeScheduler.checkNow(context) - } - ) - if (replyNudge) { - SettingsRow( - position = RowPosition.MIDDLE, - title = stringResource(R.string.settings_reply_nudge_after_title), - subtitle = nudgeIntervalLabel(nudgeHours), - onClick = { nudgeDialog = true } - ) - } SettingsRow( position = RowPosition.MIDDLE, title = stringResource(R.string.settings_suggested_replies_title), @@ -164,48 +139,6 @@ fun NotificationSettingsScreen(vm: AppViewModel, onBack: () -> Unit) { SettingsFooter(stringResource(R.string.settings_notif_footer)) } - - if (nudgeDialog) { - AlertDialog( - onDismissRequest = { nudgeDialog = false }, - title = { Text(stringResource(R.string.settings_reply_nudge_after_title)) }, - text = { - Column { - ReplyNudgePolicy.INTERVAL_CHOICES.forEach { hours -> - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp) - ) { - RadioButton( - selected = nudgeHours == hours, - onClick = { - nudgeHours = hours - vm.settings.replyNudgeHours = hours - ReplyNudgeScheduler.checkNow(context) - nudgeDialog = false - } - ) - Spacer(Modifier.padding(start = 8.dp)) - Text(nudgeIntervalLabel(hours)) - } - } - } - }, - confirmButton = { - TextButton(onClick = { nudgeDialog = false }) { - Text(stringResource(R.string.common_cancel)) - } - } - ) - } -} - -/** "1 day" / "2 days" / "3 days", for the nudge interval. */ -@Composable -private fun nudgeIntervalLabel(hours: Int): String = when (hours) { - 48 -> stringResource(R.string.settings_reply_nudge_two_days) - 72 -> stringResource(R.string.settings_reply_nudge_three_days) - else -> stringResource(R.string.settings_reply_nudge_one_day) } /** Auto-delete master switch, what it purges, and how long each bucket is kept. */ diff --git a/app/src/main/java/com/anindra/messages/ui/SettingsSearch.kt b/app/src/main/java/com/anindra/messages/ui/SettingsSearch.kt index 399540e18..d51a70ca1 100644 --- a/app/src/main/java/com/anindra/messages/ui/SettingsSearch.kt +++ b/app/src/main/java/com/anindra/messages/ui/SettingsSearch.kt @@ -212,7 +212,6 @@ object SettingsSearch { R.string.settings_notif_action_mark_read_title, R.string.settings_notif_action_delete_title, R.string.settings_bubble_back_closes_title, - R.string.settings_reply_nudge_title, R.string.settings_suggested_replies_title, R.string.settings_notif_manage_channels) screen(Route.AUTO_DELETE, R.string.settings_retention_title, diff --git a/app/src/main/res/values-ar/strings_main.xml b/app/src/main/res/values-ar/strings_main.xml index 72ecfa1f1..5a10015c9 100644 --- a/app/src/main/res/values-ar/strings_main.xml +++ b/app/src/main/res/values-ar/strings_main.xml @@ -82,11 +82,6 @@ لا أستطيع الحضور مرحبًا فهمت - في انتظار ردك - الرد على %1$s؟ - محادثة تنتظر ردك - تنبيهات الرد - تذكيرات برسالة تركتها بلا رد رسالة مجدولة إلى %1$s في انتظار الإرسال diff --git a/app/src/main/res/values-ar/strings_settings.xml b/app/src/main/res/values-ar/strings_settings.xml index 2e67083da..2cdc633c2 100644 --- a/app/src/main/res/values-ar/strings_settings.xml +++ b/app/src/main/res/values-ar/strings_settings.xml @@ -52,12 +52,6 @@ إظهار زر الحذف في الإشعار الردود المقترحة اقترح ردودًا بلمسة واحدة فوق مربع الرسالة وعلى الإشعار - تنبيه للرسائل التي لم تُجَب - ذكّرني بالرد على رسالة تركتها بلا رد - التنبيه بعد - يوم واحد - يومان - 3 أيام إغلاق الفقاعة بزر الرجوع عند الإيقاف: يُبقي زر الرجوع الفقاعة مفتوحة تقارير التسليم diff --git a/app/src/main/res/values-de/strings_main.xml b/app/src/main/res/values-de/strings_main.xml index b8a5a1bd9..960b9b612 100644 --- a/app/src/main/res/values-de/strings_main.xml +++ b/app/src/main/res/values-de/strings_main.xml @@ -78,11 +78,6 @@ Schaffe es nicht Hallo Verstanden - Warte auf deine Antwort - %1$s antworten? - Eine Konversation wartet auf Ihre Antwort - Antwortstupps - Erinnerungen an eine unbeantwortete Nachricht Geplante Nachricht An %1$s diff --git a/app/src/main/res/values-de/strings_settings.xml b/app/src/main/res/values-de/strings_settings.xml index 3f2bea80b..ab82914b5 100644 --- a/app/src/main/res/values-de/strings_settings.xml +++ b/app/src/main/res/values-de/strings_settings.xml @@ -52,12 +52,6 @@ Löschen-Schaltfläche in der Benachrichtigung anzeigen Vorgeschlagene Antworten Zeige Antworten mit einem Tippen oberhalb des Nachrichtenfensters und der Benachrichtigung - Anstupsen für unbeantwortete Nachrichten - Erinnere mich daran, auf eine Nachricht zu antworten, die ich nicht beantwortet habe - Anstupsen nach - 1 Tag - 2 Tage - 3 Tage Blase mit Zurück schließen Aus: Zurück lässt die Blase geöffnet Zustellungsberichte diff --git a/app/src/main/res/values-es/strings_main.xml b/app/src/main/res/values-es/strings_main.xml index d059769d4..8e0314f30 100644 --- a/app/src/main/res/values-es/strings_main.xml +++ b/app/src/main/res/values-es/strings_main.xml @@ -82,11 +82,6 @@ No puedo ir Hola Entendido - Esperando tu respuesta - ¿Responder a %1$s? - Una conversación espera tu respuesta - Recordatorios de respuesta - Recordatorios de un mensaje que dejaste sin respuesta Mensaje programado Para %1$s En espera de envío diff --git a/app/src/main/res/values-es/strings_settings.xml b/app/src/main/res/values-es/strings_settings.xml index 24441a915..b6a415828 100644 --- a/app/src/main/res/values-es/strings_settings.xml +++ b/app/src/main/res/values-es/strings_settings.xml @@ -52,12 +52,6 @@ Mostrar un botón de eliminar en la notificación Respuestas sugeridas Ofrecer respuestas de un toque sobre el cuadro de mensaje y en la notificación - Recordatorio de mensajes sin responder - Recuérdame responder a un mensaje que dejé sin respuesta - Recordar después de - 1 día - 2 días - 3 días Cerrar la burbuja con Atrás Desactivado: Atrás deja la burbuja abierta Informes de entrega diff --git a/app/src/main/res/values-fa/strings_main.xml b/app/src/main/res/values-fa/strings_main.xml index a2932e872..2f9076ae9 100644 --- a/app/src/main/res/values-fa/strings_main.xml +++ b/app/src/main/res/values-fa/strings_main.xml @@ -78,11 +78,6 @@ نمی‌توانم بیایم سلام متوجه شدم - منتظر پاسخ شماست - پاسخ به %1$s؟ - گفتگویی منتظر پاسخ شماست - یادآوری‌های پاسخ - یادآوری پیامی که بی‌پاسخ گذاشتید پیام زمان‌بندی‌شده به %1$s در انتظار ارسال diff --git a/app/src/main/res/values-fa/strings_settings.xml b/app/src/main/res/values-fa/strings_settings.xml index 60da37072..6382513eb 100644 --- a/app/src/main/res/values-fa/strings_settings.xml +++ b/app/src/main/res/values-fa/strings_settings.xml @@ -52,12 +52,6 @@ نمایش دکمه حذف روی اعلان پاسخ‌های پیشنهادی پاسخ‌های یک‌لمسی بالای کادر پیام و روی اعلان پیشنهاد شود - یادآوری پیام‌های بی‌پاسخ - یادآوری کن به پیامی که بی‌پاسخ گذاشتم پاسخ دهم - یادآوری پس از - ۱ روز - ۲ روز - ۳ روز بستن حباب با دکمه بازگشت خاموش: دکمه بازگشت حباب را باز نگه می‌دارد گزارش‌های تحویل diff --git a/app/src/main/res/values-fr/strings_main.xml b/app/src/main/res/values-fr/strings_main.xml index 874e44e26..851d6a771 100644 --- a/app/src/main/res/values-fr/strings_main.xml +++ b/app/src/main/res/values-fr/strings_main.xml @@ -78,11 +78,6 @@ Je ne pourrai pas venir Salut Compris - En attente de votre réponse - Répondre à %1$s ? - Une conversation attend votre réponse - Notifications de rappel - Rappels concernant un message auquel vous n\'avez pas encore répondu Messages planifiés À %1$s diff --git a/app/src/main/res/values-fr/strings_settings.xml b/app/src/main/res/values-fr/strings_settings.xml index 60443aaaf..208ba1074 100644 --- a/app/src/main/res/values-fr/strings_settings.xml +++ b/app/src/main/res/values-fr/strings_settings.xml @@ -52,12 +52,6 @@ Afficher un bouton \"Supprimer\" sur la notification Réponses suggérées Proposer des réponses en un clic au-dessus de la boîte de message et sur la notification - Rappel pour les messages sans réponse - Me rappeler de répondre à un message auquel je n\'ai pas encore répondu - Rappel après - 1 jour - 2 jours - 3 jours Fermer la bulle avec retour Désactivé : Retourne à la liste de discussion et laisse la bulle ouverte Rapports de livraison diff --git a/app/src/main/res/values-hi/strings_main.xml b/app/src/main/res/values-hi/strings_main.xml index 5ba6f71cb..53852dd51 100644 --- a/app/src/main/res/values-hi/strings_main.xml +++ b/app/src/main/res/values-hi/strings_main.xml @@ -82,11 +82,6 @@ मैं नहीं आ पाऊँगा नमस्ते समझ गया - आपके जवाब का इंतज़ार - %1$s को जवाब दें? - एक बातचीत आपके जवाब का इंतज़ार कर रही है - जवाब की याद - उस संदेश की याद जिसे आपने बिना जवाब छोड़ा शीड्यूल किया गया संदेश %1$s को भेजने के लिए प्रतीक्षारत diff --git a/app/src/main/res/values-hi/strings_settings.xml b/app/src/main/res/values-hi/strings_settings.xml index 9f63f8320..a4e11e033 100644 --- a/app/src/main/res/values-hi/strings_settings.xml +++ b/app/src/main/res/values-hi/strings_settings.xml @@ -52,12 +52,6 @@ सूचना पर हटाएँ बटन दिखाएँ सुझाए गए जवाब संदेश बॉक्स के ऊपर और सूचना पर एक टैप वाले जवाब सुझाएँ - बिना जवाब वाले संदेशों के लिए याद दिलाएँ - उस संदेश का जवाब देने की याद दिलाएँ जिसे मैंने बिना जवाब छोड़ा - इतने समय बाद याद दिलाएँ - 1 दिन - 2 दिन - 3 दिन बैक से बबल बंद करें बंद: बैक बबल को खुला रखता है डिलीवरी रिपोर्ट diff --git a/app/src/main/res/values-ja/strings_main.xml b/app/src/main/res/values-ja/strings_main.xml index caa285228..703bd685e 100644 --- a/app/src/main/res/values-ja/strings_main.xml +++ b/app/src/main/res/values-ja/strings_main.xml @@ -82,11 +82,6 @@ 行けません やあ わかりました - 返信を待っています - %1$s に返信しますか? - 返信を待っている会話があります - 返信リマインド - 返信していないメッセージのリマインド スケジュールされたメッセージ %1$s 宛 送信待ち diff --git a/app/src/main/res/values-ja/strings_settings.xml b/app/src/main/res/values-ja/strings_settings.xml index 2b8bfe9c9..ce44455f0 100644 --- a/app/src/main/res/values-ja/strings_settings.xml +++ b/app/src/main/res/values-ja/strings_settings.xml @@ -52,12 +52,6 @@ 通知に削除ボタンを表示 返信の候補 メッセージ欄の上と通知にワンタップの返信を表示します - 未返信メッセージのリマインド - 返信し忘れたメッセージを通知する - リマインドするタイミング - 1 日後 - 2 日後 - 3 日後 戻るでバブルを閉じる オフ: 戻るを押してもバブルは開いたままになります 配信レポート diff --git a/app/src/main/res/values-ko/strings_main.xml b/app/src/main/res/values-ko/strings_main.xml index a2fe31f62..d9a5882e7 100644 --- a/app/src/main/res/values-ko/strings_main.xml +++ b/app/src/main/res/values-ko/strings_main.xml @@ -82,11 +82,6 @@ 못 갈 것 같아요 안녕 알겠어 - 답장을 기다리는 중 - %1$s에게 답장할까요? - 답장을 기다리는 대화가 있습니다 - 답장 알림 - 답장하지 않은 메시지에 대한 알림 예약된 메시지 %1$s에게 전송 대기 중 diff --git a/app/src/main/res/values-ko/strings_settings.xml b/app/src/main/res/values-ko/strings_settings.xml index c0f5ec440..ac699cb01 100644 --- a/app/src/main/res/values-ko/strings_settings.xml +++ b/app/src/main/res/values-ko/strings_settings.xml @@ -52,12 +52,6 @@ 알림에 삭제 버튼 표시 추천 답장 메시지 입력창 위와 알림에 한 번의 탭으로 보낼 답장을 제안합니다 - 답장하지 않은 메시지 알림 - 답장하지 않은 메시지를 다시 알려줍니다 - 알림 시점 - 1일 - 2일 - 3일 뒤로 가기로 버블 닫기 꺼짐: 뒤로 가기를 눌러도 버블은 열린 상태로 유지됩니다 전달 보고서 diff --git a/app/src/main/res/values-pl/strings_main.xml b/app/src/main/res/values-pl/strings_main.xml index 0516dd1ff..56365b729 100644 --- a/app/src/main/res/values-pl/strings_main.xml +++ b/app/src/main/res/values-pl/strings_main.xml @@ -82,11 +82,6 @@ Nie dam rady Cześć Rozumiem - Czeka na Twoją odpowiedź - Odpowiedzieć %1$s? - Rozmowa czeka na Twoją odpowiedź - Przypomnienia o odpowiedzi - Przypomnienia o wiadomości bez odpowiedzi Zaplanowana wiadomość Do %1$s Oczekuje na wysłanie diff --git a/app/src/main/res/values-pl/strings_settings.xml b/app/src/main/res/values-pl/strings_settings.xml index c1864f6b6..d839da92a 100644 --- a/app/src/main/res/values-pl/strings_settings.xml +++ b/app/src/main/res/values-pl/strings_settings.xml @@ -52,12 +52,6 @@ Pokaż przycisk Usuń w powiadomieniu Sugerowane odpowiedzi Proponuj odpowiedzi jednym dotknięciem nad polem wiadomości i w powiadomieniu - Przypomnienie o nieodpowiedzianych wiadomościach - Przypominaj mi o odpowiedzi na wiadomość, którą zostawiłem bez odpowiedzi - Przypomnij po - 1 dzień - 2 dni - 3 dni Zamykaj dymek przyciskiem Wstecz Wyłączone: Wstecz pozostawia dymek otwarty Raporty dostarczenia 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 0028de43c..a0df20308 100644 --- a/app/src/main/res/values-pt-rBR/strings_main.xml +++ b/app/src/main/res/values-pt-rBR/strings_main.xml @@ -82,11 +82,6 @@ Não vou conseguir Oi Entendi - Aguardando sua resposta - Responder para %1$s? - Uma conversa aguarda sua resposta - Lembretes de resposta - Lembretes sobre uma mensagem sem resposta Mensagem agendada Para %1$s Aguardando envio diff --git a/app/src/main/res/values-pt-rBR/strings_settings.xml b/app/src/main/res/values-pt-rBR/strings_settings.xml index 84da28cc3..d1c839d1d 100644 --- a/app/src/main/res/values-pt-rBR/strings_settings.xml +++ b/app/src/main/res/values-pt-rBR/strings_settings.xml @@ -52,12 +52,6 @@ Mostrar um botão Excluir na notificação Respostas sugeridas Oferecer respostas com um toque acima da caixa de mensagem e na notificação - Lembrete de mensagens sem resposta - Lembrar de responder a uma mensagem que deixei sem resposta - Lembrar após - 1 dia - 2 dias - 3 dias Fechar a bolha com Voltar Desativado: Voltar mantém a bolha aberta Relatórios de entrega diff --git a/app/src/main/res/values-ru/strings_main.xml b/app/src/main/res/values-ru/strings_main.xml index 18ffe457a..571f417e4 100644 --- a/app/src/main/res/values-ru/strings_main.xml +++ b/app/src/main/res/values-ru/strings_main.xml @@ -82,11 +82,6 @@ Не смогу прийти Привет Понял - Ждёт вашего ответа - Ответить %1$s? - Разговор ждёт вашего ответа - Напоминания об ответе - Напоминания о сообщении без ответа Запланированное сообщение Кому: %1$s Ожидает отправки diff --git a/app/src/main/res/values-ru/strings_settings.xml b/app/src/main/res/values-ru/strings_settings.xml index d996c71c9..1f390f978 100644 --- a/app/src/main/res/values-ru/strings_settings.xml +++ b/app/src/main/res/values-ru/strings_settings.xml @@ -52,12 +52,6 @@ Показывать кнопку «Удалить» в уведомлении Предлагаемые ответы Предлагать ответы в одно касание над полем сообщения и в уведомлении - Напоминание о неотвеченных сообщениях - Напоминать мне ответить на сообщение, оставленное без ответа - Напомнить через - 1 день - 2 дня - 3 дня Закрывать пузырь кнопкой «Назад» Выкл.: «Назад» оставляет пузырь открытым Отчёты о доставке 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 e80db98be..f1d9c541e 100644 --- a/app/src/main/res/values-zh-rCN/strings_main.xml +++ b/app/src/main/res/values-zh-rCN/strings_main.xml @@ -79,11 +79,6 @@ 我去不了 你好 知道了 - 等待你的回复 - 回复 %1$s? - 有一个会话在等待你的回复 - 回复提醒 - 关于尚未回复消息的提醒 计划消息 发送给 %1$s 等待发送 diff --git a/app/src/main/res/values-zh-rCN/strings_settings.xml b/app/src/main/res/values-zh-rCN/strings_settings.xml index 95fa55666..0249656ee 100644 --- a/app/src/main/res/values-zh-rCN/strings_settings.xml +++ b/app/src/main/res/values-zh-rCN/strings_settings.xml @@ -52,12 +52,6 @@ 在通知上显示删除按钮 建议回复 在消息框上方和通知中提供一键回复 - 未回复消息提醒 - 提醒我回复尚未回复的消息 - 提醒时间 - 1 天 - 2 天 - 3 天 按返回键关闭气泡 关闭:返回键保持气泡打开 送达报告 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 afa008e2d..f3ce00c1d 100644 --- a/app/src/main/res/values-zh-rTW/strings_main.xml +++ b/app/src/main/res/values-zh-rTW/strings_main.xml @@ -79,11 +79,6 @@ 我去不了 你好 知道了 - 等待你的回覆 - 回覆 %1$s? - 有一個會話在等待你的回覆 - 回覆提醒 - 關於尚未回覆訊息的提醒 排定訊息 傳送給 %1$s 等待傳送 diff --git a/app/src/main/res/values-zh-rTW/strings_settings.xml b/app/src/main/res/values-zh-rTW/strings_settings.xml index cc7f45fac..12656f976 100644 --- a/app/src/main/res/values-zh-rTW/strings_settings.xml +++ b/app/src/main/res/values-zh-rTW/strings_settings.xml @@ -52,12 +52,6 @@ 在通知上顯示刪除按鈕 建議回覆 在訊息框上方和通知中提供一鍵回覆 - 未回覆訊息提醒 - 提醒我回覆尚未回覆的訊息 - 提醒時間 - 1 天 - 2 天 - 3 天 按返回鍵關閉氣泡 關閉:返回鍵維持氣泡開啟 送達報告 diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 8cf07e694..45c37c8df 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -82,11 +82,6 @@ Can\'t make it Hey Got it - Waiting for your reply - Reply to %1$s? - A conversation is waiting for your reply - Reply nudges - Reminders about a message you left unanswered Scheduled message diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index 6e9480c36..6af073430 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -52,12 +52,6 @@ Show a delete button on the notification Suggested replies Offer one-tap replies above the message box and on the notification - Nudge for unanswered messages - Remind me to reply to a message I left unanswered - Nudge after - 1 day - 2 days - 3 days Close bubble with Back Off: Back leaves the bubble open Delivery reports diff --git a/app/src/test/java/com/anindra/messages/data/ReplyNudgePolicyTest.kt b/app/src/test/java/com/anindra/messages/data/ReplyNudgePolicyTest.kt deleted file mode 100644 index d5e02f696..000000000 --- a/app/src/test/java/com/anindra/messages/data/ReplyNudgePolicyTest.kt +++ /dev/null @@ -1,219 +0,0 @@ -package com.anindra.messages.data - -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test -import java.io.File - -/** - * #484: a message that was read and then forgotten is the one that never comes - * back — unread counts only cover messages nobody opened. A nudge is a reminder, - * so it has to be narrow: only a thread whose newest message is inbound, already - * read and old enough, and never one that asked not to be disturbed. - */ -class ReplyNudgePolicyTest { - - private val main: File by lazy { - generateSequence(File("").absoluteFile) { it.parentFile } - .map { File(it, "app/src/main") } - .firstOrNull { File(it, "java").isDirectory } - ?: error("app/src/main not found") - } - - private fun src(path: String) = File(main, path).readText() - - private val hour = 3_600_000L - private val now = 1_000_000_000_000L - - private fun row( - newest: Long = now - 30 * hour, - lastIsMine: Boolean = false, - unread: Int = 0, - archived: Boolean = false, - blocked: Boolean = false, - deleted: Boolean = false - ) = ReplyNudgeRow( - conversationId = 7, - address = "+15551230000", - snippet = "Are we still on for dinner?", - newest = newest, - lastIsMine = lastIsMine, - unread = unread, - archived = archived, - blocked = blocked, - deleted = deleted - ) - - @Test - fun aReadUnansweredMessageBecomesDueAfterTheInterval() { - val day = ReplyNudgePolicy.intervalMillis(24) - assertFalse( - "a message from an hour ago is not forgotten yet", - ReplyNudgePolicy.shouldNudge(row(newest = now - hour), false, 0, now, day) - ) - assertTrue( - "a day-old read message is exactly the case this exists for", - ReplyNudgePolicy.shouldNudge(row(newest = now - 25 * hour), false, 0, now, day) - ) - } - - @Test - fun aThreadFromMonthsAgoIsHistoryNotAReminder() { - val day = ReplyNudgePolicy.intervalMillis(24) - assertTrue( - "a week is still a reply the user meant to send", - ReplyNudgePolicy.shouldNudge(row(newest = now - 6 * 24 * hour), false, 0, now, day) - ) - assertFalse( - "three months on, the message is history and a card for it is noise (#604)", - ReplyNudgePolicy.shouldNudge(row(newest = now - 90 * 24 * hour), false, 0, now, day) - ) - assertTrue( - "the ceiling is a week", - ReplyNudgePolicy.MAX_AGE_MILLIS == 7 * 24 * hour - ) - } - - @Test - fun theQueryUsesTheSameCeilingAsThePolicy() { - val repo = src("java/com/anindra/messages/data/Repository.kt") - assertTrue( - "the prefilter must take its age from the policy, or the two drift", - repo.contains("ReplyNudgePolicy.MAX_AGE_MILLIS") - ) - assertTrue( - "a conversation older than the ceiling cannot be a nudge candidate", - Regex("""timestamp>=\?""").containsMatchIn(repo) - ) - } - - @Test - fun anAnsweredThreadIsNeverNudged() { - assertFalse( - "the newest message being ours is the definition of answered", - ReplyNudgePolicy.shouldNudge(row(lastIsMine = true), false, 0, now, hour) - ) - } - - @Test - fun anUnreadThreadIsLeftToItsOwnNotification() { - assertFalse( - "unread already has a message notification; a second one would double up", - ReplyNudgePolicy.shouldNudge(row(unread = 2), false, 0, now, hour) - ) - } - - @Test - fun everyQuietStateWinsOverTheReminder() { - val day = ReplyNudgePolicy.intervalMillis(24) - assertFalse("archived", ReplyNudgePolicy.shouldNudge(row(archived = true), false, 0, now, day)) - assertFalse("blocked", ReplyNudgePolicy.shouldNudge(row(blocked = true), false, 0, now, day)) - assertFalse("trashed", ReplyNudgePolicy.shouldNudge(row(deleted = true), false, 0, now, day)) - assertFalse( - "a chat muted through its Android channel", - ReplyNudgePolicy.shouldNudge(row(), muted = true, lastNudgedAt = 0, now = now, intervalMillis = day) - ) - } - - @Test - fun oneNudgePerConversationPerDay() { - val day = ReplyNudgePolicy.intervalMillis(24) - assertFalse( - "nudged an hour ago", - ReplyNudgePolicy.shouldNudge(row(), false, lastNudgedAt = now - hour, now = now, intervalMillis = day) - ) - assertTrue( - "a thread still unanswered the next day earns one more", - ReplyNudgePolicy.shouldNudge( - row(), false, lastNudgedAt = now - 25 * hour, now = now, intervalMillis = day - ) - ) - } - - @Test - fun theIntervalIsBoundedAndReadsAsHours() { - assertTrue(ReplyNudgePolicy.intervalMillis(24) == 24 * hour) - assertTrue(ReplyNudgePolicy.intervalMillis(0) == hour) - assertTrue("a week is the cap", ReplyNudgePolicy.intervalMillis(1_000) == 7 * 24 * hour) - assertTrue(ReplyNudgePolicy.INTERVAL_CHOICES.contains(ReplyNudgePolicy.DEFAULT_INTERVAL_HOURS)) - } - - @Test - fun theSwitchOwnsTheScheduleAndTheAppStartReconciles() { - val app = src("java/com/anindra/messages/MessagesApplication.kt") - assertTrue( - "the worker's schedule must follow its switch, or it outlives the preference", - Regex("""ReplyNudgeScheduler\.apply\(\s*this@MessagesApplication,\s*s\.replyNudgeEnabled""") - .containsMatchIn(app) - ) - assertTrue( - "an app start is when a nudge that came due while the app was closed is posted", - app.contains("ReplyNudgeScheduler.checkNow(this@MessagesApplication)") - ) - val ui = src("java/com/anindra/messages/ui/AdvancedSubScreens.kt") - assertTrue( - "turning the switch off has to disarm the worker too", - Regex("""vm\.settings\.replyNudgeEnabled = it[\s\S]{0,200}?ReplyNudgeScheduler\.apply\(context, it\)""") - .containsMatchIn(ui) - ) - assertTrue( - "the interval only matters while the switch is on", - Regex("""if \(replyNudge\) \{[\s\S]{0,400}?settings_reply_nudge_after_title""") - .containsMatchIn(ui) - ) - } - - @Test - fun replyingDropsTheCardOnEverySendPath() { - val repo = src("java/com/anindra/messages/data/Repository.kt") - assertTrue( - "every send ends in touchConversation(isMe = true), so the cancel belongs there", - Regex("""touchConversation\(conversationId, clean, now, isMe = true\)""").containsMatchIn(repo) - ) - assertTrue( - "a reply is the answer the nudge was waiting for", - Regex("""if \(isMe\) com\.anindra\.messages\.sms\.ReplyNudge\.cancel\(context, conversationId\)""") - .containsMatchIn(repo) - ) - } - - @Test - fun theCardIsQuietAndOpensTheChat() { - val nudge = src("java/com/anindra/messages/sms/ReplyNudge.kt") - assertTrue("a reminder must not buzz", nudge.contains("NotificationManager.IMPORTANCE_LOW")) - assertTrue(nudge.contains("setSound(null, null)")) - assertTrue(nudge.contains("setShowBadge(false)")) - assertTrue("silent even where the channel is louder", nudge.contains(".setSilent(true)")) - assertTrue("tapping it opens the conversation", nudge.contains("\"open_conversation_address\"")) - assertTrue("a nudge must not inflate the launcher badge", !nudge.contains(".setNumber(")) - assertTrue( - "a private body must not reach the lock screen", - nudge.contains("privacyModeEnabled") && nudge.contains("notif_nudge_private") - ) - assertTrue( - "gone the moment the row stops qualifying", - Regex("""activeNotifications\?\.filter \{ it\.tag == TAG && it\.id !in live \}""") - .containsMatchIn(nudge) - ) - } - - @Test - fun theWorkerAsksThePolicyAndTheMasterSwitch() { - val scheduler = src("java/com/anindra/messages/data/ReplyNudgeScheduler.kt") - assertTrue( - "the period is WorkManager's floor: the policy decides what is due", - scheduler.contains("PERIOD_MINUTES = 15L") - ) - assertTrue( - "a disabled switch disarms both the period and the one-shot check", - Regex("""if \(!enabled\) \{[\s\S]{0,200}?cancelUniqueWork\(WORK_NAME\)""") - .containsMatchIn(scheduler) - ) - assertTrue(scheduler.contains("if (!app.repository.settings.replyNudgeEnabled) return Result.success()")) - assertTrue( - "everything that posts goes through the same master switch", - src("java/com/anindra/messages/sms/ReplyNudge.kt") - .contains("if (!settings.replyNudgeEnabled || !NotificationHelper.canPost(context))") - ) - } -} diff --git a/app/src/test/java/com/anindra/messages/data/ReplyNudgeRemovalTest.kt b/app/src/test/java/com/anindra/messages/data/ReplyNudgeRemovalTest.kt new file mode 100644 index 000000000..59492d701 --- /dev/null +++ b/app/src/test/java/com/anindra/messages/data/ReplyNudgeRemovalTest.kt @@ -0,0 +1,72 @@ +package com.anindra.messages.data + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * Reply nudges are removed. The feature had no user request behind it, its + * Google Messages counterpart was dropped, and it was the source of #604's + * months-old reminders. These assertions keep the code, the setting and the + * old background job from creeping back. + */ +class ReplyNudgeRemovalTest { + + private val app: File by lazy { + generateSequence(File("").absoluteFile) { it.parentFile } + .map { File(it, "app") } + .firstOrNull { File(it, "src").isDirectory } + ?: error("app/src not found") + } + + private fun src(path: String) = File(app, path).readText() + + @Test + fun theNudgeSourcesAreGone() { + for (path in listOf( + "src/main/java/com/anindra/messages/data/ReplyNudgePolicy.kt", + "src/main/java/com/anindra/messages/data/ReplyNudgeScheduler.kt", + "src/main/java/com/anindra/messages/sms/ReplyNudge.kt", + "src/test/java/com/anindra/messages/data/ReplyNudgePolicyTest.kt" + )) { + assertFalse("$path must not exist", File(app, path).exists()) + } + } + + @Test + fun noScreenOrSettingReadsTheFeature() { + for (path in listOf( + "src/main/java/com/anindra/messages/data/SettingsStore.kt", + "src/main/java/com/anindra/messages/data/Repository.kt", + "src/main/java/com/anindra/messages/ui/AdvancedSubScreens.kt", + "src/main/java/com/anindra/messages/ui/SettingsSearch.kt" + )) { + val source = src(path) + assertFalse("$path still mentions replyNudge", "replyNudge" in source) + assertFalse("$path still mentions reply_nudge", "reply_nudge" in source) + assertFalse("$path still mentions ReplyNudge", "ReplyNudge" in source) + } + } + + @Test + fun anUpgradeDropsTheOldJobCardAndChannel() { + val application = src("src/main/java/com/anindra/messages/MessagesApplication.kt") + assertTrue( + "the queued worker must be cancelled, its class no longer exists", + "cancelUniqueWork(\"messages-reply-nudge\")" in application + ) + assertTrue( + "the one-shot check is cancelled too", + "cancelUniqueWork(\"messages-reply-nudge-check\")" in application + ) + assertTrue( + "a card left in the shade has to go", + "filter { it.tag == \"nudge\" }" in application + ) + assertTrue( + "and the channel it used", + "deleteNotificationChannel(\"messages_nudge\")" in application + ) + } +} diff --git a/scripts b/scripts index 58fe845ae..2e8817987 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 58fe845aeb903eef6555f883cbc0a23436d87084 +Subproject commit 2e881798743d64c25f63c520aa6510aac828c465