Reworked aliases.

This commit is contained in:
Burak Kaan Köse
2024-08-17 19:54:52 +02:00
parent a87df2e9f6
commit 747efac2ec
22 changed files with 496 additions and 437 deletions

View File

@@ -78,18 +78,20 @@ namespace Wino.Core.Domain.Entities
[Ignore]
public CustomServerInformation ServerInformation { get; set; }
/// <summary>
/// Gets or sets the aliases of the account.
/// It's only synchronized for Gmail right now.
/// Other provider types are manually added by users and not verified.
/// </summary>
//[Ignore]
//public List<MailAccountAlias> Aliases { get; set; }
/// <summary>
/// Account preferences.
/// </summary>
[Ignore]
public MailAccountPreferences Preferences { get; set; }
/// <summary>
/// Gets whether the account can perform ProfileInformation sync type.
/// </summary>
public bool IsProfileInfoSyncSupported => ProviderType == MailProviderType.Outlook || ProviderType == MailProviderType.Office365 || ProviderType == MailProviderType.Gmail;
/// <summary>
/// Gets whether the account can perform AliasInformation sync type.
/// </summary>
public bool IsAliasSyncSupported => ProviderType == MailProviderType.Gmail;
}
}

View File

@@ -1,22 +1,10 @@
using System;
using System.Collections.Generic;
using SQLite;
namespace Wino.Core.Domain.Entities
{
public class MailAccountAlias
public class RemoteAccountAlias
{
/// <summary>
/// Unique Id for the alias.
/// </summary>
[PrimaryKey]
public Guid Id { get; set; }
/// <summary>
/// Account id that this alias is attached to.
/// </summary>
public Guid AccountId { get; set; }
/// <summary>
/// Display address of the alias.
/// </summary>
@@ -32,13 +20,6 @@ namespace Wino.Core.Domain.Entities
/// </summary>
public bool IsPrimary { get; set; }
/// <summary>
/// Whether this alias is the root alias for the account.
/// Root alias means the first alias that was created for the account.
/// It can't be deleted or changed.
/// </summary>
public bool IsRootAlias { get; set; }
/// <summary>
/// Whether the alias is verified by the server.
/// Non-verified aliases will show an info tip to users during sending.
@@ -47,37 +28,30 @@ namespace Wino.Core.Domain.Entities
/// </summary>
public bool IsVerified { get; set; }
/// <summary>
/// Whether this alias is the root alias for the account.
/// Root alias means the first alias that was created for the account.
/// It can't be deleted or changed.
/// </summary>
public bool IsRootAlias { get; set; }
}
public class MailAccountAlias : RemoteAccountAlias
{
/// <summary>
/// Unique Id for the alias.
/// </summary>
[PrimaryKey]
public Guid Id { get; set; }
/// <summary>
/// Account id that this alias is attached to.
/// </summary>
public Guid AccountId { get; set; }
/// <summary>
/// Root aliases can't be deleted.
/// </summary>
public bool CanDelete => !IsRootAlias;
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
var other = (MailAccountAlias)obj;
return other != null &&
AccountId == other.AccountId &&
AliasAddress == other.AliasAddress &&
ReplyToAddress == other.ReplyToAddress &&
IsPrimary == other.IsPrimary &&
IsVerified == other.IsVerified &&
IsRootAlias == other.IsRootAlias;
}
public override int GetHashCode()
{
int hashCode = 59052167;
hashCode = hashCode * -1521134295 + AccountId.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(AliasAddress);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ReplyToAddress);
hashCode = hashCode * -1521134295 + IsPrimary.GetHashCode();
hashCode = hashCode * -1521134295 + IsRootAlias.GetHashCode();
hashCode = hashCode * -1521134295 + IsVerified.GetHashCode();
hashCode = hashCode * -1521134295 + CanDelete.GetHashCode();
return hashCode;
}
}
}

View File

@@ -4,9 +4,10 @@
{
FoldersOnly, // Only synchronize folder metadata.
ExecuteRequests, // Run the queued requests, and then synchronize if needed.
Inbox, // Only Inbox
Inbox, // Only Inbox, Sent and Draft folders.
Custom, // Only sync folders that are specified in the options.
Full, // Synchronize everything
Full, // Synchronize all folders. This won't update profile or alias information.
UpdateProfile, // Only update profile information
Alias, // Only update alias information
}
}

View File

@@ -1,34 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Wino.Core.Domain.Entities;
namespace Wino.Core.Domain.Extensions
{
public static class EntityExtensions
{
public static List<MailAccountAlias> GetFinalAliasList(List<MailAccountAlias> localAliases, List<MailAccountAlias> networkAliases)
{
var finalAliases = new List<MailAccountAlias>();
var networkAliasDict = networkAliases.ToDictionary(a => a, a => a);
// Handle updating and retaining existing aliases
foreach (var localAlias in localAliases)
{
if (networkAliasDict.TryGetValue(localAlias, out var networkAlias))
{
// If alias exists in both lists, update it with the network alias (preserving Id from local)
networkAlias.Id = localAlias.Id; // Preserve the local Id
finalAliases.Add(networkAlias);
networkAliasDict.Remove(localAlias); // Remove from dictionary to track what's been handled
}
// If the alias isn't in the network list, it's considered deleted and not added to finalAliases
}
// Add new aliases that were not in the local list
finalAliases.AddRange(networkAliasDict.Values);
return finalAliases;
}
}
}

View File

@@ -139,5 +139,12 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="accountId">Account id.</param>
/// <param name="address">Address to create root primary alias from.</param>
Task CreateRootAliasAsync(Guid accountId, string address);
/// <summary>
/// Will compare local-remote aliases and update the local ones or add/delete new ones.
/// </summary>
/// <param name="remoteAccountAliases">Remotely fetched basic alias info from synchronizer.</param>
/// <param name="account">Account to update remote aliases for..</param>
Task UpdateRemoteAliasInformationAsync(MailAccount account, List<RemoteAccountAlias> remoteAccountAliases);
}
}

View File

@@ -49,7 +49,7 @@ namespace Wino.Core.Domain.Interfaces
/// Sender name and
/// </summary>
/// <returns></returns>
Task<ProfileInformation> SynchronizeProfileInformationAsync();
Task<ProfileInformation> GetProfileInformationAsync();
/// <summary>
/// Downloads a single MIME message from the server and saves it to disk.

View File

@@ -25,7 +25,12 @@ namespace Wino.Core.Domain.Models.Synchronization
public static SynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
public static SynchronizationResult Completed(IEnumerable<IMailItem> downloadedMessages, ProfileInformation profileInformation = null)
=> new() { DownloadedMessages = downloadedMessages, ProfileInformation = profileInformation, CompletedState = SynchronizationCompletedState.Success };
=> new()
{
DownloadedMessages = downloadedMessages,
ProfileInformation = profileInformation,
CompletedState = SynchronizationCompletedState.Success
};
public static SynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static SynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };

View File

@@ -22,6 +22,8 @@
"BasicIMAPSetupDialog_Password": "Password",
"BasicIMAPSetupDialog_Title": "IMAP Account",
"Buttons_AddAccount": "Add Account",
"Buttons_AddNewAlias": "Add New Alias",
"Buttons_SyncAliases": "Synchronize Aliases",
"Buttons_ApplyTheme": "Apply Theme",
"Buttons_Browse": "Browse",
"Buttons_Cancel": "Cancel",
@@ -128,6 +130,7 @@
"Exception_CustomThemeMissingName": "You must provide a name.",
"Exception_CustomThemeMissingWallpaper": "You must provide a custom background image.",
"Exception_FailedToSynchronizeFolders": "Failed to synchronize folders",
"Exception_FailedToSynchronizeAliases": "Failed to synchronize aliases",
"Exception_FailedToSynchronizeProfileInformation": "Failed to synchronize profile information",
"Exception_GoogleAuthCallbackNull": "Callback uri is null on activation.",
"Exception_GoogleAuthCorruptedCode": "Corrupted authorization response.",

View File

@@ -133,6 +133,16 @@ namespace Wino.Core.Domain
/// </summary>
public static string Buttons_AddAccount => Resources.GetTranslatedString(@"Buttons_AddAccount");
/// <summary>
/// Add New Alias
/// </summary>
public static string Buttons_AddNewAlias => Resources.GetTranslatedString(@"Buttons_AddNewAlias");
/// <summary>
/// Synchronize Aliases
/// </summary>
public static string Buttons_SyncAliases => Resources.GetTranslatedString(@"Buttons_SyncAliases");
/// <summary>
/// Apply Theme
/// </summary>
@@ -663,6 +673,11 @@ namespace Wino.Core.Domain
/// </summary>
public static string Exception_FailedToSynchronizeFolders => Resources.GetTranslatedString(@"Exception_FailedToSynchronizeFolders");
/// <summary>
/// Failed to synchronize aliases
/// </summary>
public static string Exception_FailedToSynchronizeAliases => Resources.GetTranslatedString(@"Exception_FailedToSynchronizeAliases");
/// <summary>
/// Failed to synchronize profile information
/// </summary>