feat #14740: main window with call list and transcript
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
//! 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};
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 and the assigned account.
|
||||
#[derive(Serialize, Clone, Debug, PartialEq)]
|
||||
pub struct CallHeader {
|
||||
#[serde(flatten)]
|
||||
pub item: CallListItem,
|
||||
pub error: Option<String>,
|
||||
pub account_id: 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,
|
||||
}
|
||||
|
||||
/// Everything the detail pane shows about one call.
|
||||
#[derive(Serialize, Clone, Debug, PartialEq)]
|
||||
pub struct CallDetail {
|
||||
pub call: CallHeader,
|
||||
pub segments: Vec<SegmentView>,
|
||||
/// Renamed speakers by key; speakers not in here keep their default
|
||||
/// label.
|
||||
pub speaker_names: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl CallDetail {
|
||||
pub fn of(call: &Call, segments: &[Segment], speaker_names: BTreeMap<String, String>) -> Self {
|
||||
let segments = segments
|
||||
.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(),
|
||||
account_id: call.account_id.clone(),
|
||||
},
|
||||
segments,
|
||||
speaker_names,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
account_id: 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,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[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());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#[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.account_id = Some("mock-2".into());
|
||||
|
||||
let value = serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new())).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,
|
||||
"error": "Netzwerkfehler",
|
||||
"account_id": "mock-2",
|
||||
},
|
||||
"segments": [],
|
||||
"speaker_names": {},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user