mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 15:18:00 +00:00
Ask the delete confirmation in only one place
This commit is contained in:
1 file changed
+23
-23
@@ -704,37 +704,35 @@ public partial class Workspaces : MSGComponentBase
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteChatAsync(string? chatPath, bool askForConfirmation = true, bool unloadChat = true)
|
/// <summary>Deletes the given chat and updates the tree, asking the user to confirm that beforehand.</summary>
|
||||||
|
/// <param name="chatPath">Path of the chat to delete.</param>
|
||||||
|
/// <param name="askForConfirmation">False skips the question. Only for callers who already asked.</param>
|
||||||
|
/// <param name="unloadChat">Whether to take the chat out of the view when it is the one being shown.</param>
|
||||||
|
/// <returns>True when the chat is gone, which includes it never having been there. False when it is still there.</returns>
|
||||||
|
/// <remarks>
|
||||||
|
/// The question itself comes from the workspace behaviour, so that it is worded in one place only.
|
||||||
|
/// Callers who do more than deleting have to honor the return value: a chat that is busy is not
|
||||||
|
/// deleted either, and then nothing about it may be reset.
|
||||||
|
/// </remarks>
|
||||||
|
public async Task<bool> DeleteChatAsync(string? chatPath, bool askForConfirmation = true, bool unloadChat = true)
|
||||||
{
|
{
|
||||||
var chat = await this.LoadChatAsync(chatPath, false);
|
var chat = await this.LoadChatAsync(chatPath, false);
|
||||||
|
|
||||||
|
// There is nothing left to delete, so the caller may go on:
|
||||||
if (chat is null)
|
if (chat is null)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Deleting a chat while it is being worked on would pull the ground from under that work.
|
||||||
|
// We check before asking: nobody should confirm something that cannot happen anyway.
|
||||||
|
//
|
||||||
var mediaOwner = MediaImportOwner.ForChat(chat.ChatId);
|
var mediaOwner = MediaImportOwner.ForChat(chat.ChatId);
|
||||||
if (this.AIJobService.IsChatGenerationActive(chat.ChatId) || this.MediaTranscriptionService.IsBusy(mediaOwner))
|
if (this.AIJobService.IsChatGenerationActive(chat.ChatId) || this.MediaTranscriptionService.IsBusy(mediaOwner))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (askForConfirmation)
|
if (!await WorkspaceBehaviour.DeleteChatAsync(this.DialogService, chat.WorkspaceId, chat.ChatId, askForConfirmation))
|
||||||
{
|
return false;
|
||||||
var workspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(chat.WorkspaceId);
|
|
||||||
var dialogParameters = new DialogParameters<ConfirmDialog>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
x => x.Message, (chat.WorkspaceId == Guid.Empty) switch
|
|
||||||
{
|
|
||||||
true => string.Format(T("Are you sure you want to delete the temporary chat '{0}'?"), chat.Name),
|
|
||||||
false => string.Format(T("Are you sure you want to delete the chat '{0}' in the workspace '{1}'?"), chat.Name, workspaceName),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>(T("Delete Chat"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
||||||
var dialogResult = await dialogReference.Result;
|
|
||||||
if (dialogResult is null || dialogResult.Canceled)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await WorkspaceBehaviour.DeleteChatAsync(this.DialogService, chat.WorkspaceId, chat.ChatId, askForConfirmation: false);
|
|
||||||
this.MediaTranscriptionService.ClearOwnerState(mediaOwner);
|
this.MediaTranscriptionService.ClearOwnerState(mediaOwner);
|
||||||
await this.LoadTreeItemsAsync(startPrefetch: false);
|
await this.LoadTreeItemsAsync(startPrefetch: false);
|
||||||
|
|
||||||
@@ -743,6 +741,8 @@ public partial class Workspaces : MSGComponentBase
|
|||||||
this.CurrentChatThread = null;
|
this.CurrentChatThread = null;
|
||||||
await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread);
|
await this.CurrentChatThreadChanged.InvokeAsync(this.CurrentChatThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RenameChatAsync(string? chatPath)
|
private async Task RenameChatAsync(string? chatPath)
|
||||||
|
|||||||
Reference in new issue
Block a user