From 3531e169cfc530f6c1d0156f5902c7fa59a66459 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 18 Nov 2026 20:59:50 +0100 Subject: [PATCH] Leave tasks alone on Done or Snooze from another store's reminder (#100) --- .../data/reminders/ReminderActionReceiver.kt | 21 ++++++++++++---- .../data/reminders/ReminderActionStoreTest.kt | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionStoreTest.kt diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionReceiver.kt b/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionReceiver.kt index ae2f1e4..298c1f0 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionReceiver.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionReceiver.kt @@ -22,6 +22,7 @@ import kotlin.time.Instant * elapses. All app-internal intents, so the receiver is not exported. * * - **Done** completes the task — only the reminded occurrence, for a series. + * Done and Snooze from a reminder of another store only take it down. * - **Snooze** hides the notification and arms [ReminderSnoozeScheduler]'s * alarm, which lives outside [ScheduledReminderStore] so no scheduler pass * can cancel it. @@ -52,14 +53,14 @@ class ReminderActionReceiver : BroadcastReceiver() { try { when (action) { ACTION_DONE -> runCatching { - forgetPersistent(taskId, occurrence, store) + if (!forgetPersistent(taskId, occurrence, store)) return@runCatching val anchor = occurrence.takeIf { it != ScheduledReminder.NO_OCCURRENCE } ?.let(Instant::fromEpochMilliseconds) repository.setCompleted(taskId, anchor, completed = true) } ACTION_SNOOZE -> runCatching { - forgetPersistent(taskId, occurrence, store) + if (!forgetPersistent(taskId, occurrence, store)) return@runCatching val minutes = settingsPrefs.settings.first().snoozeMinutes snoozeScheduler.schedule(taskId, occurrence, System.currentTimeMillis() + minutes * 60_000L) } @@ -90,11 +91,16 @@ class ReminderActionReceiver : BroadcastReceiver() { } } - /** Before the action's own work, so a restore running meanwhile finds nothing to bring back. */ - private suspend fun forgetPersistent(taskId: Long, occurrence: Long, store: String?) { + /** + * Before the action's own work, so a restore running meanwhile finds nothing + * to bring back. False when the reminder was posted from another store, + * whose task ids name other tasks here: the action then stops at this. + */ + private suspend fun forgetPersistent(taskId: Long, occurrence: Long, store: String?): Boolean { if (store != null) notifier.forget(taskId, store, occurrence) startupGate.awaitReady() if (store == null) notifier.forget(taskId, occurrence = occurrence) + return actsHere(store, notifier::isCurrentStore) } companion object { @@ -107,6 +113,13 @@ class ReminderActionReceiver : BroadcastReceiver() { private const val EXTRA_OCCURRENCE = "de.jeanlucmakiola.agendula.extra.OCCURRENCE_START" private const val EXTRA_STORE = "de.jeanlucmakiola.agendula.extra.STORE" + /** + * Whether a reminder posted from [postedIn] may act on its task id in the + * current store; one from before the store was recorded may. + */ + internal fun actsHere(postedIn: String?, isCurrentStore: (String) -> Boolean): Boolean = + postedIn == null || isCurrentStore(postedIn) + /** * The data URI is what keeps two reminders' PendingIntents apart — * `filterEquals` never compares extras. diff --git a/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionStoreTest.kt b/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionStoreTest.kt new file mode 100644 index 0000000..3079261 --- /dev/null +++ b/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ReminderActionStoreTest.kt @@ -0,0 +1,24 @@ +package de.jeanlucmakiola.agendula.data.reminders + +import com.google.common.truth.Truth.assertThat +import org.junit.jupiter.api.Test + +class ReminderActionStoreTest { + + private val current = { store: String -> store == "own" } + + @Test + fun `a reminder from the current store acts on its task`() { + assertThat(ReminderActionReceiver.actsHere("own", current)).isTrue() + } + + @Test + fun `a reminder from another store leaves the task with its id alone`() { + assertThat(ReminderActionReceiver.actsHere("provider", current)).isFalse() + } + + @Test + fun `a reminder posted before the store was recorded still acts`() { + assertThat(ReminderActionReceiver.actsHere(null, current)).isTrue() + } +}