Updating aliases during profile sync for Gmail.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SQLite;
|
||||
|
||||
namespace Wino.Core.Domain.Entities
|
||||
@@ -38,5 +39,30 @@ namespace Wino.Core.Domain.Entities
|
||||
/// Non-verified alias messages might be rejected by SMTP server.
|
||||
/// </summary>
|
||||
public bool IsVerified { get; set; }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hashCode = -753829106;
|
||||
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 + IsVerified.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
Wino.Core.Domain/Extensions/EntityExtensions.cs
Normal file
34
Wino.Core.Domain/Extensions/EntityExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,5 +100,13 @@ namespace Wino.Core.Domain.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="accountIdOrderPair">AccountId-OrderNumber pair for all accounts.</param>
|
||||
Task UpdateAccountOrdersAsync(Dictionary<Guid, int> accountIdOrderPair);
|
||||
|
||||
/// <summary>
|
||||
/// Updated account's aliases.
|
||||
/// </summary>
|
||||
/// <param name="accountId">Account id to update aliases for.</param>
|
||||
/// <param name="aliases">Full list of updated aliases.</param>
|
||||
/// <returns></returns>
|
||||
Task UpdateAccountAliases(Guid accountId, List<MailAccountAlias> aliases);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user