Schema v4 adds calls.crm_base_url; existing uploads are tagged with the test backend. A call counts as uploaded (list/detail fields, the "Hochgeladen am" line, the upload-once guard) only if it was uploaded to this build's backend. Uploading to the other server replaces the single upload record; nothing is deleted. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
108 lines
3.3 KiB
Rust
108 lines
3.3 KiB
Rust
//! Domain types shared by the recording pipeline, the SQLite store and the
|
|
//! Tauri command layer.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use chrono::{DateTime, Local};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Primary key of a `calls` row (SQLite `rowid`).
|
|
pub type CallId = i64;
|
|
|
|
/// Lifecycle state of a recorded call.
|
|
///
|
|
/// Serializes (and is persisted) as its lowercase snake_case name, e.g.
|
|
/// `CallStatus::AwaitingDecision` -> `"awaiting_decision"`.
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum CallStatus {
|
|
Recording,
|
|
AwaitingDecision,
|
|
Processing,
|
|
Done,
|
|
Failed,
|
|
}
|
|
|
|
/// A single recorded call and everything tracked about its lifecycle.
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
|
pub struct Call {
|
|
pub id: CallId,
|
|
pub app: String,
|
|
pub started_at: DateTime<Local>,
|
|
pub ended_at: Option<DateTime<Local>>,
|
|
pub status: CallStatus,
|
|
pub interrupted: bool,
|
|
pub error: Option<String>,
|
|
pub mic_path: PathBuf,
|
|
pub out_path: PathBuf,
|
|
pub transcribed_at: Option<DateTime<Local>>,
|
|
pub audio_deleted: bool,
|
|
/// The name the user gave the call, if any.
|
|
pub title: Option<String>,
|
|
/// The id the CRM gave the transcript at its last upload.
|
|
pub crm_transcript_id: Option<String>,
|
|
/// The backend ([`crate::backend`]'s base URL) `crm_transcript_id` was
|
|
/// uploaded to; `None` if never uploaded. A build whose own backend
|
|
/// differs (e.g. release reading a row a test build uploaded) does not
|
|
/// count this as uploaded — see `call_view::uploaded_here`.
|
|
pub crm_base_url: Option<String>,
|
|
/// When the transcript was last uploaded.
|
|
pub uploaded_at: Option<DateTime<Local>>,
|
|
}
|
|
|
|
/// A single transcribed word with its timing and speaker attribution.
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
|
pub struct Word {
|
|
pub text: String,
|
|
pub start: f64,
|
|
pub end: f64,
|
|
pub speaker: Option<String>,
|
|
}
|
|
|
|
/// Who is speaking in a segment: the local user, or one of the remote
|
|
/// participants detected via diarization.
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum Speaker {
|
|
Me,
|
|
Remote(u32),
|
|
}
|
|
|
|
impl Speaker {
|
|
/// Stable identifier used as a storage/lookup key, e.g. for
|
|
/// `Store::set_speaker_name` / `Store::speaker_names`.
|
|
pub fn key(&self) -> String {
|
|
match self {
|
|
Speaker::Me => "me".to_string(),
|
|
Speaker::Remote(n) => format!("remote:{n}"),
|
|
}
|
|
}
|
|
|
|
/// Default German display label before the user renames a speaker.
|
|
pub fn default_label(&self) -> String {
|
|
match self {
|
|
Speaker::Me => "Ich".to_string(),
|
|
Speaker::Remote(n) => format!("Sprecher {n}"),
|
|
}
|
|
}
|
|
|
|
/// Parses a key produced by [`Speaker::key`] back into a `Speaker`.
|
|
pub fn from_key(key: &str) -> Option<Self> {
|
|
if key == "me" {
|
|
Some(Speaker::Me)
|
|
} else {
|
|
key.strip_prefix("remote:")
|
|
.and_then(|n| n.parse::<u32>().ok())
|
|
.map(Speaker::Remote)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A merged, diarized stretch of transcript attributed to one speaker.
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
|
pub struct Segment {
|
|
pub speaker: Speaker,
|
|
pub start: f64,
|
|
pub end: f64,
|
|
pub text: String,
|
|
}
|