mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 15:53:48 +00:00
Let chat deletion report whether the chat is gone
This commit is contained in:
1 file changed
+21
-4
@@ -1082,11 +1082,24 @@ public static class WorkspaceBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true)
|
/// <summary>Deletes the given chat, asking the user to confirm that beforehand.</summary>
|
||||||
|
/// <param name="dialogService">Used to show the confirmation.</param>
|
||||||
|
/// <param name="workspaceId">Workspace that owns the chat; an empty id means a temporary chat.</param>
|
||||||
|
/// <param name="chatId">Chat to delete.</param>
|
||||||
|
/// <param name="askForConfirmation">False skips the question. Only for callers who already asked.</param>
|
||||||
|
/// <returns>True when the chat is gone, which includes it never having been there. False when it is still there.</returns>
|
||||||
|
/// <remarks>
|
||||||
|
/// 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.
|
||||||
|
/// </remarks>
|
||||||
|
public static async Task<bool> DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true)
|
||||||
{
|
{
|
||||||
var chat = await LoadChatAsync(new(workspaceId, chatId));
|
var chat = await LoadChatAsync(new(workspaceId, chatId));
|
||||||
|
|
||||||
|
// There is nothing left to delete, so the caller may go on:
|
||||||
if (chat is null)
|
if (chat is null)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
if (askForConfirmation)
|
if (askForConfirmation)
|
||||||
{
|
{
|
||||||
@@ -1105,7 +1118,7 @@ public static class WorkspaceBehaviour
|
|||||||
var dialogReference = await dialogService.ShowAsync<ConfirmDialog>(TB("Delete Chat"), dialogParameters, Dialogs.DialogOptions.FULLSCREEN);
|
var dialogReference = await dialogService.ShowAsync<ConfirmDialog>(TB("Delete Chat"), dialogParameters, Dialogs.DialogOptions.FULLSCREEN);
|
||||||
var dialogResult = await dialogReference.Result;
|
var dialogResult = await dialogReference.Result;
|
||||||
if (dialogResult is null || dialogResult.Canceled)
|
if (dialogResult is null || dialogResult.Canceled)
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var chatDirectory = chat.WorkspaceId == Guid.Empty
|
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());
|
: Path.Join(SettingsManager.DataDirectory, "workspaces", chat.WorkspaceId.ToString(), chat.ChatId.ToString());
|
||||||
|
|
||||||
var (acquired, semaphore) = await TryAcquireChatSemaphoreAsync(workspaceId, chatId, nameof(DeleteChatAsync));
|
var (acquired, semaphore) = await TryAcquireChatSemaphoreAsync(workspaceId, chatId, nameof(DeleteChatAsync));
|
||||||
|
|
||||||
|
// Another operation holds the chat, so it stays where it is:
|
||||||
if (!acquired)
|
if (!acquired)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1128,6 +1143,8 @@ public static class WorkspaceBehaviour
|
|||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
ForgetChatSemaphore(workspaceId, chatId);
|
ForgetChatSemaphore(workspaceId, chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task EnsureWorkspace(Guid workspaceId, string workspaceName)
|
private static async Task EnsureWorkspace(Guid workspaceId, string workspaceName)
|
||||||
|
|||||||
Reference in new issue
Block a user