Addressing some Outlook sending issues due to API delay.

This commit is contained in:
Burak Kaan Köse
2024-08-21 13:15:50 +02:00
parent 16feb8602d
commit 0baac3dc49
10 changed files with 133 additions and 81 deletions

View File

@@ -531,7 +531,6 @@ namespace Wino.Core.Services
if (shouldUpdateIdentifier)
{
_logger.Debug("Updating synchronization identifier for {Name}. From: {SynchronizationDeltaIdentifier} To: {NewIdentifier}", account.Name, account.SynchronizationDeltaIdentifier, newIdentifier);
account.SynchronizationDeltaIdentifier = newIdentifier;
await UpdateAccountAsync(account);

View File

@@ -558,36 +558,11 @@ namespace Wino.Core.Services
public Task<List<MailFolderPairMetadata>> GetMailFolderPairMetadatasAsync(string mailCopyId)
=> GetMailFolderPairMetadatasAsync(new List<string>() { mailCopyId });
public async Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options)
{
var folders = new List<MailItemFolder>();
if (options.Type == SynchronizationType.Inbox)
{
var inboxFolder = await GetSpecialFolderByAccountIdAsync(options.AccountId, SpecialFolderType.Inbox);
var sentFolder = await GetSpecialFolderByAccountIdAsync(options.AccountId, SpecialFolderType.Sent);
var draftFolder = await GetSpecialFolderByAccountIdAsync(options.AccountId, SpecialFolderType.Draft);
// For properly creating threads we need Sent and Draft to be synchronized as well.
if (sentFolder != null && sentFolder.IsSynchronizationEnabled)
{
folders.Add(sentFolder);
}
if (draftFolder != null && draftFolder.IsSynchronizationEnabled)
{
folders.Add(draftFolder);
}
// User might've disabled inbox synchronization somehow...
if (inboxFolder != null && inboxFolder.IsSynchronizationEnabled)
{
folders.Add(inboxFolder);
}
}
else if (options.Type == SynchronizationType.Full)
if (options.Type == SynchronizationType.Full)
{
// Only get sync enabled folders.
@@ -598,19 +573,75 @@ namespace Wino.Core.Services
folders.AddRange(synchronizationFolders);
}
else if (options.Type == SynchronizationType.Custom)
else
{
// Only get the specified and enabled folders.
// Inbox, Sent and Draft folders must always be synchronized regardless of whether they are enabled or not.
// Custom folder sync will add additional folders to the list if not specified.
var synchronizationFolders = await Connection.Table<MailItemFolder>()
.Where(a => a.MailAccountId == options.AccountId && a.IsSynchronizationEnabled && options.SynchronizationFolderIds.Contains(a.Id))
.ToListAsync();
var mustHaveFolders = await GetInboxSynchronizationFoldersAsync(options.AccountId);
// Order is important for moving.
// By implementation, removing mail folders must be synchronized first. Requests are made in that order for custom sync.
// eg. Moving item from Folder A to Folder B. If we start syncing Folder B first, we might miss adding assignment for Folder A.
if (options.Type == SynchronizationType.Inbox)
{
return mustHaveFolders;
}
else if (options.Type == SynchronizationType.Custom)
{
// Only get the specified and enabled folders.
folders.AddRange(synchronizationFolders.OrderBy(a => options.SynchronizationFolderIds.IndexOf(a.Id)));
var synchronizationFolders = await Connection.Table<MailItemFolder>()
.Where(a => a.MailAccountId == options.AccountId && options.SynchronizationFolderIds.Contains(a.Id))
.ToListAsync();
// Order is important for moving.
// By implementation, removing mail folders must be synchronized first. Requests are made in that order for custom sync.
// eg. Moving item from Folder A to Folder B. If we start syncing Folder B first, we might miss adding assignment for Folder A.
var orderedCustomFolders = synchronizationFolders.OrderBy(a => options.SynchronizationFolderIds.IndexOf(a.Id));
foreach (var item in orderedCustomFolders)
{
if (!mustHaveFolders.Any(a => a.Id == item.Id))
{
mustHaveFolders.Add(item);
}
}
}
return mustHaveFolders;
}
return folders;
}
private async Task<List<MailItemFolder>> GetInboxSynchronizationFoldersAsync(Guid accountId)
{
var folders = new List<MailItemFolder>();
var inboxFolder = await GetSpecialFolderByAccountIdAsync(accountId, SpecialFolderType.Inbox);
var sentFolder = await GetSpecialFolderByAccountIdAsync(accountId, SpecialFolderType.Sent);
var draftFolder = await GetSpecialFolderByAccountIdAsync(accountId, SpecialFolderType.Draft);
var deletedFolder = await GetSpecialFolderByAccountIdAsync(accountId, SpecialFolderType.Deleted);
if (deletedFolder != null)
{
folders.Add(deletedFolder);
}
if (inboxFolder != null)
{
folders.Add(inboxFolder);
}
// For properly creating threads we need Sent and Draft to be synchronized as well.
if (sentFolder != null)
{
folders.Add(sentFolder);
}
if (draftFolder != null)
{
folders.Add(draftFolder);
}
return folders;

View File

@@ -395,7 +395,7 @@ namespace Wino.Core.Services
return;
}
_logger.Debug("Inserting mail {MailCopyId} to Folder {FolderId}", mailCopy.Id, mailCopy.FolderId);
_logger.Debug("Inserting mail {MailCopyId} to {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName);
await Connection.InsertAsync(mailCopy).ConfigureAwait(false);
@@ -427,7 +427,7 @@ namespace Wino.Core.Services
return;
}
_logger.Debug("Deleting mail {Id} with Folder {FolderId}", mailCopy.Id, mailCopy.FolderId);
_logger.Debug("Deleting mail {Id} from folder {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName);
await Connection.DeleteAsync(mailCopy).ConfigureAwait(false);
@@ -473,6 +473,8 @@ namespace Wino.Core.Services
public Task ChangeReadStatusAsync(string mailCopyId, bool isRead)
=> UpdateAllMailCopiesAsync(mailCopyId, (item) =>
{
if (item.IsRead == isRead) return false;
item.IsRead = isRead;
return true;
@@ -481,6 +483,8 @@ namespace Wino.Core.Services
public Task ChangeFlagStatusAsync(string mailCopyId, bool isFlagged)
=> UpdateAllMailCopiesAsync(mailCopyId, (item) =>
{
if (item.IsFlagged == isFlagged) return false;
item.IsFlagged = isFlagged;
return true;