Skip to content
Merged
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
50 changes: 47 additions & 3 deletions apps/noteiq-windows/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ fn in_call_refresh_index(minutes: u32) -> i32 {
};
i32::try_from(index).unwrap_or_default()
}

/// The interval actually used, which is always the choice shown in Settings.
fn effective_in_call_refresh_minutes(minutes: u32) -> u32 {
usize::try_from(in_call_refresh_index(minutes))
.ok()
.and_then(|index| IN_CALL_REFRESH_CHOICES.get(index).copied())
.unwrap_or(0)
}
const NO_MEETING: &str = "No meeting";

fn no_meeting_row() -> MeetingRow {
Expand Down Expand Up @@ -570,6 +578,9 @@ fn bind_callbacks(
let mut state = state.borrow_mut();
state.settings.meeting_reminders_enabled = enabled;
state.reminders.enabled.store(enabled, Ordering::Relaxed);
if !enabled {
state.reminders.in_call = false;
}
persist_settings(&mut state);
refresh_view(&ui, &state);
});
Expand Down Expand Up @@ -879,6 +890,8 @@ fn check_meeting_reminders(
.enabled
.store(state.settings.meeting_reminders_enabled, Ordering::Relaxed);
if !state.settings.meeting_reminders_enabled {
// Calls are not followed while reminders are off, so the next call seen is new.
state.reminders.in_call = false;
return;
}
let delay = reminder_delay(state.settings.meeting_reminder_delay_minutes);
Expand All @@ -894,7 +907,8 @@ fn check_meeting_reminders(
let defer = call.is_some_and(|in_call| in_call != Some(false));
state.reminders.blocked.store(defer, Ordering::Relaxed);
let in_call = call.flatten() == Some(true);
let call_started = in_call && state.reminders.history.record_call(now);
let continuing = state.reminders.in_call;
let call_started = in_call && state.reminders.history.record_call(now, continuing);
Comment thread
DevSecNinja marked this conversation as resolved.
Resolved
let call_ended = state.reminders.in_call && call == Some(Some(false));
let call_save_due = in_call
&& state
Expand Down Expand Up @@ -968,7 +982,7 @@ fn refresh_meetings_during_call(
}

fn in_call_lookup_due(state: &AppState, now: DateTime<FixedOffset>) -> bool {
let minutes = state.settings.in_call_refresh_minutes;
let minutes = effective_in_call_refresh_minutes(state.settings.in_call_refresh_minutes);
if minutes == 0 || !state.capture_open || meetings_in_progress(&state.meetings, now) == 0 {
return false;
}
Expand Down Expand Up @@ -3063,7 +3077,7 @@ mod tests {
state
.reminders
.history
.record_call(ended.start.unwrap() + TimeDelta::minutes(1));
.record_call(ended.start.unwrap() + TimeDelta::minutes(1), false);
state.reminders.last_lookup = Some(Instant::now());
let (notifier, jobs) = mpsc::channel();
state.reminders.notifier = Some(notifier);
Expand Down Expand Up @@ -3125,6 +3139,27 @@ mod tests {
);
}

#[test]
fn calls_seen_before_and_after_reminders_were_off_are_separate() {
let now = Local::now().fixed_offset();
let (_window, mut state) = window_with(Vec::new(), now);
state.reminders.call_probe = Some(|| Some(true));
let (sender, _events) = mpsc::channel();

check_meeting_reminders(&mut state, &sender, now);
state.settings.meeting_reminders_enabled = false;
check_meeting_reminders(&mut state, &sender, now + TimeDelta::minutes(1));
assert!(!state.reminders.in_call);

state.settings.meeting_reminders_enabled = true;
check_meeting_reminders(&mut state, &sender, now + TimeDelta::hours(2));
assert_eq!(
state.reminders.history.calls.len(),
2,
"the gap while reminders were off is not bridged"
);
}

#[test]
fn a_call_in_progress_is_saved_every_few_minutes() {
let folder = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -3204,6 +3239,15 @@ mod tests {
assert!(in_call_lookup_due(&state, now));
state.settings.in_call_refresh_minutes = minutes + 5;
assert!(!in_call_lookup_due(&state, now), "a longer interval waits");
// A hand-edited 7 shows as "Every 10 minutes", and that is also what is used.
state.settings.in_call_refresh_minutes = 7;
let seven = Instant::now()
.checked_sub(Duration::from_secs(8 * 60))
.unwrap();
state.last_meeting_refresh = Some(seven);
assert_eq!(effective_in_call_refresh_minutes(7), 10);
assert!(!in_call_lookup_due(&state, now), "uses the shown interval");
state.last_meeting_refresh = Some(stale);
state.settings.in_call_refresh_minutes = 0;
assert!(!in_call_lookup_due(&state, now), "Off never checks");
state.settings.in_call_refresh_minutes = minutes;
Expand Down
8 changes: 5 additions & 3 deletions crates/noteiq-core/src/meeting_reminder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,13 @@ impl ReminderHistory {
}

/// Records that the user is in a call at `now`, extending the latest call when the
/// previous check also saw one. Returns whether a new call started, which is worth saving.
pub fn record_call(&mut self, now: DateTime<FixedOffset>) -> bool {
/// previous check also saw one, or when `continuing` says no check saw the call end since,
/// so checks that could not tell do not split a call. Returns whether a new call started,
/// which is worth saving.
pub fn record_call(&mut self, now: DateTime<FixedOffset>, continuing: bool) -> bool {
if let Some(last) = self.calls.last_mut()
&& now >= last.end
&& now - last.end <= CALL_GAP
&& (continuing || now - last.end <= CALL_GAP)
{
last.end = now;
return false;
Expand Down
29 changes: 24 additions & 5 deletions crates/noteiq-core/tests/meeting_reminder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn looked_up(meetings: &[Meeting], minutes: i64) -> ReminderTracker {
/// A history in which the user was in a call during `meeting()`.
fn joined() -> ReminderHistory {
let mut history = ReminderHistory::default();
history.record_call(end() - TimeDelta::minutes(10));
history.record_call(end() - TimeDelta::minutes(10), false);
history
}

Expand Down Expand Up @@ -75,9 +75,9 @@ fn only_meetings_the_user_was_in_a_call_for_are_reminded() {
};
// The call is seen before any calendar details, as when NoteIQ starts late in a meeting.
let mut history = ReminderHistory::default();
assert!(history.record_call(end() - TimeDelta::minutes(1)));
assert!(history.record_call(end() - TimeDelta::minutes(1), false));
assert!(
!history.record_call(end() - TimeDelta::seconds(30)),
!history.record_call(end() - TimeDelta::seconds(30), false),
"the same call"
);
let tracker = looked_up(&[meeting(), earlier.clone()], 6);
Expand Down Expand Up @@ -106,7 +106,7 @@ fn a_call_that_runs_on_starts_the_reminder_window_when_it_ends() {
let mut history = ReminderHistory::default();
let mut at = end() - TimeDelta::minutes(5);
while at <= after_end(3 * 60) {
history.record_call(at);
history.record_call(at, false);
at += TimeDelta::seconds(30);
}
let tracker = looked_up(&[meeting()], 3 * 60);
Expand All @@ -121,6 +121,25 @@ fn a_call_that_runs_on_starts_the_reminder_window_when_it_ends() {
);
}

#[test]
fn checks_that_could_not_tell_do_not_split_a_call_that_runs_on() {
let mut history = ReminderHistory::default();
history.record_call(end() - TimeDelta::minutes(5), false);
// Checks that could not tell for 2.5 hours, then the same call is seen again.
assert!(!history.record_call(after_end(150), true));
assert_eq!(history.calls.len(), 1);
let tracker = looked_up(&[meeting()], 151);
assert_eq!(
ids(tracker.due(after_end(151), DELAY, &history, &[])),
["event-42"],
"the window counts from the end of the call, not from before the gap"
);

// Without a call in progress, a long gap starts a new call.
assert!(history.record_call(after_end(400), false));
assert_eq!(history.calls.len(), 2);
}

#[test]
fn skips_meetings_that_need_no_note() {
let skipped = [
Expand Down Expand Up @@ -281,7 +300,7 @@ fn entries_saved_with_an_older_key_still_suppress_their_meeting() {
let mut history = ReminderHistory::load(&path);
assert!(history.contains(&meeting()));
assert_eq!(history.meeting("ffffffffffffffff"), Some(&meeting()));
history.record_call(end() - TimeDelta::minutes(10));
history.record_call(end() - TimeDelta::minutes(10), false);
let tracker = looked_up(&[meeting()], 6);
assert!(tracker.due(after_end(6), DELAY, &history, &[]).is_empty());
}
Expand Down
Loading