Files
Wino-Mail/Wino.Core/Requests/CreateDraftRequest.cs
Tiktack f408f59beb Improve mailto links handling (#310)
* Refactor draft creation

* try scoped namespace

* Refactor mailto protocol and revert namespaces

* Remove useless account query

* Fix typo and CC/BCC in replies

* Replace convert with existing extension

* Small fixes

* Fix CC/Bcc in replies to automatically show if needed.

* Fixed body parameter position from mailto parameters

* Fixed issue with ReplyAll self not removed
2024-08-10 14:33:02 +02:00

54 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using MoreLinq;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.Domain.Models.Requests;
using Wino.Messaging.UI;
namespace Wino.Core.Requests
{
public record CreateDraftRequest(DraftPreparationRequest DraftPreperationRequest)
: RequestBase<BatchCreateDraftRequest>(DraftPreperationRequest.CreatedLocalDraftCopy, MailSynchronizerOperation.CreateDraft),
ICustomFolderSynchronizationRequest
{
public List<Guid> SynchronizationFolderIds =>
[
DraftPreperationRequest.CreatedLocalDraftCopy.AssignedFolder.Id
];
public override IBatchChangeRequest CreateBatch(IEnumerable<IRequest> matchingItems)
=> new BatchCreateDraftRequest(matchingItems, DraftPreperationRequest);
public override void ApplyUIChanges()
{
// No need for it since Draft folder is automatically navigated and draft item is added + selected.
// We only need to revert changes in case of network fails to create the draft.
}
public override void RevertUIChanges()
{
WeakReferenceMessenger.Default.Send(new MailRemovedMessage(Item));
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public record class BatchCreateDraftRequest(IEnumerable<IRequest> Items, DraftPreparationRequest DraftPreperationRequest)
: BatchRequestBase(Items, MailSynchronizerOperation.CreateDraft)
{
public override void ApplyUIChanges()
{
// No need for it since Draft folder is automatically navigated and draft item is added + selected.
// We only need to revert changes in case of network fails to create the draft.
}
public override void RevertUIChanges()
{
Items.ForEach(item => WeakReferenceMessenger.Default.Send(new MailRemovedMessage(item.Item)));
}
}
}