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:
hauke
2026-11-06 09:38:55 +01:00
co-authored by Claude Opus 5.5
parent cfde9690b2
commit d1658f5d9e
15 changed files with 1391 additions and 15 deletions
+162 -8
View File
@@ -16,10 +16,12 @@ use std::thread;
use std::time::{Duration, Instant};
use chrono::{DateTime, Local};
use recorder_core::accounts;
use recorder_core::call_view::{self, CallDetail, CallListItem};
use recorder_core::capture::{CaptureSource, OutputTarget};
use recorder_core::detect::{CallDetector, DetectorEvent, MicSession};
use recorder_core::http::{HttpTransport, ReqwestTransport};
use recorder_core::model::{Call, CallId, CallStatus};
use recorder_core::model::{Call, CallId, CallStatus, Speaker};
use recorder_core::recorder::Recorder;
use recorder_core::secrets::SecretStore;
use recorder_core::settings::Settings;
@@ -105,9 +107,7 @@ impl CallBrief {
app: call.app.clone(),
started_at: call.started_at,
ended_at: call.ended_at,
duration_secs: call
.ended_at
.map_or(0, |end| (end - call.started_at).num_seconds().max(0)),
duration_secs: call_view::duration_secs(call),
}
}
}
@@ -416,12 +416,55 @@ impl AppState {
}
pub fn call_brief(&self, id: CallId) -> Result<CallBrief, String> {
let call = self
.store
Ok(CallBrief::of(&self.find_call(id)?))
}
/// All calls for the main window's list, newest first.
pub fn call_list(&self) -> Result<Vec<CallListItem>, String> {
let calls = self.store.list_calls().map_err(|e| e.to_string())?;
Ok(calls.iter().map(CallListItem::of).collect())
}
/// The selected call with its transcript and speaker names.
pub fn call_detail(&self, id: CallId) -> Result<CallDetail, String> {
let call = self.find_call(id)?;
let segments = self.store.segments(id).map_err(|e| e.to_string())?;
let names = self.store.speaker_names(id).map_err(|e| e.to_string())?;
Ok(CallDetail::of(&call, &segments, names))
}
/// Renames a speaker of call `id`; a blank `name` restores the default
/// label ("Ich", "Sprecher N").
pub fn rename_speaker(&self, id: CallId, speaker_key: &str, name: &str) -> Result<(), String> {
if Speaker::from_key(speaker_key).is_none() {
return Err(format!("Unbekannter Sprecher: {speaker_key}"));
}
self.find_call(id)?;
let name = name.trim();
let result = if name.is_empty() {
self.store.remove_speaker_name(id, speaker_key)
} else {
self.store.set_speaker_name(id, speaker_key, name)
};
result.map_err(|e| format!("Name konnte nicht gespeichert werden: {e}"))
}
/// Assigns call `id` to one of the [`accounts`], or to none.
pub fn set_account(&self, id: CallId, account_id: Option<&str>) -> Result<(), String> {
if account_id.is_some_and(|account| !accounts::exists(account)) {
return Err("Unbekannter Kunde".to_string());
}
self.find_call(id)?;
self.store
.set_account(id, account_id)
.map_err(|e| format!("Kunde konnte nicht gespeichert werden: {e}"))
}
fn find_call(&self, id: CallId) -> Result<Call, String> {
self.store
.get_call(id)
.map_err(|e| e.to_string())?
.ok_or_else(|| "Gespräch nicht gefunden".to_string())?;
Ok(CallBrief::of(&call))
.ok_or_else(|| "Gespräch nicht gefunden".to_string())
}
/// Deletes a finished call: both audio files and the row, and takes it
@@ -595,6 +638,7 @@ fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
#[cfg(test)]
mod tests {
use chrono::TimeZone;
use recorder_core::model::{Segment, Speaker};
use recorder_core::secrets::MemorySecrets;
use super::*;
@@ -895,6 +939,116 @@ mod tests {
assert!(f.state.claim_processing(recording + 1, true).is_err());
}
#[test]
fn call_list_is_newest_first_with_durations() {
let f = fixture();
let (older, _, _) = finished_call(&f, "a");
let newer = f
.state
.store
.create_call("Manuell", at(11, 0, 0), Path::new(""), Path::new(""))
.unwrap();
let list = f.state.call_list().unwrap();
let rows: Vec<_> = list
.iter()
.map(|item| (item.id, item.status, item.duration_secs))
.collect();
assert_eq!(
rows,
[
(newer, CallStatus::Recording, 0),
(older, CallStatus::AwaitingDecision, 32 * 60 + 30),
]
);
}
#[test]
fn call_detail_shows_the_transcript_with_renamed_speakers() {
let f = fixture();
let (id, _, _) = finished_call(&f, "a");
f.state
.store
.save_segments(
id,
&[
Segment {
speaker: Speaker::Me,
start: 0.0,
end: 1.5,
text: "Guten Tag.".into(),
},
Segment {
speaker: Speaker::Remote(1),
start: 2.0,
end: 3.0,
text: "Hallo.".into(),
},
],
)
.unwrap();
f.state
.rename_speaker(id, "remote:1", "Frau Probe")
.unwrap();
let detail = f.state.call_detail(id).unwrap();
assert_eq!(detail.call.item.id, id);
let labels: Vec<_> = detail.segments.iter().map(|s| s.label.as_str()).collect();
assert_eq!(labels, ["Ich", "Frau Probe"]);
assert!(f.state.call_detail(id + 1).is_err());
}
#[test]
fn renaming_a_speaker_trims_and_an_empty_name_restores_the_default() {
let f = fixture();
let (id, _, _) = finished_call(&f, "a");
let names = |f: &Fixture| f.state.store.speaker_names(id).unwrap();
f.state
.rename_speaker(id, "remote:2", " Herr Test ")
.unwrap();
assert_eq!(
names(&f).get("remote:2").map(String::as_str),
Some("Herr Test")
);
f.state.rename_speaker(id, "remote:2", " ").unwrap();
assert!(names(&f).is_empty());
}
#[test]
fn renaming_needs_a_known_speaker_and_call() {
let f = fixture();
let (id, _, _) = finished_call(&f, "a");
assert!(f.state.rename_speaker(id, "remote:x", "Name").is_err());
assert!(f.state.rename_speaker(id + 1, "me", "Name").is_err());
assert!(f.state.store.speaker_names(id).unwrap().is_empty());
}
#[test]
fn the_account_is_set_and_cleared() {
let f = fixture();
let (id, _, _) = finished_call(&f, "a");
let account = |f: &Fixture| f.state.store.get_call(id).unwrap().unwrap().account_id;
f.state.set_account(id, Some("mock-2")).unwrap();
assert_eq!(account(&f).as_deref(), Some("mock-2"));
f.state.set_account(id, None).unwrap();
assert_eq!(account(&f), None);
}
#[test]
fn only_known_accounts_and_calls_are_assigned() {
let f = fixture();
let (id, _, _) = finished_call(&f, "a");
assert!(f.state.set_account(id, Some("mock-99")).is_err());
assert!(f.state.set_account(id + 1, Some("mock-1")).is_err());
assert_eq!(
f.state.store.get_call(id).unwrap().unwrap().account_id,
None
);
}
#[test]
fn invalid_detection_delays_are_not_saved() {
let f = fixture();