Fixing an issue where doing folder config on account does not refresh the folder list.

This commit is contained in:
Burak Kaan Köse
2024-08-22 01:20:08 +02:00
parent 298344c2ab
commit d060db3c96
5 changed files with 37 additions and 33 deletions

View File

@@ -151,15 +151,12 @@ namespace Wino.Core.MenuItems
return accountMenuItem; return accountMenuItem;
} }
public async Task ReplaceFoldersAsync(IEnumerable<IMenuItem> folders) public void ReplaceFolders(IEnumerable<IMenuItem> folders)
{
await _dispatcher.ExecuteOnUIThread(() =>
{ {
ClearFolderAreaMenuItems(); ClearFolderAreaMenuItems();
Items.Add(new SeperatorItem()); Items.Add(new SeperatorItem());
AddRange(folders); AddRange(folders);
});
} }
/// <summary> /// <summary>
@@ -194,9 +191,11 @@ namespace Wino.Core.MenuItems
{ {
item.IsExpanded = false; item.IsExpanded = false;
item.IsSelected = false; item.IsSelected = false;
Remove(item);
}); });
RemoveRange(itemsToRemove); // RemoveRange(itemsToRemove);
} }
} }
} }

View File

@@ -387,11 +387,6 @@ namespace Wino.Core.Services
if (configuration == null) if (configuration == null)
throw new ArgumentNullException(nameof(configuration)); throw new ArgumentNullException(nameof(configuration));
var account = await _accountService.GetAccountAsync(accountId);
if (account == null)
throw new ArgumentNullException(nameof(account));
// Update system folders for this account. // Update system folders for this account.
await Task.WhenAll(UpdateSystemFolderInternalAsync(configuration.SentFolder, SpecialFolderType.Sent), await Task.WhenAll(UpdateSystemFolderInternalAsync(configuration.SentFolder, SpecialFolderType.Sent),
@@ -400,9 +395,8 @@ namespace Wino.Core.Services
UpdateSystemFolderInternalAsync(configuration.TrashFolder, SpecialFolderType.Deleted), UpdateSystemFolderInternalAsync(configuration.TrashFolder, SpecialFolderType.Deleted),
UpdateSystemFolderInternalAsync(configuration.ArchiveFolder, SpecialFolderType.Archive)); UpdateSystemFolderInternalAsync(configuration.ArchiveFolder, SpecialFolderType.Archive));
await _accountService.UpdateAccountAsync(account);
return account; return await _accountService.GetAccountAsync(accountId).ConfigureAwait(false);
} }
private Task UpdateSystemFolderInternalAsync(MailItemFolder folder, SpecialFolderType assignedSpecialFolderType) private Task UpdateSystemFolderInternalAsync(MailItemFolder folder, SpecialFolderType assignedSpecialFolderType)
@@ -492,13 +486,6 @@ namespace Wino.Core.Services
return; return;
} }
var account = await _accountService.GetAccountAsync(folder.MailAccountId).ConfigureAwait(false);
if (account == null)
{
_logger.Warning("Account with id {MailAccountId} does not exist. Cannot update folder.", folder.MailAccountId);
return;
}
_logger.Debug("Updating folder {FolderName}", folder.Id, folder.FolderName); _logger.Debug("Updating folder {FolderName}", folder.Id, folder.FolderName);
await Connection.UpdateAsync(folder).ConfigureAwait(false); await Connection.UpdateAsync(folder).ConfigureAwait(false);

View File

@@ -38,7 +38,8 @@ namespace Wino.Mail.ViewModels
IRecipient<LanguageChanged>, IRecipient<LanguageChanged>,
IRecipient<AccountMenuItemsReordered>, IRecipient<AccountMenuItemsReordered>,
IRecipient<AccountSynchronizationProgressUpdatedMessage>, IRecipient<AccountSynchronizationProgressUpdatedMessage>,
IRecipient<NavigateAppPreferencesRequested> IRecipient<NavigateAppPreferencesRequested>,
IRecipient<AccountFolderConfigurationUpdated>
{ {
#region Menu Items #region Menu Items
@@ -631,6 +632,9 @@ namespace Wino.Mail.ViewModels
await MenuItems.SetAccountMenuItemEnabledStatusAsync(false); await MenuItems.SetAccountMenuItemEnabledStatusAsync(false);
// Load account folder structure and replace the visible folders.
var folders = await _folderService.GetAccountFoldersForDisplayAsync(clickedBaseAccountMenuItem);
await ExecuteUIThread(() => await ExecuteUIThread(() =>
{ {
clickedBaseAccountMenuItem.IsEnabled = false; clickedBaseAccountMenuItem.IsEnabled = false;
@@ -643,12 +647,10 @@ namespace Wino.Mail.ViewModels
clickedBaseAccountMenuItem.IsSelected = true; clickedBaseAccountMenuItem.IsSelected = true;
latestSelectedAccountMenuItem = clickedBaseAccountMenuItem; latestSelectedAccountMenuItem = clickedBaseAccountMenuItem;
MenuItems.ReplaceFolders(folders);
}); });
// Load account folder structure and replace the visible folders.
var folders = await _folderService.GetAccountFoldersForDisplayAsync(clickedBaseAccountMenuItem);
await MenuItems.ReplaceFoldersAsync(folders);
await UpdateUnreadItemCountAsync(); await UpdateUnreadItemCountAsync();
await MenuItems.SetAccountMenuItemEnabledStatusAsync(true); await MenuItems.SetAccountMenuItemEnabledStatusAsync(true);
@@ -955,6 +957,16 @@ namespace Wino.Mail.ViewModels
} }
} }
public async void Receive(AccountFolderConfigurationUpdated message)
{
// Reloading of folders is needed to re-create folder tree if the account is loaded.
if (MenuItems.TryGetAccountMenuItem(message.AccountId, out IAccountMenuItem accountMenuItem))
{
await ChangeLoadedAccountAsync(accountMenuItem, true);
}
}
public async void Receive(MergedInboxRenamed message) public async void Receive(MergedInboxRenamed message)
{ {
var mergedInboxMenuItem = MenuItems.FirstOrDefault(a => a.EntityId == message.MergedInboxId); var mergedInboxMenuItem = MenuItems.FirstOrDefault(a => a.EntityId == message.MergedInboxId);

View File

@@ -19,9 +19,9 @@ using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models.Synchronization; using Wino.Core.Domain.Models.Synchronization;
using Wino.Core.UWP.Extensions; using Wino.Core.UWP.Extensions;
using Wino.Dialogs; using Wino.Dialogs;
using Wino.Messaging.Client.Accounts;
using Wino.Messaging.Client.Shell; using Wino.Messaging.Client.Shell;
using Wino.Messaging.Server; using Wino.Messaging.Server;
using Wino.Messaging.UI;
namespace Wino.Services namespace Wino.Services
{ {
@@ -197,16 +197,13 @@ namespace Wino.Services
if (configuration != null) if (configuration != null)
{ {
var updatedAccount = await folderService.UpdateSystemFolderConfigurationAsync(accountId, configuration);
InfoBarMessage(Translator.SystemFolderConfigSetupSuccess_Title, Translator.SystemFolderConfigSetupSuccess_Message, InfoBarMessageType.Success); InfoBarMessage(Translator.SystemFolderConfigSetupSuccess_Title, Translator.SystemFolderConfigSetupSuccess_Message, InfoBarMessageType.Success);
// Update account menu item and force re-synchronization. WeakReferenceMessenger.Default.Send(new AccountFolderConfigurationUpdated(accountId));
WeakReferenceMessenger.Default.Send(new AccountUpdatedMessage(updatedAccount));
var options = new SynchronizationOptions() var options = new SynchronizationOptions()
{ {
AccountId = updatedAccount.Id, AccountId = accountId,
Type = SynchronizationType.Full, Type = SynchronizationType.Full,
}; };

View File

@@ -0,0 +1,9 @@
using System;
namespace Wino.Messaging.Client.Accounts
{
/// <summary>
/// When account's special folder configuration is updated.
/// </summary>
public record AccountFolderConfigurationUpdated(Guid AccountId);
}