Kept the unsent message with its chat (#1049)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-10-11 15:52:09 +02:00
1 parent 1c13300988
commit 468d28aa94
18 files changed
+1333 -240

No files matched your search

@@ -178,25 +178,13 @@ public partial class AttachDocuments : MSGComponentBase
var completed = this.EffectiveImportOwner.Kind.PersistsOwnSources()
? Array.Empty<FileAttachment>()
: delivery?.Attachments ?? [];
var pending = this.OwnerChat?.PendingMediaTranscripts ?? [];
var pending = this.OwnerChat?.Draft.MediaTranscripts ?? [];
var changed = false;
var ownerPendingChanged = false;
foreach (var attachment in completed.Concat(pending))
changed |= this.DocumentPaths.Add(attachment);
if (this.OwnerChat is not null)
{
foreach (var attachment in completed.OfType<ManagedTranscriptAttachment>())
{
if (this.OwnerChat.PendingMediaTranscripts.All(existing => existing.FilePath != attachment.FilePath))
{
this.OwnerChat.PendingMediaTranscripts.Add(attachment);
ownerPendingChanged = true;
}
}
}
var ownerPendingChanged = this.OwnerChat?.Draft.AddAttachments(completed.OfType<ManagedTranscriptAttachment>()) ?? false;
if (changed || ownerPendingChanged)
{
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
@@ -276,10 +264,11 @@ public partial class AttachDocuments : MSGComponentBase
var previousAttachments = this.DocumentPaths.ToHashSet();
this.DocumentPaths = await ReviewAttachmentsDialog.OpenDialogAsync(this.DialogService, this.DocumentPaths, this.AttachDroppedPathsAsync, () => this.IsUnavailable);
foreach (var removedAttachment in previousAttachments.Except(this.DocumentPaths))
var removedAttachments = previousAttachments.Except(this.DocumentPaths).ToList();
foreach (var removedAttachment in removedAttachments)
ManagedTranscriptAttachment.TryDeleteOwnedFile(removedAttachment);
this.ReconcileOwnerPendingTranscripts();
this.RemoveFromOwnerDraft(removedAttachments);
//
// Said out loud, like every other path in this file. Removing a file in the dialog changed
@@ -295,11 +284,12 @@ public partial class AttachDocuments : MSGComponentBase
if (this.IsUnavailable)
return;
foreach (var attachment in this.DocumentPaths)
var removedAttachments = this.DocumentPaths.ToList();
foreach (var attachment in removedAttachments)
ManagedTranscriptAttachment.TryDeleteOwnedFile(attachment);
this.DocumentPaths.Clear();
this.ReconcileOwnerPendingTranscripts();
this.RemoveFromOwnerDraft(removedAttachments);
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
await this.OnChange(this.DocumentPaths);
}
@@ -311,21 +301,22 @@ public partial class AttachDocuments : MSGComponentBase
this.DocumentPaths.Remove(fileAttachment);
ManagedTranscriptAttachment.TryDeleteOwnedFile(fileAttachment);
this.ReconcileOwnerPendingTranscripts();
this.RemoveFromOwnerDraft([fileAttachment]);
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
await this.OnChange(this.DocumentPaths);
}
/// <summary>Keeps persisted chat-draft transcript references aligned with the composer.</summary>
private void ReconcileOwnerPendingTranscripts()
{
if (this.OwnerChat is null)
return;
var retainedPaths = this.DocumentPaths.Select(attachment => attachment.FilePath).ToHashSet(StringComparer.Ordinal);
this.OwnerChat.PendingMediaTranscripts.RemoveAll(attachment => !retainedPaths.Contains(attachment.FilePath));
}
/// <summary>
/// Removes the attachments the user took out of the composer from the draft of the owner chat.
/// </summary>
/// <remarks>
/// Only what the user removed leaves the draft. The media transcription service hands a finished
/// transcript to the draft before the composer shows it, so aligning the draft with the composer
/// would drop such a transcript, and its file would stay behind without an owner.
/// </remarks>
/// <param name="removedAttachments">The attachments the user removed.</param>
private void RemoveFromOwnerDraft(IEnumerable<FileAttachment> removedAttachments) => this.OwnerChat?.Draft.RemoveAttachments(removedAttachments);
/// <summary>
/// Validates the given paths and attaches every file which passes.