From babed18af07b06d713b05aed0950f319fa5f2dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sun, 28 Apr 2024 20:20:29 +0200 Subject: [PATCH] Added hashset uniqueid mail check to prevent gmail unread folder items to be removed on next item selection. --- Wino.Core/Services/MailService.cs | 4 +-- Wino.Mail.ViewModels/MailListPageViewModel.cs | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Wino.Core/Services/MailService.cs b/Wino.Core/Services/MailService.cs index 662fb15b..7cc0bf63 100644 --- a/Wino.Core/Services/MailService.cs +++ b/Wino.Core/Services/MailService.cs @@ -394,9 +394,7 @@ namespace Wino.Core.Services await Connection.DeleteAsync(mailCopy).ConfigureAwait(false); - // Update UI except unread folder to prevent automatic navigation to the next mail. - if (mailCopy.AssignedFolder.SpecialFolderType != SpecialFolderType.Unread) - ReportUIChange(new MailRemovedMessage(mailCopy)); + ReportUIChange(new MailRemovedMessage(mailCopy)); } #endregion diff --git a/Wino.Mail.ViewModels/MailListPageViewModel.cs b/Wino.Mail.ViewModels/MailListPageViewModel.cs index 8fd1f0cf..fe466afe 100644 --- a/Wino.Mail.ViewModels/MailListPageViewModel.cs +++ b/Wino.Mail.ViewModels/MailListPageViewModel.cs @@ -45,6 +45,14 @@ namespace Wino.Mail.ViewModels private Guid? trackingSynchronizationId = null; private int completedTrackingSynchronizationCount = 0; + /* [Bug] Unread folder reads All emails automatically with setting "Mark as Read: When Selected" enabled + * https://github.com/bkaankose/Wino-Mail/issues/162 + * We store the UniqueIds of the mails that are marked as read in Gmail Unread folder + * to prevent them from being removed from the list when they are marked as read. + */ + + private HashSet gmailUnreadFolderMarkedAsReadUniqueIds = new HashSet(); + private IObservable> selectionChangedObservable = null; public WinoMailCollection MailCollection { get; } = new WinoMailCollection(); @@ -210,9 +218,9 @@ namespace Wino.Mail.ViewModels _activeMailItem = selectedMailItemViewModel; - Messenger.Send(new ActiveMailItemChangedEvent(selectedMailItemViewModel)); + Messenger.Send(new ActiveMailItemChangedEvent(_activeMailItem)); - if (selectedMailItemViewModel == null) return; + if (_activeMailItem == null || _activeMailItem.IsRead) return; // Automatically set mark as read or not based on preferences. @@ -220,13 +228,16 @@ namespace Wino.Mail.ViewModels if (markAsPreference == MailMarkAsOption.WhenSelected) { - if (selectedMailItemViewModel != null && !selectedMailItemViewModel.IsRead) - { - var operation = MailOperation.MarkAsRead; - var package = new MailOperationPreperationRequest(operation,_activeMailItem.MailCopy); + var operation = MailOperation.MarkAsRead; + var package = new MailOperationPreperationRequest(operation, _activeMailItem.MailCopy); - await ExecuteMailOperationAsync(package); + if (ActiveFolder?.SpecialFolderType == SpecialFolderType.Unread && + !gmailUnreadFolderMarkedAsReadUniqueIds.Contains(_activeMailItem.UniqueId)) + { + gmailUnreadFolderMarkedAsReadUniqueIds.Add(_activeMailItem.UniqueId); } + + await ExecuteMailOperationAsync(package); } else if (markAsPreference == MailMarkAsOption.AfterDelay && PreferencesService.MarkAsDelay >= 0) { @@ -558,13 +569,17 @@ namespace Wino.Mail.ViewModels // We should delete the items only if: // 1. They are deleted from the active folder. // 2. Deleted from draft or sent folder. + // 3. Removal is not caused by Gmail Unread folder action. // Delete/sent are special folders that can list their items in other folders. bool removedFromActiveFolder = ActiveFolder.HandlingFolders.Any(a => a.Id == removedMail.AssignedFolder.Id); bool removedFromDraftOrSent = removedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Draft || removedMail.AssignedFolder.SpecialFolderType == SpecialFolderType.Sent; - if (removedFromActiveFolder || removedFromDraftOrSent) + bool isDeletedByGmailUnreadFolderAction = ActiveFolder.SpecialFolderType == SpecialFolderType.Unread && + gmailUnreadFolderMarkedAsReadUniqueIds.Contains(removedMail.UniqueId); + + if ((removedFromActiveFolder || removedFromDraftOrSent) && !isDeletedByGmailUnreadFolderAction) { bool isDeletedMailSelected = SelectedItems.Any(a => a.MailCopy.UniqueId == removedMail.UniqueId); @@ -801,6 +816,7 @@ namespace Wino.Mail.ViewModels isChangingFolder = true; ActiveFolder = message.BaseFolderMenuItem; + gmailUnreadFolderMarkedAsReadUniqueIds.Clear(); trackingSynchronizationId = null; completedTrackingSynchronizationCount = 0;