Skip to content
Draft
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
14 changes: 7 additions & 7 deletions apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ pub fn is_recovered(doc: &DocMeta) -> bool {
/// unexpectedly", how much audio the meeting missed while it recorded, or,
/// when a repair added words after the notes were written, "Transcript
/// updated" with a way to update the notes.
/// `dismissed` runs after the note's flags are cleared.
/// `dismissed` runs after the note's flags are cleared. `update_notes` is
/// the pane's own Write notes, so an edited summary is never replaced
/// without asking.
pub fn recovered(
doc: Option<&DocMeta>,
palette: &Palette,
dismissed: impl Fn(&mut App) + 'static,
update_notes: impl Fn(&mut App) + 'static,
) -> Option<AnyElement> {
let doc = doc?;
let recovered = is_recovered(doc);
Expand Down Expand Up @@ -106,12 +109,9 @@ pub fn recovered(
Some(dismiss),
));
}
let update: cap_ai::Handler = Box::new(move |_, _, cx| {
if let Some(meetings) = Meetings::try_global(cx) {
meetings.update(cx, |m, cx| m.update_notes(&id, cx));
}
clear(cx);
});
// The line stays until new notes land (writing them clears the flag), so
// cancelling "Replace notes?" keeps the reminder.
let update: cap_ai::Handler = Box::new(move |_, _, cx| update_notes(cx));
Some(cap_ai::dock_line(
palette,
tr::documents::notes::transcript_updated().into(),
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/src/meetings_ui/documents/cap_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ pub fn dock_line(
el.child(
div()
.id("cap-ai-dock-action")
.debug_selector(|| "cap-ai-dock-action".into())
.h(px(22.))
.px(px(9.))
.flex()
Expand Down
83 changes: 48 additions & 35 deletions apps/desktop-gpui/src/meetings_ui/documents/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2707,34 +2707,39 @@ impl Pane {
return;
}
if self.has_enhanced() && self.enhanced_edited {
let Some(window) = cx
.windows()
.into_iter()
.find(|w| Some(*w) == crate::meetings_ui::MeetingWindows::get(cx).documents)
else {
return;
};
// Deferred: a click or menu action in the documents window is
// still dispatching there, and the window can't be updated from
// inside its own event.
let pane = cx.weak_entity();
window
.update(cx, |_, window, cx| {
let answer = window.prompt(
gpui::PromptLevel::Warning,
tr::documents::confirm::replace_notes(),
Some(tr::documents::confirm::replace_notes_detail()),
&[
gpui::PromptButton::ok(tr::documents::confirm::replace()),
gpui::PromptButton::cancel(tr::common::cancel()),
],
cx,
);
cx.spawn(async move |cx| {
if answer.await.ok() == Some(0) {
pane.update(cx, |pane, cx| pane.generate(options, cx)).ok();
}
cx.defer(move |cx| {
let Some(window) = cx
.windows()
.into_iter()
.find(|w| Some(*w) == crate::meetings_ui::MeetingWindows::get(cx).documents)
else {
return;
};
window
.update(cx, |_, window, cx| {
let answer = window.prompt(
gpui::PromptLevel::Warning,
tr::documents::confirm::replace_notes(),
Some(tr::documents::confirm::replace_notes_detail()),
&[
gpui::PromptButton::ok(tr::documents::confirm::replace()),
gpui::PromptButton::cancel(tr::common::cancel()),
],
cx,
);
cx.spawn(async move |cx| {
if answer.await.ok() == Some(0) {
pane.update(cx, |pane, cx| pane.generate(options, cx)).ok();
}
})
.detach();
})
.detach();
})
.ok();
.ok();
});
return;
}
self.generate(options, cx);
Expand Down Expand Up @@ -3995,15 +4000,23 @@ impl Pane {
return None;
}
let pane = cx.weak_entity();
if let Some(line) = super::bar::health_line::recovered(self.doc.as_ref(), &palette, move |cx| {
pane.update(cx, |p, cx| {
if let Some(doc) = p.doc.as_mut() {
super::bar::health_line::forget(doc);
}
cx.notify();
})
.ok();
}) {
let writer = cx.weak_entity();
if let Some(line) = super::bar::health_line::recovered(
self.doc.as_ref(),
&palette,
move |cx| {
pane.update(cx, |p, cx| {
if let Some(doc) = p.doc.as_mut() {
super::bar::health_line::forget(doc);
}
cx.notify();
})
.ok();
},
move |cx| {
writer.update(cx, |p, cx| p.write_notes(None, cx)).ok();
},
) {
return Some(line);
}
if self.too_short && !self.has_enhanced() {
Expand Down
156 changes: 156 additions & 0 deletions apps/desktop-gpui/src/meetings_ui/documents/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,3 +2713,159 @@ fn a_long_list_item_in_an_answer_wraps_like_the_lines_around_it(cx: &mut TestApp
assert!(height(url, cx) > line * 2., "{url}: an unbroken link wraps");
}
}

/// A finished meeting whose summary was written before a repair added
/// words, so the note offers "Transcript updated · Update notes", drawn in
/// its own window with Cap Notes running.
fn stale_summary(
edited: bool,
cx: &mut TestAppContext,
) -> (
tempfile::TempDir,
String,
Entity<Pane>,
&mut VisualTestContext,
) {
let dir = tempfile::tempdir().unwrap();
let library = Library::open(dir.path().join("documents")).unwrap();
let now = Utc::now();
let mut meta = library
.create(DocKind::Meeting, now - ChronoDuration::hours(1), 7)
.unwrap();
meta.title = "Weekly".into();
meta.title_is_auto = false;
meta.meeting = Some(MeetingDetails {
started_at: Some(now - ChronoDuration::hours(1)),
ended_at: Some(now - ChronoDuration::minutes(30)),
duration_ms: 30 * 60_000,
has_enhanced: true,
..MeetingDetails::default()
});
crate::meetings::persist::set_flag(&mut meta, crate::meetings::persist::NOTES_STALE_KEY, true);
library.save(&meta).unwrap();
// Cap wrote the summary; an edited one also has a line the person typed.
let markdown = if edited {
"### Summary\n\nShip the deck on Friday\n\nAsk Sam about pricing\n"
} else {
"### Summary\n\nShip the deck on Friday\n"
};
let mut summary = Document::from_markdown(markdown);
let typed = if edited {
summary.blocks.len() - 1
} else {
usize::MAX
};
for (index, block) in summary.blocks.iter_mut().enumerate() {
if index != typed {
block.origin = cap_notes::Origin::Generated;
}
}
library
.write_enhanced(&meta.id, &summary.to_json())
.unwrap();
let id = meta.id.clone();
let calendar_dir = dir.path().join("calendar");
cx.update(|cx| {
crate::meetings::Meetings::install_for_tests(
cap_meetings::settings::MeetingSettings::default(),
calendar_dir,
cx,
);
});
let store = cx.new(|cx| DocStore::with_library(Some(library.clone()), cx));
let theme = Theme::light();
let pane_store = store.clone();
let (pane, cx) = cx.add_window_view(|window, cx| {
Pane::new(
pane_store,
gpui::WeakEntity::new_invalid(),
&theme,
window,
cx,
)
});
cx.update(|window, cx| {
crate::meetings_ui::MeetingWindows::get(cx).documents = Some(window.window_handle());
});
cx.simulate_resize(gpui::size(gpui::px(1000.), gpui::px(700.)));
cx.run_until_parked();
store.update(cx, |s, cx| s.open(Some(id.clone()), cx));
cx.run_until_parked();
assert!(super::writer::flush_blocking(
std::time::Duration::from_secs(5)
));
cx.run_until_parked();
assert_eq!(
pane.read_with(cx, |p, _| p.enhanced_edited),
edited,
"the loaded summary reads as edited only when the person typed in it"
);
(dir, id, pane, cx)
}

/// Waits for the save writer, since Write notes starts only once every
/// queued save has landed.
fn after_queued_saves(cx: &mut VisualTestContext) {
cx.run_until_parked();
assert!(super::writer::flush_blocking(
std::time::Duration::from_secs(5)
));
cx.run_until_parked();
}

fn notes_started(id: &str, cx: &mut VisualTestContext) -> bool {
cx.update(|_, cx| {
crate::meetings::Meetings::global(cx)
.read(cx)
.notes_state(id)
.is_some()
})
}

fn click_update_notes(cx: &mut VisualTestContext) {
let action = cx
.debug_bounds("cap-ai-dock-action")
.expect("the transcript updated line offers Update notes");
cx.simulate_click(action.center(), gpui::Modifiers::none());
cx.run_until_parked();
}

#[gpui::test]
fn update_notes_on_the_transcript_line_asks_before_replacing_an_edited_summary(
cx: &mut TestAppContext,
) {
let (_dir, id, _pane, cx) = stale_summary(true, cx);
click_update_notes(cx);
assert!(cx.has_pending_prompt(), "Replace notes? is asked first");
cx.simulate_prompt_answer(crate::i18n::tr::common::cancel());
after_queued_saves(cx);
assert!(
!notes_started(&id, cx),
"cancelling keeps the edited summary"
);
assert!(
cx.debug_bounds("cap-ai-dock-action").is_some(),
"cancelling keeps the reminder to update the notes"
);
}

#[gpui::test]
fn update_notes_on_the_transcript_line_replaces_an_edited_summary_once_confirmed(
cx: &mut TestAppContext,
) {
let (_dir, id, _pane, cx) = stale_summary(true, cx);
click_update_notes(cx);
assert!(cx.has_pending_prompt(), "Replace notes? is asked first");
cx.simulate_prompt_answer(crate::i18n::tr::documents::confirm::replace());
after_queued_saves(cx);
assert!(notes_started(&id, cx), "confirming writes new notes");
}

#[gpui::test]
fn update_notes_on_the_transcript_line_still_writes_an_unedited_summary(cx: &mut TestAppContext) {
let (_dir, id, _pane, cx) = stale_summary(false, cx);
click_update_notes(cx);
assert!(!cx.has_pending_prompt(), "nothing to ask about");
after_queued_saves(cx);
assert!(notes_started(&id, cx), "Update notes writes new notes");
}
Loading