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,82 @@
|
||||
//! Customer accounts a call can be assigned to (the "Kunde" dropdown).
|
||||
//!
|
||||
//! A static mock for now: the names are clearly fictional placeholders
|
||||
//! until the account system is connected.
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
/// A customer account. `id` is what a call stores as its `account_id`.
|
||||
#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Account {
|
||||
pub id: &'static str,
|
||||
pub name: &'static str,
|
||||
}
|
||||
|
||||
const MOCK_ACCOUNTS: [Account; 5] = [
|
||||
Account {
|
||||
id: "mock-1",
|
||||
name: "Weingut Beispiel GmbH",
|
||||
},
|
||||
Account {
|
||||
id: "mock-2",
|
||||
name: "Weinhandel Muster KG",
|
||||
},
|
||||
Account {
|
||||
id: "mock-3",
|
||||
name: "Vinothek Probe",
|
||||
},
|
||||
Account {
|
||||
id: "mock-4",
|
||||
name: "Kellerei Test eG",
|
||||
},
|
||||
Account {
|
||||
id: "mock-5",
|
||||
name: "Restaurant Platzhalter",
|
||||
},
|
||||
];
|
||||
|
||||
/// All accounts, in display order.
|
||||
pub fn list() -> Vec<Account> {
|
||||
MOCK_ACCOUNTS.to_vec()
|
||||
}
|
||||
|
||||
/// Whether `id` names one of the accounts.
|
||||
pub fn exists(id: &str) -> bool {
|
||||
MOCK_ACCOUNTS.iter().any(|account| account.id == id)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn mock_accounts_are_stable_and_unique() {
|
||||
let accounts = list();
|
||||
let names: Vec<_> = accounts.iter().map(|a| a.name).collect();
|
||||
assert_eq!(
|
||||
names,
|
||||
[
|
||||
"Weingut Beispiel GmbH",
|
||||
"Weinhandel Muster KG",
|
||||
"Vinothek Probe",
|
||||
"Kellerei Test eG",
|
||||
"Restaurant Platzhalter",
|
||||
]
|
||||
);
|
||||
let ids: HashSet<_> = accounts.iter().map(|a| a.id).collect();
|
||||
assert_eq!(ids.len(), 5);
|
||||
// Stored with the calls, so they must never change.
|
||||
assert_eq!(accounts[0].id, "mock-1");
|
||||
assert_eq!(accounts[4].id, "mock-5");
|
||||
assert_eq!(list(), accounts);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_listed_accounts_exist() {
|
||||
assert!(exists("mock-3"));
|
||||
assert!(!exists("mock-6"));
|
||||
assert!(!exists(""));
|
||||
}
|
||||
}
|
||||
@@ -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": {},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
//! transcription and summarization logic, kept independent of the Tauri
|
||||
//! application shell so it can be unit-tested without a GUI or network.
|
||||
|
||||
pub mod accounts;
|
||||
pub mod audio;
|
||||
pub mod call_view;
|
||||
pub mod capture;
|
||||
pub mod detect;
|
||||
pub mod http;
|
||||
|
||||
@@ -286,6 +286,17 @@ impl Store {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Drops the rename of `speaker_key`, so it shows its default label
|
||||
/// again. Not an error if it was never renamed.
|
||||
pub fn remove_speaker_name(&self, id: CallId, speaker_key: &str) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
"DELETE FROM speaker_names WHERE call_id = ?1 AND speaker_key = ?2",
|
||||
params![id, speaker_key],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn speaker_names(&self, id: CallId) -> Result<BTreeMap<String, String>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt =
|
||||
@@ -661,6 +672,24 @@ mod tests {
|
||||
assert_eq!(names.get("remote:1").unwrap(), "Frau Mueller");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_removed_speaker_name_is_gone() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
let id = store
|
||||
.create_call("teams.exe", Local::now(), Path::new(""), Path::new(""))
|
||||
.unwrap();
|
||||
store
|
||||
.set_speaker_name(id, "remote:1", "Frau Probe")
|
||||
.unwrap();
|
||||
store.set_speaker_name(id, "remote:2", "Herr Test").unwrap();
|
||||
|
||||
store.remove_speaker_name(id, "remote:1").unwrap();
|
||||
store.remove_speaker_name(id, "remote:3").unwrap(); // never renamed
|
||||
|
||||
let names = store.speaker_names(id).unwrap();
|
||||
assert_eq!(names.keys().collect::<Vec<_>>(), ["remote:2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_newest_first() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user