Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Reminders: an audit of sync and writes, and its fixes

Yashwanth Kamireddi91781fb2b1a1
diff --git a/crates/quince-core/src/reminders.rs b/crates/quince-core/src/reminders.rs
index fba1ef4..d19a038 100644
--- a/crates/quince-core/src/reminders.rs
+++ b/crates/quince-core/src/reminders.rs
@@ -886,42 +886,45 @@ impl Library {
Ok(found)
}
+ /// One reminder by its id, wherever it is and however long its list: what a change waiting
+ /// to be sent is checked against. (Through a list, one past the most a list returns was
+ /// taken for deleted and its change dropped unsent.)
+ pub fn reminder(&self, guid: &str) -> Result<Option<Reminder>> {
+ use rusqlite::OptionalExtension;
+ Ok(self
+ .conn
+ .query_row(
+ &format!("SELECT {REMINDER_COLUMNS} FROM reminders WHERE guid = ?1"),
+ params![guid],
+ reminder_row,
+ )
+ .optional()?
+ .map(|(r, _)| r))
+ }
+
+ /// A reminder's subtasks, every one, wherever they are.
+ pub fn subtasks_of(&self, parent: &str) -> Result<Vec<Reminder>> {
+ let mut stmt = self.conn.prepare(&format!(
+ "SELECT {REMINDER_COLUMNS} FROM reminders WHERE parent_guid = ?1"
+ ))?;
+ let rows = stmt.query_map(params![parent], reminder_row)?;
+ Ok(rows
+ .collect::<rusqlite::Result<Vec<_>>>()?
+ .into_iter()
+ .map(|(r, _)| r)
+ .collect())
+ }
+
pub fn reminders_in(&self, list_guid: &str, include_done: bool) -> Result<Vec<Reminder>> {
let list = self
.reminder_lists()?
.into_iter()
.find(|l| l.guid == list_guid);
- let mut stmt = self.conn.prepare(
- "SELECT guid, list_guid, title, notes, due_at, completed_at, priority, flagged,
- parent_guid, recur_frequency, recur_interval, etag, timezone, section_guid, all_day,
- CASE WHEN json_valid(raw)
- THEN json_extract(raw, '$.fields.CreationDate.value') END
- FROM reminders
- WHERE list_guid = ?1 AND (?2 = 1 OR completed_at IS NULL)",
- )?;
- let rows = stmt.query_map(params![list_guid, i64::from(include_done)], |row| {
- Ok((
- Reminder {
- guid: row.get(0)?,
- list_guid: row.get(1)?,
- title: row.get(2)?,
- notes: row.get(3)?,
- due_at: row.get(4)?,
- completed_at: row.get(5)?,
- priority: row.get(6)?,
- flagged: row.get::<_, i64>(7)? != 0,
- parent_guid: row.get(8)?,
- recur_frequency: row.get(9)?,
- recur_interval: row.get(10)?,
- etag: row.get(11)?,
- raw: None,
- timezone: row.get(12)?,
- section_guid: row.get(13)?,
- all_day: row.get::<_, i64>(14)? != 0,
- },
- row.get::<_, Option<i64>>(15).unwrap_or(None),
- ))
- })?;
+ let mut stmt = self.conn.prepare(&format!(
+ "SELECT {REMINDER_COLUMNS} FROM reminders
+ WHERE list_guid = ?1 AND (?2 = 1 OR completed_at IS NULL)"
+ ))?;
+ let rows = stmt.query_map(params![list_guid, i64::from(include_done)], reminder_row)?;
let mut found = rows.collect::<rusqlite::Result<Vec<_>>>()?;
let (sorting, order) = list
.map(|l| (l.sorting, l.reminder_order))
@@ -932,6 +935,37 @@ impl Library {
}
}
+/// The columns a reminder is read from, in the order [`reminder_row`] takes them.
+const REMINDER_COLUMNS: &str =
+ "guid, list_guid, title, notes, due_at, completed_at, priority, flagged,
+ parent_guid, recur_frequency, recur_interval, etag, timezone, section_guid, all_day,
+ CASE WHEN json_valid(raw) THEN json_extract(raw, '$.fields.CreationDate.value') END";
+
+/// A reminder, and when it was made, from a row of [`REMINDER_COLUMNS`].
+fn reminder_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<(Reminder, Option<i64>)> {
+ Ok((
+ Reminder {
+ guid: row.get(0)?,
+ list_guid: row.get(1)?,
+ title: row.get(2)?,
+ notes: row.get(3)?,
+ due_at: row.get(4)?,
+ completed_at: row.get(5)?,
+ priority: row.get(6)?,
+ flagged: row.get::<_, i64>(7)? != 0,
+ parent_guid: row.get(8)?,
+ recur_frequency: row.get(9)?,
+ recur_interval: row.get(10)?,
+ etag: row.get(11)?,
+ raw: None,
+ timezone: row.get(12)?,
+ section_guid: row.get(13)?,
+ all_day: row.get::<_, i64>(14)? != 0,
+ },
+ row.get::<_, Option<i64>>(15).unwrap_or(None),
+ ))
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/quince-icloud/src/cloudkit.rs b/crates/quince-icloud/src/cloudkit.rs
index 8ff394a..1cd839b 100644
--- a/crates/quince-icloud/src/cloudkit.rs
+++ b/crates/quince-icloud/src/cloudkit.rs
@@ -145,9 +145,9 @@ impl<'a> ZoneClient<'a> {
}
if tries >= BUSY_TRIES {
quiet!("cloudkit: still busy after {tries} tries ({status})");
- return Err(Error::Refused(
- "iCloud is busy right now. Nothing was changed — try again in a minute.".into(),
- ));
+ // Busy, not refused: nothing was applied, and a change waiting to be sent is
+ // kept for later rather than dropped as if Apple had turned it down.
+ return Err(Error::Busy);
}
let asked = serde_json::from_str::<Value>(&text)
.ok()
@@ -833,12 +833,7 @@ impl ZoneClient<'_> {
))
.await;
}
- Err(Error::Busy) => {
- return Err(Error::Refused(
- "iCloud is busy right now. Nothing was changed — try again in a minute."
- .into(),
- ))
- }
+ Err(Error::Busy) => return Err(Error::Busy),
other => return other,
}
}
@@ -926,6 +921,23 @@ impl ZoneClient<'_> {
.await
}
+ /// [`Self::update_record_signed`] with no retry: a conflict comes back as
+ /// [`Error::Conflict`], for a caller whose fields were built from the record as it stood
+ /// (a reminder's title document) and must be built again, not resent.
+ pub async fn update_record_signed_exact(
+ &self,
+ zone: &str,
+ record_name: &str,
+ record_type: &str,
+ change_tag: &str,
+ mut changes: Value,
+ ) -> Result<Value> {
+ let current = self.lookup_record(zone, record_name).await?;
+ stamp_tokens(&mut changes, current.as_ref());
+ self.update_record_exact(zone, record_name, record_type, change_tag, changes)
+ .await
+ }
+
/// Change a record by working the change out from the record as Apple holds it, written
/// only over that exact version — and, if another device wrote first, read again and
/// worked out again. For fields written whole from what was read, such as a list's order:
diff --git a/crates/quince-icloud/src/reminders.rs b/crates/quince-icloud/src/reminders.rs
index 4b7e72d..9c333f8 100644
--- a/crates/quince-icloud/src/reminders.rs
+++ b/crates/quince-icloud/src/reminders.rs
@@ -960,10 +960,16 @@ pub fn apply_cloudkit(
Default::default()
};
for reminder in &mut reminders {
+ // A rule counts only for a reminder that still lists one: a repeat cleared on the phone
+ // can leave its rule record in the zone, and taken as repeating, the reminder could
+ // not be ticked ("Apple did not say on what schedule").
+ if !with_rules.contains(&reminder.guid) {
+ continue;
+ }
if let Some((frequency, interval)) = rules.get(&reminder.guid) {
reminder.recur_frequency = Some(*frequency);
reminder.recur_interval = Some(*interval);
- } else if with_rules.contains(&reminder.guid) {
+ } else {
if let Some(&(frequency, interval)) = stored_repeats.get(&reminder.guid) {
reminder.recur_frequency = Some(frequency);
reminder.recur_interval = interval;
@@ -1467,6 +1473,38 @@ pub async fn edit_cloudkit(
params: Vec<(String, String)>,
reminder: &Reminder,
edit: &ReminderEdit,
+) -> Result<()> {
+ // A title or notes edit is built from the document as it stood: if another device wrote
+ // first it is built again from theirs, never resent over it.
+ if edit.title.is_some() || edit.notes.is_some() {
+ match edit_once(
+ http,
+ ckdatabasews_root,
+ params.clone(),
+ reminder,
+ edit,
+ true,
+ )
+ .await
+ {
+ Err(Error::Conflict) => {
+ return edit_once(http, ckdatabasews_root, params, reminder, edit, true).await;
+ }
+ other => return other,
+ }
+ }
+ edit_once(http, ckdatabasews_root, params, reminder, edit, false).await
+}
+
+/// One try at [`edit_cloudkit`]; `exact` writes only over the version read, a conflict
+/// coming back as [`Error::Conflict`].
+async fn edit_once(
+ http: &reqwest::Client,
+ ckdatabasews_root: &str,
+ params: Vec<(String, String)>,
+ reminder: &Reminder,
+ edit: &ReminderEdit,
+ exact: bool,
) -> Result<()> {
if edit.is_empty() {
return Ok(());
@@ -1493,13 +1531,24 @@ pub async fn edit_cloudkit(
} else {
None
};
- let document = |field: &str, text: &str| -> String {
- current
+ // A document there that cannot be edited exactly is refused, never written over with a new
+ // one: a fresh document drops the records devices merge by, and a phone merging it with its
+ // own copy could show the title doubled or lose it.
+ let document = |field: &str, text: &str| -> Result<String> {
+ match current
.as_ref()
.and_then(|rec| rec.pointer(&format!("/fields/{field}/value")))
.and_then(Value::as_str)
- .and_then(|existing| crate::ckdocument::replace_text_in_base64(existing, text))
- .unwrap_or_else(|| crate::ckdocument::text_to_base64(text))
+ .filter(|existing| !existing.is_empty())
+ {
+ None => Ok(crate::ckdocument::text_to_base64(text)),
+ Some(existing) => crate::ckdocument::replace_text_in_base64(existing, text).ok_or_else(|| {
+ Error::Refused(
+ "Quince can’t safely change this reminder’s text yet, so nothing was changed. Editing it on an Apple device is safe."
+ .into(),
+ )
+ }),
+ }
};
if let Some(title) = &edit.title {
@@ -1507,7 +1556,7 @@ pub async fn edit_cloudkit(
"TitleDocument".into(),
serde_json::json!({
"type": "ENCRYPTED_BYTES",
- "value": document("TitleDocument", title.trim()),
+ "value": document("TitleDocument", title.trim())?,
}),
);
}
@@ -1520,7 +1569,7 @@ pub async fn edit_cloudkit(
"NotesDocument".into(),
serde_json::json!({
"type": "ENCRYPTED_BYTES",
- "value": document("NotesDocument", text),
+ "value": document("NotesDocument", text)?,
}),
);
}
@@ -1610,9 +1659,24 @@ pub async fn edit_cloudkit(
.and_then(Value::as_str)
.or(reminder.etag.as_deref());
- client
- .update_record_signed(ZONE, &reminder.guid, "Reminder", tag, Value::Object(fields))
- .await?;
+ match (exact, tag) {
+ (true, Some(tag)) => {
+ client
+ .update_record_signed_exact(
+ ZONE,
+ &reminder.guid,
+ "Reminder",
+ tag,
+ Value::Object(fields),
+ )
+ .await?
+ }
+ _ => {
+ client
+ .update_record_signed(ZONE, &reminder.guid, "Reminder", tag, Value::Object(fields))
+ .await?
+ }
+ };
// Moved to another list: it joins the end of that list's order and leaves the old one's,
// as on the phone. The move itself has happened either way.
if let Some(list_guid) = edit
@@ -1823,6 +1887,41 @@ fn in_list(r: &Value, list_guid: &str) -> bool {
== Some(list_guid)
}
+/// Whether a tick made here at `made_at` (seconds) has been overtaken at Apple: the reminder
+/// is gone, already ticked as wanted (a one-off), or changed on another device after it was
+/// made — a later change there wins, as it would had both been made online. A few seconds'
+/// grace for the two clocks.
+pub async fn tick_overtaken(
+ http: &reqwest::Client,
+ ckdatabasews_root: &str,
+ params: Vec<(String, String)>,
+ reminder: &Reminder,
+ done: bool,
+ made_at: i64,
+) -> Result<bool> {
+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
+ let Some(current) = client.lookup_record(ZONE, &reminder.guid).await? else {
+ return Ok(true);
+ };
+ let completed = current
+ .pointer("/fields/Completed/value")
+ .and_then(Value::as_i64)
+ .is_some_and(|v| v != 0);
+ if !reminder.repeats() && completed == done {
+ return Ok(true);
+ }
+ let changed = [
+ current.pointer("/fields/LastModifiedDate/value"),
+ current.pointer("/modified/timestamp"),
+ ]
+ .into_iter()
+ .flatten()
+ .filter_map(Value::as_i64)
+ .max()
+ .unwrap_or(0);
+ Ok(changed > (made_at + 5) * 1000)
+}
+
/// Tick a CloudKit reminder off, or put it back.
///
/// Sends only the fields that change, guarded by the record's change tag, so a reminder
@@ -1895,10 +1994,19 @@ pub async fn set_completed_cloudkit(
&reminder.guid,
"Reminder",
reminder.etag.as_deref(),
- serde_json::json!({
- "Completed": { "value": i64::from(done), "type": "NUMBER_INT64" },
- "LastModifiedDate": { "value": now_millis(), "type": "TIMESTAMP" },
- }),
+ {
+ let mut fields = serde_json::json!({
+ "Completed": { "value": i64::from(done), "type": "NUMBER_INT64" },
+ "LastModifiedDate": { "value": now_millis(), "type": "TIMESTAMP" },
+ });
+ // When it was ticked, as the phone records it: without it a reminder ticked
+ // again here kept the date it was first completed on, everywhere.
+ if done {
+ fields["CompletionDate"] =
+ serde_json::json!({ "value": now_millis(), "type": "TIMESTAMP" });
+ }
+ fields
+ },
)
.await?;
Ok(())
diff --git a/probe/examples/notes_list.rs b/probe/examples/notes_list.rs
index d4bf190..9ae7362 100644
--- a/probe/examples/notes_list.rs
+++ b/probe/examples/notes_list.rs
@@ -42,7 +42,13 @@ async fn main() -> Result<()> {
.unwrap_or_default()
.iter()
.filter_map(|x| x.attachment.clone())
- .map(|a| if std::env::var("FULL").is_ok() { a } else { a.chars().take(4).collect() })
+ .map(|a| {
+ if std::env::var("FULL").is_ok() {
+ a
+ } else {
+ a.chars().take(4).collect()
+ }
+ })
.collect();
println!(
"{} | {:30} | deleted {} | folder {} | atts {} | created {} | {:?} | modified {}",
diff --git a/probe/examples/reminder_outbox_live.rs b/probe/examples/reminder_outbox_live.rs
index 3affcc0..0c30a5f 100644
--- a/probe/examples/reminder_outbox_live.rs
+++ b/probe/examples/reminder_outbox_live.rs
@@ -65,6 +65,28 @@ async fn main() -> Result<()> {
completed().await?
);
anyhow::ensure!(completed().await?);
+ // Ticked here, the time it was ticked is Apple's own field, as the phone writes it.
+ let rec = zc
+ .lookup_record("Reminders", &guid)
+ .await?
+ .ok_or_else(|| anyhow!("gone"))?;
+ let when = rec
+ .pointer("/fields/CompletionDate/value")
+ .and_then(serde_json::Value::as_i64);
+ let now = jiff::Timestamp::now().as_second();
+ println!(
+ "CompletionDate written: {:?} ({}s ago)",
+ when,
+ when.map_or(-1, |w| now - w / 1000)
+ );
+ anyhow::ensure!(when.is_some_and(|w| (now - w / 1000).abs() < 120));
+ // A queued tick Apple already holds steps aside; an old untick, overtaken by the tick
+ // made since, steps aside; an untick made after Apple's last change goes.
+ let held = r::tick_overtaken(&http, &root, p.clone(), &reminder, true, now).await?;
+ let old = r::tick_overtaken(&http, &root, p.clone(), &reminder, false, 1).await?;
+ let fresh = r::tick_overtaken(&http, &root, p.clone(), &reminder, false, now + 60).await?;
+ println!("overtaken: already held {held}, older than Apple's {old}, newer {fresh}");
+ anyhow::ensure!(held && old && !fresh);
// Untick then, sent on the change tag the library held before the tick — stale, as the
// worker's would be until the next pass.
lib.outbox_push("reminders", &guid, "done", "{\"done\":false,\"at\":1}")?;
diff --git a/src-tauri/src/alerts.rs b/src-tauri/src/alerts.rs
index 5dd06b7..04f91af 100644
--- a/src-tauri/src/alerts.rs
+++ b/src-tauri/src/alerts.rs
@@ -183,6 +183,17 @@ fn show(app: AppHandle, due: DueAlarm) {
}
#[cfg(all(unix, not(target_os = "macos")))]
{
+ // The occurrence this alert is for: a repeating reminder ticked since (here or on the
+ // phone) has moved on, and a press on this alert must not move it on again.
+ let due_then = {
+ let app = app.clone();
+ let guid = due.reminder_guid.clone();
+ tauri::async_runtime::block_on(async move {
+ let data = app.state::<Data>();
+ let library = data.0.lock().await;
+ library.reminder(&guid).ok().flatten().map(|r| r.due_at)
+ })
+ };
let shown = notify_rust::Notification::new()
.appname("Quince")
.summary(&due.title)
@@ -206,7 +217,19 @@ fn show(app: AppHandle, due: DueAlarm) {
tauri::async_runtime::block_on(async move {
let auth = app.state::<Auth>();
let data = app.state::<Data>();
- if let Err(e) =
+ let now = data
+ .0
+ .lock()
+ .await
+ .reminder(&due.reminder_guid)
+ .ok()
+ .flatten();
+ let same = now.as_ref().is_some_and(|r| {
+ r.completed_at.is_none() && Some(r.due_at) == due_then
+ });
+ if !same {
+ quiet!("an alert was answered after its reminder had moved on");
+ } else if let Err(e) =
crate::set_done(&auth, &data, &due.reminder_guid, &due.list_guid, true)
.await
{
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 343813a..21b986d 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1526,10 +1526,9 @@ async fn set_done(
let reminder = {
let library = data.0.lock().await;
library
- .reminders_in(list_guid, true)
+ .reminder(guid)
.map_err(|e| e.to_string())?
- .into_iter()
- .find(|r| r.guid == guid)
+ .filter(|r| r.list_guid == list_guid)
.ok_or("That reminder is no longer in the local library.")?
};
if !(done && reminder.repeats()) {
@@ -1575,10 +1574,9 @@ async fn reminder_set_repeat(
let reminder = {
let library = data.0.lock().await;
library
- .reminders_in(&list_guid, true)
+ .reminder(&guid)
.map_err(|e| e.to_string())?
- .into_iter()
- .find(|r| r.guid == guid)
+ .filter(|r| r.list_guid == list_guid)
.ok_or("That reminder is no longer in the local library.")?
};
@@ -1642,9 +1640,14 @@ async fn reminder_create(
flagged,
..Default::default()
};
- quince_icloud::reminders::edit_cloudkit(&http, &root, params.clone(), &made, &edit)
- .await
- .map_err(|e| e.to_string())?;
+ // The reminder exists at Apple now, whatever happens next: a failure here must not
+ // read as "nothing was made", or the title put back and entered again made a second.
+ if let Err(e) =
+ quince_icloud::reminders::edit_cloudkit(&http, &root, params.clone(), &made, &edit)
+ .await
+ {
+ quiet!("a new reminder's date or flag was not set: {e}");
+ }
}
refresh_reminders(&http, &root, params, &data, false).await
@@ -1662,16 +1665,25 @@ async fn reminder_delete(
let reminder = {
let library = data.0.lock().await;
library
- .reminders_in(&list_guid, true)
+ .reminder(&guid)
.map_err(|e| e.to_string())?
- .into_iter()
- .find(|r| r.guid == guid)
+ .filter(|r| r.list_guid == list_guid)
.ok_or("That reminder is no longer in the local library.")?
};
+ // Its subtasks go with it, as on the phone: left behind they came back at the top level
+ // here and stayed in iCloud.
+ let children = data.0.lock().await.subtasks_of(&guid).unwrap_or_default();
quince_icloud::reminders::delete_cloudkit(&http, &root, params.clone(), &reminder)
.await
.map_err(|e| e.to_string())?;
+ for child in &children {
+ if let Err(e) =
+ quince_icloud::reminders::delete_cloudkit(&http, &root, params.clone(), child).await
+ {
+ quiet!("a subtask did not go with its reminder: {e}");
+ }
+ }
refresh_reminders(&http, &root, params, &data, false).await
}
@@ -1690,10 +1702,9 @@ async fn reminder_edit(
let reminder = {
let library = data.0.lock().await;
library
- .reminders_in(&list_guid, true)
+ .reminder(&guid)
.map_err(|e| e.to_string())?
- .into_iter()
- .find(|r| r.guid == guid)
+ .filter(|r| r.list_guid == list_guid)
.ok_or("That reminder is no longer in the local library.")?
};
@@ -1706,12 +1717,7 @@ async fn reminder_edit(
if let Some(to) = edit.list_guid.as_deref().filter(|to| *to != list_guid) {
let children: Vec<quince_core::reminders::Reminder> = {
let library = data.0.lock().await;
- library
- .reminders_in(&list_guid, true)
- .unwrap_or_default()
- .into_iter()
- .filter(|r| r.parent_guid.as_deref() == Some(guid.as_str()))
- .collect()
+ library.subtasks_of(&guid).unwrap_or_default()
};
let follow = quince_icloud::reminders::ReminderEdit {
list_guid: Some(to.to_string()),
diff --git a/src-tauri/src/outbox.rs b/src-tauri/src/outbox.rs
index ff7589f..053e09c 100644
--- a/src-tauri/src/outbox.rs
+++ b/src-tauri/src/outbox.rs
@@ -60,16 +60,22 @@ enum Outcome {
}
/// Whether Apple could not be reached (keep it) rather than said no (drop it).
-fn transient(e: &Error) -> bool {
- matches!(
- e,
+/// How many times an answer this app does not understand is retried before the change is
+/// given up and said to be refused — a fault that will never clear held every change queued
+/// after it forever, each shown as made.
+const PROTOCOL_TRIES: i64 = 5;
+
+fn transient(e: &Error, tries: i64) -> bool {
+ match e {
Error::Network(_)
- | Error::ReauthRequired
- | Error::Protocol(_)
- | Error::StaleCursor
- | Error::Io(_)
- | Error::Storage(_)
- )
+ | Error::ReauthRequired
+ | Error::StaleCursor
+ | Error::Busy
+ | Error::Io(_)
+ | Error::Storage(_) => true,
+ Error::Protocol(_) => tries < PROTOCOL_TRIES,
+ _ => false,
+ }
}
#[derive(Clone, serde::Serialize)]
@@ -105,6 +111,20 @@ async fn drain_reminders(app: &AppHandle) -> Outcome {
let report = drain(&data.0, &crate::REMINDERS_PASS, |reminder, d| {
let (http, root, params) = (http.clone(), root.clone(), params.clone());
async move {
+ // A change made on another device after this one was queued wins; the pass after
+ // sending reads Apple's version back.
+ if quince_icloud::reminders::tick_overtaken(
+ &http,
+ &root,
+ params.clone(),
+ &reminder,
+ d.done,
+ d.at,
+ )
+ .await?
+ {
+ return Ok(());
+ }
quince_icloud::reminders::set_completed_cloudkit(
&http, &root, params, &reminder, d.done,
)
@@ -170,11 +190,7 @@ where
let _pass = pass.lock().await;
let reminder = {
let lib = library.lock().await;
- lib.reminder_list_of(&p.record)
- .ok()
- .flatten()
- .and_then(|l| lib.reminders_in(&l, true).ok())
- .and_then(|rs| rs.into_iter().find(|r| r.guid == p.record))
+ lib.reminder(&p.record).ok().flatten()
};
let Some(reminder) = reminder else {
// Gone from the library (deleted here or elsewhere): nothing left to send.
@@ -195,7 +211,7 @@ where
let _ = library.lock().await.outbox_done(p.id);
report.sent = true;
}
- Err(e) if transient(&e) => {
+ Err(e) if transient(&e, p.tries) => {
let _ = library.lock().await.outbox_retry(p.id, &e.to_string());
report.outcome = Outcome::Later;
return report;
diff --git a/src-tauri/src/refresh.rs b/src-tauri/src/refresh.rs
index 768dc5f..b73b168 100644
--- a/src-tauri/src/refresh.rs
+++ b/src-tauri/src/refresh.rs
@@ -205,6 +205,10 @@ async fn run(client: &Arc<Mutex<Client>>, data: &Mutex<Library>, services: &[&st
move |library, f| {
let (lists, count, _) =
quince_icloud::reminders::apply_cloudkit(library, f)?;
+ // Changes still on their way to Apple stay as made here: without this
+ // a reminder ticked offline showed open again after every pass, and
+ // its alert could ring for something already done.
+ crate::outbox::replay_reminders(library)?;
if full {
library.mark_full_sync("reminders")?;
}
diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsx
index f21fde8..fd27859 100644
--- a/src/screens/RemindersView.tsx
+++ b/src/screens/RemindersView.tsx
@@ -555,7 +555,9 @@ export function RemindersView() {
.slice(0, index)
.reverse()
.find((x) => !x.parentGuid);
- if (!above) return Promise.resolve(null);
+ // One with subtasks of its own stays where it is: nested, they would be two deep, which
+ // Apple does not keep, and they vanished from the list.
+ if (!above || flat.some((x) => x.parentGuid === r.guid)) return Promise.resolve(null);
return write(
r,
() => api.reminderEdit(r.guid, r.listGuid, { parentGuid: above.guid }),
@@ -1473,10 +1475,9 @@ export function RemindersView() {
>
Move Out of Subtasks
</button>
- ) : (
+ ) : items.some((x) => x.parentGuid === reminder.guid) ? null : (
<button
className="rx-link"
-
onClick={() => void indent(reminder)}
>
Make Subtask
@@ -1550,9 +1551,11 @@ export function RemindersView() {
{ label: r.flagged ? "Unflag" : "Flag", run: () => void flag(r) },
{ label: r.completedAt ? "Mark as Not Completed" : "Mark as Completed", run: () => void toggle(r) },
null,
- r.parentGuid
- ? { label: "Outdent", run: () => void outdent(r) }
- : { label: "Indent", run: () => void indent(r) },
+ ...(r.parentGuid
+ ? [{ label: "Outdent", run: () => void outdent(r) }]
+ : items.some((x) => x.parentGuid === r.guid)
+ ? []
+ : [{ label: "Indent", run: () => void indent(r) }]),
// Only where there is somewhere else to go: an empty submenu is a dead end.
...(lists.some((l) => l.guid !== r.listGuid)
? [{