From 9e73ec88da2fc33a10c5cbd65360bdd64fa70c08 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 22 Sep 2026 16:59:51 +0200 Subject: [PATCH] Let chat deletion report whether the chat is gone --- .../Tools/WorkspaceBehaviour.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs b/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs index 068f369c..5852a332 100644 --- a/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs +++ b/app/MindWork AI Studio/Tools/WorkspaceBehaviour.cs @@ -1082,11 +1082,24 @@ public static class WorkspaceBehaviour } } - public static async Task DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true) + /// Deletes the given chat, asking the user to confirm that beforehand. + /// Used to show the confirmation. + /// Workspace that owns the chat; an empty id means a temporary chat. + /// Chat to delete. + /// False skips the question. Only for callers who already asked. + /// True when the chat is gone, which includes it never having been there. False when it is still there. + /// + /// This is the one place that asks whether a chat may be deleted, because a deleted chat cannot + /// be restored: there is no trash. Callers who do more than deleting have to honor the return + /// value, or a declined question would still take the rest of their work with it. + /// + public static async Task DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true) { var chat = await LoadChatAsync(new(workspaceId, chatId)); + + // There is nothing left to delete, so the caller may go on: if (chat is null) - return; + return true; if (askForConfirmation) { @@ -1105,7 +1118,7 @@ public static class WorkspaceBehaviour var dialogReference = await dialogService.ShowAsync(TB("Delete Chat"), dialogParameters, Dialogs.DialogOptions.FULLSCREEN); var dialogResult = await dialogReference.Result; if (dialogResult is null || dialogResult.Canceled) - return; + return false; } var chatDirectory = chat.WorkspaceId == Guid.Empty @@ -1113,8 +1126,10 @@ public static class WorkspaceBehaviour : Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString()); var (acquired, semaphore) = await TryAcquireChatSemaphoreAsync(workspaceId, chatId, nameof(DeleteChatAsync)); + + // Another operation holds the chat, so it stays where it is: if (!acquired) - return; + return false; try { @@ -1128,6 +1143,8 @@ public static class WorkspaceBehaviour semaphore.Release(); ForgetChatSemaphore(workspaceId, chatId); } + + return true; } private static async Task EnsureWorkspace(Guid workspaceId, string workspaceName)