Fix account folder layout is not updated if there is a change after the synchronization.

This commit is contained in:
Burak Kaan Köse
2024-08-24 17:22:47 +02:00
parent 2a1f748469
commit d30c15464b
8 changed files with 37 additions and 13 deletions

View File

@@ -250,6 +250,9 @@ namespace Wino.Core.UWP.Services
case nameof(AccountSynchronizationProgressUpdatedMessage):
WeakReferenceMessenger.Default.Send(JsonSerializer.Deserialize<AccountSynchronizationProgressUpdatedMessage>(messageJson));
break;
case nameof(AccountFolderConfigurationUpdated):
WeakReferenceMessenger.Default.Send(JsonSerializer.Deserialize<AccountFolderConfigurationUpdated>(messageJson));
break;
default:
throw new Exception("Invalid data type name passed to client.");
}

View File

@@ -76,9 +76,7 @@ namespace Wino.Core.Extensions
public static MailItemFolder GetLocalFolder(this Label label, ListLabelsResponse labelsResponse, Guid accountId)
{
var normalizedLabelName = GetFolderName(label);
var normalizedLabelName = GetFolderName(label.Name);
// Even though we normalize the label name, check is done by capitalizing the label name.
var capitalNormalizedLabelName = normalizedLabelName.ToUpper();
@@ -155,14 +153,14 @@ namespace Wino.Core.Extensions
return labelsResponse.Labels.FirstOrDefault(a => a.Name == parentLabelName)?.Id ?? string.Empty;
}
public static string GetFolderName(Label label)
public static string GetFolderName(string fullFolderName)
{
if (string.IsNullOrEmpty(label.Name)) return string.Empty;
if (string.IsNullOrEmpty(fullFolderName)) return string.Empty;
// Folders with "//" at the end has "/" as the name.
if (label.Name.EndsWith(FOLDER_SEPERATOR_STRING)) return FOLDER_SEPERATOR_STRING;
if (fullFolderName.EndsWith(FOLDER_SEPERATOR_STRING)) return FOLDER_SEPERATOR_STRING;
string[] parts = label.Name.Split(FOLDER_SEPERATOR_CHAR);
string[] parts = fullFolderName.Split(FOLDER_SEPERATOR_CHAR);
var lastPart = parts[parts.Length - 1];

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Http;
@@ -27,6 +28,7 @@ using Wino.Core.Extensions;
using Wino.Core.Http;
using Wino.Core.Integration.Processors;
using Wino.Core.Requests;
using Wino.Messaging.UI;
namespace Wino.Core.Synchronizers
{
@@ -365,6 +367,11 @@ namespace Wino.Core.Synchronizers
{
await _gmailChangeProcessor.UpdateFolderAsync(folder).ConfigureAwait(false);
}
if (insertedFolders.Any() || deletedFolders.Any() || updatedFolders.Any())
{
WeakReferenceMessenger.Default.Send(new AccountFolderConfigurationUpdated(Account.Id));
}
}
catch (Exception)
{
@@ -374,7 +381,10 @@ namespace Wino.Core.Synchronizers
private bool ShouldUpdateFolder(Label remoteFolder, MailItemFolder existingLocalFolder)
{
bool isNameChanged = !existingLocalFolder.FolderName.Equals(GoogleIntegratorExtensions.GetFolderName(remoteFolder), StringComparison.OrdinalIgnoreCase);
var remoteFolderName = GoogleIntegratorExtensions.GetFolderName(remoteFolder.Name);
var localFolderName = GoogleIntegratorExtensions.GetFolderName(existingLocalFolder.FolderName);
bool isNameChanged = !localFolderName.Equals(remoteFolderName, StringComparison.OrdinalIgnoreCase);
bool isColorChanged = existingLocalFolder.BackgroundColorHex != remoteFolder.Color?.BackgroundColor ||
existingLocalFolder.TextColorHex != remoteFolder.Color?.TextColor;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using MailKit;
using MailKit.Net.Imap;
using MailKit.Search;
@@ -21,6 +22,7 @@ using Wino.Core.Integration.Processors;
using Wino.Core.Mime;
using Wino.Core.Requests;
using Wino.Core.Requests.Bundles;
using Wino.Messaging.UI;
namespace Wino.Core.Synchronizers
{
@@ -717,6 +719,11 @@ namespace Wino.Core.Synchronizers
{
await _imapChangeProcessor.UpdateFolderAsync(folder).ConfigureAwait(false);
}
if (insertedFolders.Any() || deletedFolders.Any() || updatedFolders.Any())
{
WeakReferenceMessenger.Default.Send(new AccountFolderConfigurationUpdated(Account.Id));
}
}
catch (Exception ex)
{

View File

@@ -971,7 +971,8 @@ namespace Wino.Mail.ViewModels
{
// Reloading of folders is needed to re-create folder tree if the account is loaded.
if (MenuItems.TryGetAccountMenuItem(message.AccountId, out IAccountMenuItem accountMenuItem))
if (MenuItems.TryGetAccountMenuItem(message.AccountId, out IAccountMenuItem accountMenuItem) &&
latestSelectedAccountMenuItem == accountMenuItem)
{
await ChangeLoadedAccountAsync(accountMenuItem, true);
}

View File

@@ -19,9 +19,9 @@ using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models.Synchronization;
using Wino.Core.UWP.Extensions;
using Wino.Dialogs;
using Wino.Messaging.Client.Accounts;
using Wino.Messaging.Client.Shell;
using Wino.Messaging.Server;
using Wino.Messaging.UI;
namespace Wino.Services
{
@@ -197,6 +197,8 @@ namespace Wino.Services
if (configuration != null)
{
await folderService.UpdateSystemFolderConfigurationAsync(accountId, configuration);
InfoBarMessage(Translator.SystemFolderConfigSetupSuccess_Title, Translator.SystemFolderConfigSetupSuccess_Message, InfoBarMessageType.Success);
WeakReferenceMessenger.Default.Send(new AccountFolderConfigurationUpdated(accountId));

View File

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

View File

@@ -41,7 +41,8 @@ namespace Wino.Server
IRecipient<AccountSynchronizerStateChanged>,
IRecipient<RefreshUnreadCountsMessage>,
IRecipient<ServerTerminationModeChanged>,
IRecipient<AccountSynchronizationProgressUpdatedMessage>
IRecipient<AccountSynchronizationProgressUpdatedMessage>,
IRecipient<AccountFolderConfigurationUpdated>
{
private readonly System.Timers.Timer _timer;
private static object connectionLock = new object();
@@ -136,6 +137,8 @@ namespace Wino.Server
public async void Receive(AccountSynchronizationProgressUpdatedMessage message) => await SendMessageAsync(MessageType.UIMessage, message);
public async void Receive(AccountFolderConfigurationUpdated message) => await SendMessageAsync(MessageType.UIMessage, message);
#endregion
private string GetAppPackagFamilyName()