From 36cefaab5fe372cdbd5a6885961699c6fbd04ead Mon Sep 17 00:00:00 2001 From: hauke Date: Mon, 9 Nov 2026 14:45:17 +0100 Subject: [PATCH] feat #14740: delete transcribed calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transcribed (Done) calls get a "Löschen" button next to the upload control, with a confirmation dialog in the app's style instead of window.confirm. Deleting reuses discard_call (not a parallel path), which now also refuses while the call's transcript is being uploaded, consistent with the existing refusals for recording/processing/ CleanupPending. Co-Authored-By: Claude Opus 5.5 (1M context) --- src-tauri/src/state.rs | 83 +++++++++++++++++++--- ui/src/routes/Main.svelte | 144 +++++++++++++++++++++++++++++++++++--- 2 files changed, 211 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index c2f73c3..288f45b 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -37,6 +37,7 @@ const MANUAL_APP: &str = "Manuell"; const TEST_DURATION: Duration = Duration::from_secs(5); const TEST_POLL: Duration = Duration::from_millis(50); const ALREADY_PROCESSING: &str = "Wird bereits verarbeitet"; +const ALREADY_UPLOADING: &str = "Wird bereits hochgeladen"; /// Why [`AppState::discard_call`] refused. #[derive(Debug, Clone, PartialEq)] @@ -362,7 +363,7 @@ impl AppState { pub fn claim_upload(&self, id: CallId) -> Result, String> { let mut uploading = lock(&self.uploading); if uploading.contains(&id) { - return Err("Wird bereits hochgeladen".to_string()); + return Err(ALREADY_UPLOADING.to_string()); } if lock(&self.upload_confirmed_unsaved).contains(&id) { return Err("Bereits hochgeladen".to_string()); @@ -712,11 +713,15 @@ impl AppState { .ok_or_else(|| "Gespräch nicht gefunden".to_string()) } - /// Deletes a finished call: both audio files and the row, and takes it - /// out of the prompt queue. Returns how many calls still wait for the - /// prompt. A call that is being processed, or whose DeepScript jobs - /// are still on record ([`DiscardError::CleanupPending`]), is not - /// deleted. + /// Deletes a finished (or still undecided/failed) call: both audio files + /// and the row, cascading to its segments, speaker names, merges and + /// recorded remote jobs — this is also how a transcribed (`Done`) call's + /// "Löschen" removes it. Takes it out of the prompt queue and returns how + /// many calls still wait for it. Refused while the call is being + /// recorded, processed ([`AppState::claim_processing`]/ + /// [`AppState::reserve_processing`] or status `Processing`), uploaded + /// ([`AppState::claim_upload`]), or while its DeepScript jobs are still + /// on record ([`DiscardError::CleanupPending`]). pub fn discard_call(&self, id: CallId) -> Result { if lock(&self.current) .as_ref() @@ -724,11 +729,17 @@ impl AppState { { return Err("Das Gespräch wird gerade aufgenommen".to_string().into()); } - // Held until the call is gone, so no run can claim it meanwhile. + // Both held until the call is gone, so neither a pipeline run nor an + // upload can claim it meanwhile (same uploading -> store lock order + // as `claim_upload`, so this can never deadlock against it). let processing = lock(&self.processing); if processing.contains(&id) { return Err(ALREADY_PROCESSING.to_string().into()); } + let uploading = lock(&self.uploading); + if uploading.contains(&id) { + return Err(ALREADY_UPLOADING.to_string().into()); + } let call = self .store .get_call(id) @@ -742,7 +753,8 @@ impl AppState { return Err(DiscardError::CleanupPending); } // Files first: if one cannot be deleted, the row stays so the user - // can try again instead of leaving orphaned audio behind. + // can try again instead of leaving orphaned audio behind. Already + // gone (e.g. removed by retention) is not an error. for path in [&call.mic_path, &call.out_path] { if path.as_os_str().is_empty() { continue; @@ -768,6 +780,7 @@ impl AppState { } return Err(format!("Gespräch konnte nicht gelöscht werden: {e}").into()); } + drop(uploading); drop(processing); Ok(self.prompts_waiting()) } @@ -1147,6 +1160,60 @@ mod tests { assert!(f.state.reserve_processing(id)); } + #[test] + fn a_transcribed_call_is_deleted_like_any_other() { + let f = fixture(); + let (id, mic, out) = finished_call(&f, "a"); + f.state + .store + .set_status(id, CallStatus::Done, None) + .unwrap(); + + assert_eq!(f.state.discard_call(id), Ok(0)); + assert!(!mic.exists()); + assert!(!out.exists()); + assert_eq!(f.state.store.get_call(id).unwrap(), None); + } + + #[test] + fn a_call_being_uploaded_is_not_discarded() { + let f = fixture(); + let (id, mic, out) = finished_call(&f, "a"); + f.state + .store + .set_status(id, CallStatus::Done, None) + .unwrap(); + let claim = f.state.claim_upload(id).unwrap(); + + assert_eq!( + f.state.discard_call(id), + Err(DiscardError::Other("Wird bereits hochgeladen".to_string())) + ); + assert!(mic.exists()); + assert!(out.exists()); + assert!(f.state.store.get_call(id).unwrap().is_some()); + + // Once the upload is done, the delete goes through. + drop(claim); + assert_eq!(f.state.discard_call(id), Ok(0)); + } + + #[test] + fn a_call_already_uploaded_here_is_deleted_without_touching_the_crm() { + let f = fixture(); + let (id, mic, out) = finished_call(&f, "a"); + f.state + .store + .set_status(id, CallStatus::Done, None) + .unwrap(); + f.state.mark_uploaded(id, "4711").unwrap(); + + assert_eq!(f.state.discard_call(id), Ok(0)); + assert!(!mic.exists()); + assert!(!out.exists()); + assert_eq!(f.state.store.get_call(id).unwrap(), None); + } + #[test] fn a_cleanup_reserves_a_call_of_any_status() { let f = fixture(); diff --git a/ui/src/routes/Main.svelte b/ui/src/routes/Main.svelte index 55e1356..421ca8a 100644 --- a/ui/src/routes/Main.svelte +++ b/ui/src/routes/Main.svelte @@ -45,6 +45,12 @@ let actionError = $state('') let busy = $state(false) + // "Löschen" (transcribed calls): confirmed with a dialog instead of + // running straight away like the other actions. + let deleteDialogOpen = $state(false) + let deleteBusy = $state(false) + let deleteError = $state('') + // Uploads run per call and may outlive the selection (the login can // take a while); their errors are kept per call too. let uploading = $state([]) @@ -105,6 +111,8 @@ actionError = '' editingTitle = false titleError = '' + deleteDialogOpen = false + deleteError = '' refreshDetail() } @@ -115,6 +123,8 @@ actionError = '' editingTitle = false titleError = '' + deleteDialogOpen = false + deleteError = '' } onMount(() => { @@ -189,6 +199,49 @@ refreshList() }) + /** "Löschen" on a transcribed call: asks for confirmation first. */ + function askDelete() { + deleteError = '' + deleteDialogOpen = true + } + + function cancelDelete() { + deleteDialogOpen = false + deleteError = '' + } + + /** Confirmed delete: same backend path as "Verwerfen" (`discard_call`). + * On success the selection moves to the next call in the list, or clears + * if none is left. */ + async function confirmDelete() { + if (!detail) return + const id = detail.call.id + deleteBusy = true + try { + await discardCall(id) + deleteDialogOpen = false + selectAfterDelete(id) + refreshList() + } catch (err) { + deleteError = errorText(err) + } finally { + deleteBusy = false + } + } + + /** Selects the call that took `deletedId`'s place in the list (or the one + * before it, if `deletedId` was last), else clears the selection. */ + function selectAfterDelete(deletedId: CallId) { + const index = calls.findIndex((c) => c.id === deletedId) + const remaining = calls.filter((c) => c.id !== deletedId) + if (remaining.length === 0) { + clearSelection() + return + } + const next = remaining[Math.min(Math.max(index, 0), remaining.length - 1)] + select(next.id) + } + /** Uploads the shown call's transcript (logging in first if needed). A * call already uploaded has no button any more: the CRM never gets a * duplicate. */ @@ -351,14 +404,19 @@ {:else if call.status === 'failed'} - {:else if call.status === 'done' && !call.uploaded_at} - + {/if} + {/if} @@ -397,6 +455,40 @@ /> {/if} + + {#if deleteDialogOpen} +
e.key === 'Escape' && cancelDelete()} + role="presentation" + > +
e.stopPropagation()} + onkeydown={(e) => e.stopPropagation()} + > +

Gespräch löschen?

+

Audio und Transkript werden unwiderruflich von diesem PC gelöscht.

+ {#if call.uploaded_at} +

Die Kopie im CRM bleibt erhalten.

+ {/if} + {#if deleteError} +

{deleteError}

+ {/if} +
+ + +
+
+
+ {/if} {:else if detailError}

{detailError}

{:else if loaded && selectedId === null && calls.length > 0} @@ -574,4 +666,40 @@ background: var(--rec-soft); color: var(--rec); } + + .dialog-backdrop { + position: fixed; + inset: 0; + background: rgba(29, 35, 48, 0.4); + display: flex; + align-items: center; + justify-content: center; + z-index: 10; + } + + .dialog { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 10px; + box-shadow: 0 12px 32px rgba(29, 35, 48, 0.25); + padding: 20px; + width: min(420px, calc(100vw - 32px)); + } + + .dialog-title { + font-size: 16px; + font-weight: 600; + margin: 0 0 8px; + } + + .dialog p { + margin: 0 0 8px; + } + + .dialog-actions { + display: flex; + justify-content: flex-end; + gap: 8px; + margin-top: 16px; + }