Summaries are not coming to the desktop app, and the customer is chosen in the web UI after the upload: - drop the Anthropic key (Service::Anthropic, Settings field) and delete a leftover keyring entry best-effort at startup - drop the Summary model, the store's summary accessors and the "Zusammenfassung" tab; the transcript is the detail's only content - drop the mocked customer accounts, list_accounts/set_account and the "Kunde" dropdown; calls.account_id and summaries stay in the schema Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
361 lines
11 KiB
Rust
361 lines
11 KiB
Rust
//! What the main window shows about calls: the rows of the call list and
|
|
//! the detail of the selected call, shaped from the stored data.
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use chrono::{DateTime, Local};
|
|
use serde::Serialize;
|
|
|
|
use crate::merge;
|
|
use crate::model::{Call, CallId, CallStatus, Segment, Speaker};
|
|
|
|
/// A row of the call list.
|
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
|
pub struct CallListItem {
|
|
pub id: CallId,
|
|
pub app: String,
|
|
pub started_at: DateTime<Local>,
|
|
/// Whole seconds from start to end; 0 while recording.
|
|
pub duration_secs: i64,
|
|
pub status: CallStatus,
|
|
pub interrupted: bool,
|
|
/// The name the user gave the call, if any.
|
|
pub title: Option<String>,
|
|
}
|
|
|
|
impl CallListItem {
|
|
pub fn of(call: &Call) -> Self {
|
|
Self {
|
|
id: call.id,
|
|
app: call.app.clone(),
|
|
started_at: call.started_at,
|
|
duration_secs: duration_secs(call),
|
|
status: call.status,
|
|
interrupted: call.interrupted,
|
|
title: call.title.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Whole seconds from `started_at` to `ended_at`; 0 while the call has not
|
|
/// ended (and never negative).
|
|
pub fn duration_secs(call: &Call) -> i64 {
|
|
call.ended_at
|
|
.map_or(0, |end| (end - call.started_at).num_seconds().max(0))
|
|
}
|
|
|
|
/// The selected call's header data: its list row plus the error of a
|
|
/// failed run.
|
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
|
pub struct CallHeader {
|
|
#[serde(flatten)]
|
|
pub item: CallListItem,
|
|
pub error: Option<String>,
|
|
}
|
|
|
|
/// A transcript line with the speaker's display label.
|
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
|
pub struct SegmentView {
|
|
/// [`crate::model::Speaker::key`], stable across renames.
|
|
pub speaker_key: String,
|
|
pub label: String,
|
|
pub start: f64,
|
|
pub end: f64,
|
|
pub text: String,
|
|
}
|
|
|
|
/// A merged speaker: "Sprecher 2 → Frau Beispiel zusammengeführt".
|
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
|
pub struct MergeView {
|
|
pub from_key: String,
|
|
/// The source's default label: its own rename is not in effect while
|
|
/// it is merged.
|
|
pub from_label: String,
|
|
/// The speaker the source's lines now belong to (the end of a chain of
|
|
/// merges).
|
|
pub into_key: String,
|
|
pub into_label: String,
|
|
}
|
|
|
|
/// Everything the detail pane shows about one call.
|
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
|
pub struct CallDetail {
|
|
pub call: CallHeader,
|
|
/// The transcript with speaker merges applied
|
|
/// ([`merge::apply_merges`]).
|
|
pub segments: Vec<SegmentView>,
|
|
/// Renamed speakers by key; speakers not in here keep their default
|
|
/// label.
|
|
pub speaker_names: BTreeMap<String, String>,
|
|
/// The call's speaker merges, by source speaker number.
|
|
pub merges: Vec<MergeView>,
|
|
}
|
|
|
|
impl CallDetail {
|
|
/// `segments` are the stored ones; `merges` the stored speaker merges
|
|
/// (source key → target key).
|
|
pub fn of(
|
|
call: &Call,
|
|
segments: &[Segment],
|
|
speaker_names: BTreeMap<String, String>,
|
|
merges: &BTreeMap<String, String>,
|
|
) -> Self {
|
|
let segments = merge::apply_merges(segments, merges)
|
|
.iter()
|
|
.map(|segment| SegmentView {
|
|
speaker_key: segment.speaker.key(),
|
|
label: merge::label(&segment.speaker, &speaker_names),
|
|
start: segment.start,
|
|
end: segment.end,
|
|
text: segment.text.clone(),
|
|
})
|
|
.collect();
|
|
Self {
|
|
call: CallHeader {
|
|
item: CallListItem::of(call),
|
|
error: call.error.clone(),
|
|
},
|
|
segments,
|
|
merges: merge_views(merges, &speaker_names),
|
|
speaker_names,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn merge_views(
|
|
merges: &BTreeMap<String, String>,
|
|
speaker_names: &BTreeMap<String, String>,
|
|
) -> Vec<MergeView> {
|
|
let mut views: Vec<(u32, MergeView)> = merge::resolve_merges(merges)
|
|
.into_iter()
|
|
.filter_map(|(from_key, into_key)| {
|
|
let (Some(Speaker::Remote(n)), Some(into)) =
|
|
(Speaker::from_key(&from_key), Speaker::from_key(&into_key))
|
|
else {
|
|
return None;
|
|
};
|
|
let view = MergeView {
|
|
from_label: Speaker::Remote(n).default_label(),
|
|
into_label: merge::label(&into, speaker_names),
|
|
from_key,
|
|
into_key,
|
|
};
|
|
Some((n, view))
|
|
})
|
|
.collect();
|
|
views.sort_by_key(|(n, _)| *n);
|
|
views.into_iter().map(|(_, view)| view).collect()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use std::path::PathBuf;
|
|
|
|
use chrono::TimeZone;
|
|
use serde_json::json;
|
|
|
|
use super::*;
|
|
use crate::model::Speaker;
|
|
|
|
fn at(h: u32, m: u32, s: u32) -> DateTime<Local> {
|
|
Local.with_ymd_and_hms(2026, 11, 5, h, m, s).unwrap()
|
|
}
|
|
|
|
fn call(ended_at: Option<DateTime<Local>>) -> Call {
|
|
Call {
|
|
id: 7,
|
|
app: "Microsoft Teams".into(),
|
|
started_at: at(10, 14, 0),
|
|
ended_at,
|
|
status: CallStatus::Done,
|
|
interrupted: false,
|
|
error: None,
|
|
mic_path: PathBuf::from("7-mic.wav"),
|
|
out_path: PathBuf::from("7-out.wav"),
|
|
transcribed_at: None,
|
|
audio_deleted: false,
|
|
title: None,
|
|
}
|
|
}
|
|
|
|
fn segment(speaker: Speaker, start: f64, text: &str) -> Segment {
|
|
Segment {
|
|
speaker,
|
|
start,
|
|
end: start + 2.0,
|
|
text: text.into(),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn duration_runs_from_start_to_end() {
|
|
assert_eq!(duration_secs(&call(Some(at(10, 46, 30)))), 32 * 60 + 30);
|
|
}
|
|
|
|
#[test]
|
|
fn duration_is_zero_while_recording_and_never_negative() {
|
|
assert_eq!(duration_secs(&call(None)), 0);
|
|
assert_eq!(duration_secs(&call(Some(at(10, 13, 0)))), 0);
|
|
}
|
|
|
|
#[test]
|
|
fn list_item_carries_the_row_fields() {
|
|
let mut c = call(Some(at(10, 15, 0)));
|
|
c.status = CallStatus::AwaitingDecision;
|
|
c.interrupted = true;
|
|
assert_eq!(
|
|
CallListItem::of(&c),
|
|
CallListItem {
|
|
id: 7,
|
|
app: "Microsoft Teams".into(),
|
|
started_at: at(10, 14, 0),
|
|
duration_secs: 60,
|
|
status: CallStatus::AwaitingDecision,
|
|
interrupted: true,
|
|
title: None,
|
|
}
|
|
);
|
|
|
|
c.title = Some("Angebot Rioja".into());
|
|
assert_eq!(CallListItem::of(&c).title.as_deref(), Some("Angebot Rioja"));
|
|
}
|
|
|
|
#[test]
|
|
fn detail_labels_segments_with_renames_and_defaults() {
|
|
let segments = [
|
|
segment(Speaker::Me, 0.0, "Guten Tag."),
|
|
segment(Speaker::Remote(1), 2.5, "Hallo."),
|
|
segment(Speaker::Remote(2), 5.0, "Moin."),
|
|
];
|
|
let mut names = BTreeMap::new();
|
|
names.insert("remote:1".to_string(), "Frau Beispiel".to_string());
|
|
names.insert("remote:2".to_string(), " ".to_string());
|
|
|
|
let detail = CallDetail::of(
|
|
&call(Some(at(10, 15, 0))),
|
|
&segments,
|
|
names.clone(),
|
|
&BTreeMap::new(),
|
|
);
|
|
|
|
let lines: Vec<_> = detail
|
|
.segments
|
|
.iter()
|
|
.map(|s| (s.speaker_key.as_str(), s.label.as_str(), s.text.as_str()))
|
|
.collect();
|
|
assert_eq!(
|
|
lines,
|
|
[
|
|
("me", "Ich", "Guten Tag."),
|
|
("remote:1", "Frau Beispiel", "Hallo."),
|
|
("remote:2", "Sprecher 2", "Moin."),
|
|
]
|
|
);
|
|
assert_eq!(detail.segments[1].start, 2.5);
|
|
assert_eq!(detail.segments[1].end, 4.5);
|
|
assert_eq!(detail.speaker_names, names);
|
|
assert_eq!(detail.merges, []);
|
|
}
|
|
|
|
fn keys(pairs: &[(&str, &str)]) -> BTreeMap<String, String> {
|
|
pairs
|
|
.iter()
|
|
.map(|(a, b)| (a.to_string(), b.to_string()))
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn detail_shows_merged_speakers_under_their_target() {
|
|
let segments = [
|
|
segment(Speaker::Remote(1), 0.0, "Guten Tag,"),
|
|
segment(Speaker::Remote(2), 2.5, "hier Weingut Beispiel."),
|
|
segment(Speaker::Me, 5.0, "Hallo."),
|
|
segment(Speaker::Remote(3), 7.5, "Zur Lieferung:"),
|
|
segment(Speaker::Remote(4), 10.0, "Moin."),
|
|
];
|
|
let names = keys(&[("remote:1", "Frau Beispiel"), ("remote:2", "Herr Probe")]);
|
|
let merges = keys(&[
|
|
("remote:3", "remote:2"),
|
|
("remote:2", "remote:1"),
|
|
("remote:10", "remote:4"),
|
|
]);
|
|
|
|
let detail = CallDetail::of(&call(Some(at(10, 15, 0))), &segments, names, &merges);
|
|
|
|
let lines: Vec<_> = detail
|
|
.segments
|
|
.iter()
|
|
.map(|s| (s.speaker_key.as_str(), s.label.as_str(), s.text.as_str()))
|
|
.collect();
|
|
assert_eq!(
|
|
lines,
|
|
[
|
|
(
|
|
"remote:1",
|
|
"Frau Beispiel",
|
|
"Guten Tag, hier Weingut Beispiel."
|
|
),
|
|
("me", "Ich", "Hallo."),
|
|
("remote:1", "Frau Beispiel", "Zur Lieferung:"),
|
|
("remote:4", "Sprecher 4", "Moin."),
|
|
]
|
|
);
|
|
let merge_lines: Vec<_> = detail
|
|
.merges
|
|
.iter()
|
|
.map(|m| {
|
|
(
|
|
m.from_key.as_str(),
|
|
m.from_label.as_str(),
|
|
m.into_key.as_str(),
|
|
m.into_label.as_str(),
|
|
)
|
|
})
|
|
.collect();
|
|
assert_eq!(
|
|
merge_lines,
|
|
[
|
|
("remote:2", "Sprecher 2", "remote:1", "Frau Beispiel"),
|
|
("remote:3", "Sprecher 3", "remote:1", "Frau Beispiel"),
|
|
("remote:10", "Sprecher 10", "remote:4", "Sprecher 4"),
|
|
]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn detail_serializes_the_call_header_flat() {
|
|
let mut c = call(Some(at(10, 15, 0)));
|
|
c.status = CallStatus::Failed;
|
|
c.error = Some("Netzwerkfehler".into());
|
|
c.title = Some("Reklamation".into());
|
|
let merges = keys(&[("remote:2", "remote:1")]);
|
|
|
|
let value =
|
|
serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges)).unwrap();
|
|
|
|
assert_eq!(
|
|
value,
|
|
json!({
|
|
"call": {
|
|
"id": 7,
|
|
"app": "Microsoft Teams",
|
|
"started_at": serde_json::to_value(at(10, 14, 0)).unwrap(),
|
|
"duration_secs": 60,
|
|
"status": "failed",
|
|
"interrupted": false,
|
|
"title": "Reklamation",
|
|
"error": "Netzwerkfehler",
|
|
},
|
|
"segments": [],
|
|
"speaker_names": {},
|
|
"merges": [{
|
|
"from_key": "remote:2",
|
|
"from_label": "Sprecher 2",
|
|
"into_key": "remote:1",
|
|
"into_label": "Sprecher 1",
|
|
}],
|
|
})
|
|
);
|
|
}
|
|
}
|