Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
457 changes: 406 additions & 51 deletions crates/openloops-desktop/src/app_model.rs

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions crates/openloops-desktop/src/loop_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const CAP: usize = 55;
/// unbounded, so the `CAP` rejection in `update()` stays rare under ordinary
/// use while still bounding the store's size.
const TERMINAL_EXPIRY_SECONDS: i64 = 180 * 86400;
/// Bound on each Graph id stored in `Reminder::Created`, chosen to fit a
/// single-byte length prefix (real Microsoft Graph To Do list/task ids are
/// consistently well under this). Given the same 2560-byte credential-blob
/// Bound on each provider task-list or task id stored in `Reminder::Created`,
/// chosen to fit a single-byte length prefix (real Microsoft To Do and Google
/// Tasks list/task ids are consistently well under this). Given the same 2560-byte credential-blob
/// ceiling `CAP` is sized against, storing two such ids alongside every
/// record is not something a raised `CAP` could also absorb; a save that
/// would exceed the blob size still fails safely via `encode()`'s existing
Expand All @@ -53,8 +53,8 @@ pub enum Reminder {
#[default]
None,
Attempted,
/// Carries the Graph task-list and task id `reminders::create()`
/// resolved, so a later action (marking it complete once the card is
/// Carries the provider plus the task-list and task id its adapter's
/// `create()` resolved, so a later action (marking it complete once the card is
/// Handled) can address the same task -- see `reminders::complete()`.
/// Each id is bounded to `MAX_REMINDER_ID_LEN` bytes for storage; see
/// that constant for why.
Expand All @@ -63,8 +63,9 @@ pub enum Reminder {
list_id: String,
task_id: String,
},
/// Set only by the reminder-sync check (`reminders::check_status`)
/// finding the linked task already completed in Microsoft To Do --
/// Set only by the reminder-sync check (`provider::reminder_status`)
/// finding the linked task already completed in Microsoft To Do or
/// Google Tasks --
/// never by the user clicking Handled, which leaves `reminder` as
/// `Created` even after `reminders::complete()` succeeds. This is the
/// one thing that distinguishes "the user marked this handled" from
Expand Down Expand Up @@ -393,7 +394,7 @@ pub fn marker(key: &[u8; 32]) -> String {
})
}

/// Appends one Graph id as a single-byte length prefix followed by its
/// Appends one provider task-list or task id as a single-byte length prefix followed by its
/// bytes. Fails rather than silently truncating an id over
/// `MAX_REMINDER_ID_LEN` -- callers must reject or shorten it upstream
/// instead (see `reminders::valid_graph_id`, which already bounds ids this
Expand Down
56 changes: 48 additions & 8 deletions crates/openloops-desktop/src/review_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn reset_card_contexts_call_count() {

pub(crate) struct ReminderDraft {
pub(crate) key: [u8; 32],
pub(crate) provider: MailProvider,
pub(crate) account: String,
pub(crate) title: String,
pub(crate) when: String,
Expand Down Expand Up @@ -1079,23 +1080,23 @@ impl ReviewState {
)
}

/// Still-open, reminder-bearing decisions eligible for a To Do sync
/// Still-open, reminder-bearing decisions eligible for a reminder sync
/// right now: a `Mine`/`Watching`/`Review` decision with a
/// `Reminder::Created` record carrying real (non-empty) ids, matched
/// back to the account that carries evidence for it. `cards` is the
/// caller's own `card_contexts(items)` result -- passed in rather than
/// recomputed here so a caller that already has it (every `sync`/
/// `sync_review` pass) never pays for a second HMAC fingerprint pass
/// just to learn how many cards are eligible. Shared by
/// `AppModel::dispatch_reminder_sync` (the actual Graph call) and
/// `AppModel::reminder_sync_eligible_count` (the Review toolbar's "Sync
/// To Do" button), so the two can never disagree about what counts as
/// `AppModel::dispatch_reminder_sync` (the actual provider calls) and
/// `AppModel::reminder_sync_eligible_count` (the Review toolbar's sync
/// button), so the two can never disagree about what counts as
/// eligible.
pub(crate) fn reminder_sync_checks(
&self,
items: &[LoopItem],
cards: &[Option<CardContext>],
) -> Vec<(String, [u8; 32], String, String)> {
) -> Vec<(MailProvider, String, [u8; 32], String, String)> {
items
.iter()
.zip(cards.iter())
Expand All @@ -1108,7 +1109,7 @@ impl ReviewState {
return None;
}
let Reminder::Created {
provider: MailProvider::Microsoft,
provider,
list_id,
task_id,
} = &card.record.reminder
Expand All @@ -1123,6 +1124,7 @@ impl ReviewState {
.iter()
.find(|m| m.input.handle == item.evidence.message)?;
Some((
*provider,
source.account.clone(),
card.record.key,
list_id.clone(),
Expand Down Expand Up @@ -1875,6 +1877,7 @@ pub fn layout_fixture() -> ReviewState {
});
state.draft = Some(ReminderDraft {
key: second_key,
provider: MailProvider::Microsoft,
account: "synthetic".into(),
title: "Confirm who will send the team budget".into(),
when: default_reminder(),
Expand Down Expand Up @@ -2870,7 +2873,7 @@ mod tests {
}

#[test]
fn google_reminders_are_not_eligible_for_microsoft_sync() {
fn reminder_sync_checks_keep_and_group_provider_provenance() {
let mut state = layout_fixture();
let record = state
.decisions
Expand All @@ -2885,7 +2888,42 @@ mod tests {

let items = &state.analysis.as_ref().unwrap().items;
let cards = state.card_contexts(items);
assert!(state.reminder_sync_checks(items, &cards).is_empty());
let checks = state.reminder_sync_checks(items, &cards);
assert_eq!(checks.len(), 1);
assert_eq!(checks[0].0, MailProvider::Google);
}

#[test]
fn reminder_sync_checks_carry_each_provider_when_both_have_records() {
let mut state = layout_fixture();
let items = state.analysis.as_ref().unwrap().items.clone();
let cards = state.card_contexts(&items);
let second = cards[1].as_ref().unwrap().record.key;
state.apply_decision_change(
second,
Decision::Mine,
Reminder::Created {
provider: MailProvider::Google,
list_id: "synthetic-list".into(),
task_id: "synthetic-task".into(),
},
);
let cards = state.card_contexts(&items);
let checks = state.reminder_sync_checks(&items, &cards);
let mut providers = checks
.iter()
.map(|(provider, _, key, list_id, _)| (*provider, *key, list_id.clone()))
.collect::<Vec<_>>();
providers.sort();
assert_eq!(providers.len(), 2);
assert!(
providers
.iter()
.any(|(provider, _, _)| *provider == MailProvider::Microsoft)
);
assert!(providers.iter().any(|(provider, key, list_id)| {
*provider == MailProvider::Google && *key == second && list_id == "synthetic-list"
}));
}

#[test]
Expand Down Expand Up @@ -2955,6 +2993,7 @@ mod tests {
state.decisions.records = vec![record];
state.draft = Some(ReminderDraft {
key,
provider: source.provider,
account: source.account.clone(),
title: item.action.clone(),
when: default_reminder(),
Expand Down Expand Up @@ -3347,6 +3386,7 @@ mod tests {
let mut state = ReviewState {
draft: Some(ReminderDraft {
key: [7; 32],
provider: MailProvider::Microsoft,
account: "acct".into(),
title: "Send the draft".into(),
when: "2026-09-08 09:00".into(),
Expand Down
Loading
Loading