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:
@@ -8,6 +8,8 @@
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use recorder_core::accounts::{self, Account};
|
||||
use recorder_core::call_view::{CallDetail, CallListItem};
|
||||
use recorder_core::capture::Devices;
|
||||
use recorder_core::model::CallId;
|
||||
use recorder_core::secrets::Service;
|
||||
@@ -118,6 +120,47 @@ pub fn get_call_brief(state: State<'_, AppState>, id: CallId) -> CmdResult<CallB
|
||||
state.call_brief(id)
|
||||
}
|
||||
|
||||
/// The main window's call list, newest first.
|
||||
#[tauri::command]
|
||||
pub fn list_calls(state: State<'_, AppState>) -> CmdResult<Vec<CallListItem>> {
|
||||
state.call_list()
|
||||
}
|
||||
|
||||
/// The selected call with its transcript.
|
||||
#[tauri::command]
|
||||
pub fn get_call(state: State<'_, AppState>, id: CallId) -> CmdResult<CallDetail> {
|
||||
state.call_detail(id)
|
||||
}
|
||||
|
||||
/// Renames a speaker of a call (an empty name restores the default label).
|
||||
#[tauri::command]
|
||||
pub fn rename_speaker(
|
||||
app: AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
id: CallId,
|
||||
speaker_key: String,
|
||||
name: String,
|
||||
) -> CmdResult<()> {
|
||||
state.rename_speaker(id, &speaker_key, &name)?;
|
||||
processing::emit_updated(&app, id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_accounts() -> Vec<Account> {
|
||||
accounts::list()
|
||||
}
|
||||
|
||||
/// Assigns a call to a customer account, or to none.
|
||||
#[tauri::command]
|
||||
pub fn set_account(
|
||||
state: State<'_, AppState>,
|
||||
id: CallId,
|
||||
account_id: Option<String>,
|
||||
) -> CmdResult<()> {
|
||||
state.set_account(id, account_id.as_deref())
|
||||
}
|
||||
|
||||
/// Deletes a finished call's audio and row. Closes the prompt if no call
|
||||
/// waits for it any more; otherwise the prompt reloads and shows the next.
|
||||
/// While its DeepScript jobs are still on record, nothing is deleted and a
|
||||
|
||||
@@ -104,6 +104,11 @@ pub fn run() {
|
||||
commands::discard_call,
|
||||
commands::transcribe_call,
|
||||
commands::retry_call,
|
||||
commands::list_calls,
|
||||
commands::get_call,
|
||||
commands::rename_speaker,
|
||||
commands::list_accounts,
|
||||
commands::set_account,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
|
||||
@@ -165,7 +165,8 @@ fn deepscript_key(state: &AppState) -> Option<String> {
|
||||
.filter(|key| !key.trim().is_empty())
|
||||
}
|
||||
|
||||
fn emit_updated(app: &AppHandle, id: CallId) {
|
||||
/// Tells the UI that call `id` changed (`call-updated`).
|
||||
pub fn emit_updated(app: &AppHandle, id: CallId) {
|
||||
if let Err(e) = app.emit("call-updated", CallUpdated { id }) {
|
||||
log::error!("could not emit call-updated: {e}");
|
||||
}
|
||||
|
||||
+162
-8
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user