feat #14740: done only once uploaded
A done call only shows "fertig" once its transcript reached this build's backend (uploaded_here); otherwise it's "bereit zum Hochladen". The list row gets a blue dot for anything needing action (ready to upload or not transcribed yet), and the sidebar header shows "Gespräche · N offen". Adds ListState/needs_action to CallListItem, computed in recorder-core so the UI doesn't re-implement the rule. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,15 @@ pub struct CallListItem {
|
||||
/// Whole seconds from start to end; 0 while recording.
|
||||
pub duration_secs: i64,
|
||||
pub status: CallStatus,
|
||||
/// What the status pill shows and whether the row needs the user's
|
||||
/// attention — see [`ListState`]. Computed from `status` and
|
||||
/// [`uploaded_here`] so the UI does not re-implement the rule.
|
||||
pub list_state: ListState,
|
||||
/// Whether this row needs the user to act on it (the dot in
|
||||
/// `CallList.svelte` and the sidebar header's "N offen" count). Equal
|
||||
/// to `list_state.needs_action()`, kept as its own field so the UI
|
||||
/// does not need to know `ListState`'s variants to filter by it.
|
||||
pub needs_action: bool,
|
||||
pub interrupted: bool,
|
||||
/// The name the user gave the call, if any.
|
||||
pub title: Option<String>,
|
||||
@@ -35,12 +44,15 @@ impl CallListItem {
|
||||
/// row. Nothing is deleted; the fields are just not shown as set.
|
||||
pub fn of(call: &Call, backend_url: &str) -> Self {
|
||||
let uploaded = uploaded_here(call, backend_url);
|
||||
let list_state = ListState::of(call.status, uploaded);
|
||||
Self {
|
||||
id: call.id,
|
||||
app: call.app.clone(),
|
||||
started_at: call.started_at,
|
||||
duration_secs: duration_secs(call),
|
||||
status: call.status,
|
||||
list_state,
|
||||
needs_action: list_state.needs_action(),
|
||||
interrupted: call.interrupted,
|
||||
title: call.title.clone(),
|
||||
crm_transcript_id: if uploaded {
|
||||
@@ -53,6 +65,45 @@ impl CallListItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the call list row (and the detail header's pill) shows about a
|
||||
/// call's status. Mirrors [`CallStatus`] one-to-one, except that `Done`
|
||||
/// splits in two: a call is only ever shown as done ("fertig") once its
|
||||
/// transcript has actually reached *this build's* backend ([`uploaded_here`]);
|
||||
/// otherwise — never uploaded, or uploaded to a different backend — it is
|
||||
/// `ReadyToUpload` ("bereit zum Hochladen"), because from this build's
|
||||
/// point of view the CRM has not seen it yet.
|
||||
#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ListState {
|
||||
Recording,
|
||||
AwaitingDecision,
|
||||
Processing,
|
||||
Failed,
|
||||
Done,
|
||||
ReadyToUpload,
|
||||
}
|
||||
|
||||
impl ListState {
|
||||
fn of(status: CallStatus, uploaded_here: bool) -> Self {
|
||||
match status {
|
||||
CallStatus::Recording => ListState::Recording,
|
||||
CallStatus::AwaitingDecision => ListState::AwaitingDecision,
|
||||
CallStatus::Processing => ListState::Processing,
|
||||
CallStatus::Failed => ListState::Failed,
|
||||
CallStatus::Done if uploaded_here => ListState::Done,
|
||||
CallStatus::Done => ListState::ReadyToUpload,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a row in this state needs the user to act on it: not yet
|
||||
/// transcribed, or transcribed but not uploaded here. Excludes
|
||||
/// `Failed` (already shown in red) and the transient
|
||||
/// `Recording`/`Processing` states.
|
||||
pub fn needs_action(self) -> bool {
|
||||
matches!(self, ListState::AwaitingDecision | ListState::ReadyToUpload)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
@@ -318,6 +369,8 @@ mod tests {
|
||||
started_at: at(10, 14, 0),
|
||||
duration_secs: 60,
|
||||
status: CallStatus::AwaitingDecision,
|
||||
list_state: ListState::AwaitingDecision,
|
||||
needs_action: true,
|
||||
interrupted: true,
|
||||
title: None,
|
||||
crm_transcript_id: None,
|
||||
@@ -351,6 +404,64 @@ mod tests {
|
||||
assert!(uploaded_here(&c, BACKEND));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn done_is_fertig_only_once_uploaded_to_this_backend() {
|
||||
let mut c = call(Some(at(10, 15, 0)));
|
||||
c.status = CallStatus::Done;
|
||||
|
||||
// Never uploaded.
|
||||
assert_eq!(
|
||||
CallListItem::of(&c, BACKEND).list_state,
|
||||
ListState::ReadyToUpload
|
||||
);
|
||||
|
||||
// Uploaded, but to a different backend.
|
||||
c.crm_transcript_id = Some("4711".into());
|
||||
c.crm_base_url = Some(OTHER_BACKEND.into());
|
||||
assert_eq!(
|
||||
CallListItem::of(&c, BACKEND).list_state,
|
||||
ListState::ReadyToUpload
|
||||
);
|
||||
|
||||
// Uploaded to this build's backend.
|
||||
c.crm_base_url = Some(BACKEND.into());
|
||||
assert_eq!(CallListItem::of(&c, BACKEND).list_state, ListState::Done);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn needs_action_marks_awaiting_and_ready_to_upload_only() {
|
||||
let mut c = call(Some(at(10, 15, 0)));
|
||||
|
||||
c.status = CallStatus::AwaitingDecision;
|
||||
assert!(CallListItem::of(&c, BACKEND).needs_action, "awaiting");
|
||||
|
||||
c.status = CallStatus::Done;
|
||||
assert!(
|
||||
CallListItem::of(&c, BACKEND).needs_action,
|
||||
"done, never uploaded"
|
||||
);
|
||||
|
||||
for status in [
|
||||
CallStatus::Processing,
|
||||
CallStatus::Failed,
|
||||
CallStatus::Recording,
|
||||
] {
|
||||
c.status = status;
|
||||
assert!(
|
||||
!CallListItem::of(&c, BACKEND).needs_action,
|
||||
"{status:?} must not show the dot"
|
||||
);
|
||||
}
|
||||
|
||||
c.status = CallStatus::Done;
|
||||
c.crm_transcript_id = Some("4711".into());
|
||||
c.crm_base_url = Some(BACKEND.into());
|
||||
assert!(
|
||||
!CallListItem::of(&c, BACKEND).needs_action,
|
||||
"done and uploaded here"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_upload_to_another_backend_is_hidden_from_the_list_item() {
|
||||
// Uploaded to OTHER_BACKEND; this build's backend is BACKEND: the
|
||||
@@ -503,6 +614,8 @@ mod tests {
|
||||
"started_at": serde_json::to_value(at(10, 14, 0)).unwrap(),
|
||||
"duration_secs": 60,
|
||||
"status": "failed",
|
||||
"list_state": "failed",
|
||||
"needs_action": false,
|
||||
"interrupted": false,
|
||||
"title": "Reklamation",
|
||||
"crm_transcript_id": null,
|
||||
|
||||
Reference in New Issue
Block a user