fix: sync task reminders as VALARMs (#52) (#81)
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 7s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Skipped
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Skipped
Renovate / renovate (push) Successful in 1m1s
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 7s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Skipped
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Skipped
Renovate / renovate (push) Successful in 1m1s
Reminders set in Agendula never reached the server, so a Mac or any other client saw none, and alarms set there never rang here. Reminders now sync as VALARMs in both directions. **What syncs** - Alarms Agendula can fire exactly as written become reminders: DISPLAY/AUDIO, relative to start or due, or absolute on a non-recurring task. - Everything else stays in the residue and round-trips untouched: Apple default alarms, location alarms, repeating alarms, RFC 9074 snoozes, and triggers after their anchor. - An unchanged alarm is re-emitted verbatim. An edited one is authored fresh under its existing uid. All-day leads go out as whole days. - `ACKNOWLEDGED` is only added once a reminder is past the planner's missed-reminder grace period. **Behaviour changes** - Default reminders are stored on the task when it first gets a due date, so other clients see them. While untouched, they swap with the other default when the task flips between timed and all-day. - Removing a task's alarms in another app turns them off here instead of falling back to the default. Tasks from clients that never write alarms keep the default. - "All occurrences" reminder edits now reach occurrences that still had the series' old reminders. - `.ics` import keeps VALARMs as reminders. **Database v3** - Alarms gain a `uid` and `raw` VALARM. Tasks gain `reminders_off`. - The migration lifts claimable alarms out of the residue. It queues a one-time upload for tasks with local-only reminders on writable, non-confidential lists. **Testing** - Unit tests: full 662, offline 489. All instrumented tests pass on the emulator, including the migration. Lint is clean for both flavours. - Not covered: the repository has no unit-test harness, so storing defaults at creation and the timed/all-day swap have no automated tests. Nothing has been checked against a real Mac yet. Closes #52 Co-authored-by: Jean-Luc Makiola <business@jeanlucmakiola.de> Reviewed-on: https://codeberg.org/jlmakiola/agendula/pulls/81
This commit is contained in:
1 parent
2a1230c0ca
commit
1d6c2a0d59
36 files changed
+2465
-174
No files matched your search
+129
-1
@@ -411,6 +411,134 @@ class RoomTasksDataSourceTest {
|
||||
assertThat(db.alarms().forTask(override.id).single().minutesBefore).isEqualTo(30)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSaveKeepsTheIdentityOfAReminderItDidNotChange() {
|
||||
val id = source.insertTask(form(due = now + 1.days), listOf(TaskReminder(15)))
|
||||
val original = db.alarms().forTask(id).single()
|
||||
db.alarms().update(original.copy(raw = "BEGIN:VALARM\r\nX-VENDOR:keep\r\nEND:VALARM\r\n"))
|
||||
|
||||
source.updateTask(id, form(title = "renamed", due = now + 2.days), dueReminders = listOf(15, 60))
|
||||
|
||||
val rows = db.alarms().forTask(id)
|
||||
val kept = rows.single { it.minutesBefore == 15 }
|
||||
// Same row, same identity on the server, same original text.
|
||||
assertThat(kept.id).isEqualTo(original.id)
|
||||
assertThat(kept.uid).isEqualTo(original.uid)
|
||||
assertThat(kept.raw).contains("X-VENDOR:keep")
|
||||
assertThat(rows.single { it.minutesBefore == 60 }.uid).isNotEqualTo(original.uid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSaveKeepsABeforeStartReminderTheEditorNeverShows() {
|
||||
val id = source.insertTask(form(due = now + 1.days))
|
||||
source.setReminders(id, listOf(TaskReminder(10, fromStart = true), TaskReminder(30)))
|
||||
|
||||
source.updateTask(id, form(due = now + 1.days), dueReminders = listOf(45))
|
||||
|
||||
assertThat(source.reminders()[id]).containsExactly(TaskReminder(10, fromStart = true), TaskReminder(45))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aReminderForOneOccurrenceLeavesTheSeriesUntouched() {
|
||||
val work = syncedList()
|
||||
val id = source.insertTask(form(due = now + 1.days).copy(listId = work), listOf(TaskReminder(30)))
|
||||
makeRecurring(id, now)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(isDirty = false))
|
||||
val target = source.tasks(TaskQuery(listId = work))
|
||||
.filter { it.taskId == id }
|
||||
.first { it.distanceFromCurrent == 1 }
|
||||
|
||||
source.updateInstance(id, target.occurrenceStart!!, form(title = "moved").copy(listId = work), listOf(60))
|
||||
|
||||
// ⚠️ The master is never written, not even briefly: a sync landing in
|
||||
// between would upload the occurrence's reminder for the whole series.
|
||||
assertThat(db.alarms().forTask(id).map { it.minutesBefore }).containsExactly(30)
|
||||
assertThat(db.tasks().entity(id)!!.isDirty).isFalse()
|
||||
val override = db.tasks().override(id, target.occurrenceStart)!!
|
||||
assertThat(db.alarms().forTask(override.id).map { it.minutesBefore }).containsExactly(60)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun splittingASeriesGivesTheNewSeriesItsOwnReminderIdentities() {
|
||||
val id = source.insertTask(form(due = now + 1.days), listOf(TaskReminder(30)))
|
||||
makeRecurring(id, now - 14.days)
|
||||
val master = db.alarms().forTask(id).single()
|
||||
val target = source.tasks(TaskQuery(listId = listId))
|
||||
.filter { it.taskId == id }
|
||||
.first { it.distanceFromCurrent == 1 }
|
||||
|
||||
val created = source.splitSeries(id, target.occurrenceStart!!, form(title = "later"), listOf(30))
|
||||
|
||||
assertThat(created).isNotEqualTo(id)
|
||||
val copy = db.alarms().forTask(created).single()
|
||||
assertThat(copy.minutesBefore).isEqualTo(30)
|
||||
// A different UID on the server, so the alarm must not share one either.
|
||||
assertThat(copy.uid).isNotEqualTo(master.uid)
|
||||
assertThat(db.alarms().forTask(id).single().uid).isEqualTo(master.uid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changingOnlyTheRemindersOwesTheServerAPut() {
|
||||
val work = syncedList()
|
||||
val id = source.insertTask(form(due = now + 1.days).copy(listId = work))
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(isDirty = false))
|
||||
|
||||
source.setReminders(id, listOf(TaskReminder(15)))
|
||||
assertThat(db.tasks().entity(id)!!.isDirty).isTrue()
|
||||
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(isDirty = false))
|
||||
source.setReminders(id, listOf(TaskReminder(15)))
|
||||
// Nothing changed, so nothing is owed.
|
||||
assertThat(db.tasks().entity(id)!!.isDirty).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesReminderEditReachesTheOccurrencesThatStillHadTheOldOne() {
|
||||
val id = source.insertTask(form(due = now + 1.days), listOf(TaskReminder(15)))
|
||||
makeRecurring(id, now)
|
||||
val occurrences = source.tasks(TaskQuery(listId = listId)).filter { it.taskId == id }
|
||||
val completed = occurrences.first { it.distanceFromCurrent == 1 }.occurrenceStart!!
|
||||
val own = occurrences.first { it.distanceFromCurrent == 2 }.occurrenceStart!!
|
||||
source.setCompletedInstance(id, completed, true)
|
||||
source.updateInstance(id, own, form(title = "own"), listOf(5))
|
||||
|
||||
// Same times and rule, so the series is not reshaped — that drops its overrides.
|
||||
val first = occurrences.first()
|
||||
val unchanged = form().copy(start = first.start, due = first.due, rrule = "FREQ=WEEKLY")
|
||||
source.updateSeries(id, first.occurrenceStart!!, unchanged, listOf(60))
|
||||
|
||||
fun leads(anchor: Instant) = db.alarms().forTask(db.tasks().override(id, anchor)!!.id).map { it.minutesBefore }
|
||||
assertThat(db.alarms().forTask(id).map { it.minutesBefore }).containsExactly(60)
|
||||
// A snapshot of the series' reminder follows it…
|
||||
assertThat(leads(completed)).containsExactly(60)
|
||||
// …one set for that occurrence alone does not.
|
||||
assertThat(leads(own)).containsExactly(5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTaskWhoseAlarmsWereTurnedOffElsewhereReportsNone() {
|
||||
val id = source.insertTask(form(due = now + 1.days))
|
||||
db.alarms().setRemindersOff(id, true)
|
||||
|
||||
assertThat(source.reminders()[id]).isEmpty()
|
||||
assertThat(source.reminders()).containsKey(id)
|
||||
|
||||
// A reminder of its own again: the flag goes.
|
||||
source.setReminders(id, listOf(TaskReminder(15)))
|
||||
assertThat(db.tasks().entity(id)!!.remindersOff).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settingTheEditableReminderOwesTheServerAPut() {
|
||||
val work = syncedList()
|
||||
val id = source.insertTask(form(due = now + 1.days).copy(listId = work))
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(isDirty = false))
|
||||
|
||||
source.setAlarm(id, 30)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.isDirty).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deletingATaskInALocalListRemovesItOutright() {
|
||||
val id = source.insertTask(form())
|
||||
@@ -447,7 +575,7 @@ class RoomTasksDataSourceTest {
|
||||
source.updateInstance(id, target.occurrenceStart!!, form(title = "moved"))
|
||||
|
||||
// The fork copies the master's properties, which is what carries the
|
||||
// reminder across — the repository is what puts the series' own back.
|
||||
// reminder across.
|
||||
val override = db.tasks().override(id, target.occurrenceStart)!!
|
||||
assertThat(db.alarms().forTask(override.id).single().minutesBefore).isEqualTo(30)
|
||||
}
|
||||
|
||||
+72
@@ -75,6 +75,78 @@ class TasksDatabaseMigrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun liftsClaimableAlarmsAndPushesRemindersThatNeverLeftTheDevice() {
|
||||
val future = System.currentTimeMillis() + 7L * 24 * 60 * 60 * 1000
|
||||
val past = System.currentTimeMillis() - 7L * 24 * 60 * 60 * 1000
|
||||
val claimable = "X-FOO:bar\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nX-WR-ALARMUID:srv\r\n" +
|
||||
"TRIGGER;RELATED=END:-PT15M\r\nEND:VALARM\r\n"
|
||||
val appleDefault = "BEGIN:VALARM\r\nACTION:DISPLAY\r\nX-APPLE-DEFAULT-ALARM:TRUE\r\n" +
|
||||
"TRIGGER;RELATED=END:-PT30M\r\nEND:VALARM\r\n"
|
||||
helper.createDatabase(TEST_DB, 2).use { db ->
|
||||
db.execSQL("INSERT INTO accounts (id, display_name) VALUES (1, 'me')")
|
||||
db.execSQL("INSERT INTO task_lists (id, name, color, account_id) VALUES (1, 'Synced', 0, 1)")
|
||||
db.execSQL("INSERT INTO task_lists (id, name, color) VALUES (2, 'Local', 0)")
|
||||
db.execSQL("INSERT INTO task_lists (id, name, color, account_id, is_read_only) VALUES (3, 'Shared', 0, 1, 1)")
|
||||
fun task(id: Int, list: Int, due: Long, residue: String? = null) = db.execSQL(
|
||||
"INSERT INTO tasks (id, list_id, uid, title, due, unknown_properties) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
arrayOf<Any?>(id, list, "uid-$id", "Task $id", due, residue),
|
||||
)
|
||||
fun alarm(task: Int, minutes: Int) =
|
||||
db.execSQL("INSERT INTO task_alarms (task_id, minutes_before) VALUES (?, ?)", arrayOf<Any?>(task, minutes))
|
||||
// A server alarm, and the same lead copied locally by a fork.
|
||||
task(1, 1, future, claimable)
|
||||
alarm(1, 15)
|
||||
// Set in Agendula, never uploaded — still to fire, already past, device-only.
|
||||
task(2, 1, future)
|
||||
alarm(2, 30)
|
||||
task(3, 1, past)
|
||||
alarm(3, 30)
|
||||
task(4, 2, future)
|
||||
alarm(4, 30)
|
||||
// Somebody else's default alarm: not ours to claim.
|
||||
task(5, 1, future, appleDefault)
|
||||
// A read-only share: dirty would freeze it, never sent and never refreshed.
|
||||
task(6, 3, future)
|
||||
alarm(6, 30)
|
||||
}
|
||||
|
||||
helper.runMigrationsAndValidate(TEST_DB, 3, true, TasksDatabase.MIGRATION_2_3).use { db ->
|
||||
db.query("SELECT task_id, minutes_before, uid, raw FROM task_alarms ORDER BY task_id").use { c ->
|
||||
val rows = buildList { while (c.moveToNext()) add(listOf(c.getLong(0), c.getInt(1), c.getString(2), c.getString(3))) }
|
||||
// One for task 1: the lifted copy won and the local duplicate went.
|
||||
assertThat(rows.map { it[0] }).containsExactly(1L, 2L, 3L, 4L, 6L).inOrder()
|
||||
assertThat(rows[0][2]).isEqualTo("srv")
|
||||
assertThat(rows[0][3] as String).contains("TRIGGER;RELATED=END:-PT15M")
|
||||
// Every pre-existing row got an identity of its own, shaped as a UUID.
|
||||
assertThat(rows.drop(1).map { it[2] as String }.toSet()).hasSize(4)
|
||||
rows.drop(1).forEach {
|
||||
assertThat(it[2] as String).matches("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")
|
||||
}
|
||||
assertThat(rows.drop(1).all { (it[2] as String).isNotEmpty() && it[3] == null }).isTrue()
|
||||
}
|
||||
db.query("SELECT id, unknown_properties, is_dirty, last_modified, reminders_off FROM tasks ORDER BY id").use { c ->
|
||||
c.moveToNext()
|
||||
assertThat(c.getString(1)).isEqualTo("X-FOO:bar\r\n")
|
||||
assertThat(c.getInt(2)).isEqualTo(0)
|
||||
assertThat(c.getInt(4)).isEqualTo(0)
|
||||
c.moveToNext()
|
||||
assertThat(c.getInt(2)).isEqualTo(1)
|
||||
// The body changes, so its modification stamp does too.
|
||||
assertThat(c.isNull(3)).isFalse()
|
||||
c.moveToNext()
|
||||
assertThat(c.getInt(2)).isEqualTo(0)
|
||||
c.moveToNext()
|
||||
assertThat(c.getInt(2)).isEqualTo(0)
|
||||
c.moveToNext()
|
||||
assertThat(c.getString(1)).contains("X-APPLE-DEFAULT-ALARM:TRUE")
|
||||
assertThat(c.getInt(2)).isEqualTo(0)
|
||||
c.moveToNext()
|
||||
assertThat(c.getInt(2)).isEqualTo(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TEST_DB = "migration-test.db"
|
||||
}
|
||||
|
||||
+8
-5
@@ -299,9 +299,10 @@ private class FakeExternalStore : TasksDataSource {
|
||||
override fun tasks(query: TaskQuery): List<Task> = unused()
|
||||
override fun task(taskId: Long): Task? = unused()
|
||||
override fun subtasks(parentTaskId: Long): List<Task> = unused()
|
||||
override fun insertTask(form: TaskForm): Long = unused()
|
||||
override fun updateTask(taskId: Long, form: TaskForm) = unused()
|
||||
override fun updateInstance(taskId: Long, occurrenceStart: Instant, form: TaskForm) = unused()
|
||||
override fun insertTask(form: TaskForm, reminders: List<TaskReminder>?): Long = unused()
|
||||
override fun updateTask(taskId: Long, form: TaskForm, dueReminders: List<Int>?) = unused()
|
||||
override fun updateInstance(taskId: Long, occurrenceStart: Instant, form: TaskForm, dueReminders: List<Int>?) =
|
||||
unused()
|
||||
override fun setAlarm(taskId: Long, minutesBeforeDue: Int?) = unused()
|
||||
override fun setReminders(taskId: Long, reminders: List<TaskReminder>) = unused()
|
||||
override fun setCompleted(taskId: Long, completed: Boolean) = unused()
|
||||
@@ -309,8 +310,10 @@ private class FakeExternalStore : TasksDataSource {
|
||||
override fun deleteTask(taskId: Long) = unused()
|
||||
override fun setCancelled(taskId: Long, cancelled: Boolean) = unused()
|
||||
override fun setCancelledInstance(taskId: Long, occurrenceStart: Instant, cancelled: Boolean) = unused()
|
||||
override fun updateSeries(seriesId: Long, occurrenceStart: Instant, form: TaskForm) = unused()
|
||||
override fun splitSeries(seriesId: Long, occurrenceStart: Instant, form: TaskForm): Long = unused()
|
||||
override fun updateSeries(seriesId: Long, occurrenceStart: Instant, form: TaskForm, dueReminders: List<Int>?) =
|
||||
unused()
|
||||
override fun splitSeries(seriesId: Long, occurrenceStart: Instant, form: TaskForm, dueReminders: List<Int>?): Long =
|
||||
unused()
|
||||
override fun deleteOccurrence(seriesId: Long, occurrenceStart: Instant) = unused()
|
||||
override fun deleteFollowing(seriesId: Long, occurrenceStart: Instant) = unused()
|
||||
override fun createLocalList(name: String, color: Int): Long = unused()
|
||||
|
||||
Reference in new issue
Block a user