Fix the issue where sent and draft items are added to the existing folder regardless.

This commit is contained in:
Burak Kaan Köse
2025-10-31 11:26:51 +01:00
parent 282655dca8
commit 9e74fa9578
2 changed files with 35 additions and 7 deletions
@@ -188,6 +188,16 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
return _threadIdToItemsMap[threadId].FirstOrDefault();
}
/// <summary>
/// Checks if a ThreadId exists in the collection.
/// </summary>
/// <param name="threadId">The ThreadId to check for.</param>
/// <returns>True if the ThreadId exists in the collection, false otherwise.</returns>
public bool ContainsThreadId(string threadId)
{
return !string.IsNullOrEmpty(threadId) && _threadIdToItemsMap.ContainsKey(threadId);
}
private async Task InsertItemInternalAsync(object groupKey, IMailListItem mailItem)
{
UpdateUniqueIdHashes(mailItem, true);
+25 -7
View File
@@ -603,6 +603,16 @@ public partial class MailListPageViewModel : MailBaseViewModel,
Messenger.Send(new MailRemovedMessage(fi.MailCopy));
}
/// <summary>
/// Checks if a ThreadId exists in the current mail collection.
/// </summary>
/// <param name="mailItem">The mail item to check ThreadId for.</param>
/// <returns>True if the ThreadId exists in the collection, false otherwise.</returns>
private bool ThreadIdExistsInCollection(MailCopy mailItem)
{
return MailCollection.ContainsThreadId(mailItem.ThreadId);
}
protected override async void OnMailAdded(MailCopy addedMail)
{
base.OnMailAdded(addedMail);
@@ -616,15 +626,23 @@ public partial class MailListPageViewModel : MailBaseViewModel,
// At least one of the accounts we are listing must match with the account of the added mail.
if (!ActiveFolder.HandlingFolders.Any(a => a.MailAccountId == addedMail.AssignedAccount.Id)) return;
// Messages coming to sent or draft folder must be inserted regardless of the filter.
bool shouldPreventIgnoringFilter = addedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Draft ||
addedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Sent;
// Messages coming to sent or draft folder should only be inserted if their ThreadId exists in the collection.
bool isFromDraftOrSentFolder = addedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Draft ||
addedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Sent;
// Item does not belong to this folder and doesn't have special type to be inserted.
if (!shouldPreventIgnoringFilter && !ActiveFolder.HandlingFolders.Any(a => a.Id == addedMail.AssignedFolder.Id)) return;
if (isFromDraftOrSentFolder)
{
// Only add if the ThreadId exists in the collection (can be threaded with existing items)
if (!ThreadIdExistsInCollection(addedMail)) return;
}
else
{
// Item does not belong to this folder.
if (!ActiveFolder.HandlingFolders.Any(a => a.Id == addedMail.AssignedFolder.Id)) return;
// Item should be prevented from being added to the list due to filter.
if (!shouldPreventIgnoringFilter && ShouldPreventItemAdd(addedMail)) return;
// Item should be prevented from being added to the list due to filter.
if (ShouldPreventItemAdd(addedMail)) return;
}
await listManipulationSemepahore.WaitAsync();