From 05ddc0660a5bebeb5a5227cc210e6127ea1bac0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Thu, 15 Aug 2024 16:02:02 +0200 Subject: [PATCH] Creating MailAccountAlias entity. --- Wino.Core.Domain/Entities/MailAccount.cs | 9 ++++++ Wino.Core.Domain/Entities/MailAccountAlias.cs | 15 ++++++++++ Wino.Core/Services/AccountService.cs | 28 +++++++++++++++++++ Wino.Core/Services/DatabaseService.cs | 3 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Wino.Core.Domain/Entities/MailAccountAlias.cs diff --git a/Wino.Core.Domain/Entities/MailAccount.cs b/Wino.Core.Domain/Entities/MailAccount.cs index dbeac65c..ecd8fb64 100644 --- a/Wino.Core.Domain/Entities/MailAccount.cs +++ b/Wino.Core.Domain/Entities/MailAccount.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using SQLite; using Wino.Core.Domain.Enums; @@ -73,6 +74,14 @@ namespace Wino.Core.Domain.Entities [Ignore] public CustomServerInformation ServerInformation { get; set; } + /// + /// 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. + /// + [Ignore] + public List Aliases { get; set; } + /// /// Account preferences. /// diff --git a/Wino.Core.Domain/Entities/MailAccountAlias.cs b/Wino.Core.Domain/Entities/MailAccountAlias.cs new file mode 100644 index 00000000..97e5257e --- /dev/null +++ b/Wino.Core.Domain/Entities/MailAccountAlias.cs @@ -0,0 +1,15 @@ +using System; +using SQLite; + +namespace Wino.Core.Domain.Entities +{ + public class MailAccountAlias + { + [PrimaryKey] + public Guid Id { get; set; } + public Guid AccountId { get; set; } + public string AliasAddress { get; set; } + public bool IsPrimary { get; set; } + public bool IsVerified { get; set; } + } +} diff --git a/Wino.Core/Services/AccountService.cs b/Wino.Core/Services/AccountService.cs index 63e1055b..afd992e8 100644 --- a/Wino.Core/Services/AccountService.cs +++ b/Wino.Core/Services/AccountService.cs @@ -227,12 +227,40 @@ namespace Wino.Core.Services if (account.MergedInboxId != null) account.MergedInbox = await GetMergedInboxInformationAsync(account.MergedInboxId.Value); + // Load aliases + account.Aliases = await GetAccountAliases(account.Id, account.Address); + account.Preferences = await GetAccountPreferencesAsync(account.Id); } return accounts; } + private async Task> GetAccountAliases(Guid accountId, string primaryAccountAddress) + { + // By default all accounts must have at least 1 primary alias to create drafts for. + // If there's no alias, create one from the existing account address. Migration doesn't exists to create one for older messages. + + var aliases = await Connection.Table().ToListAsync().ConfigureAwait(false); + + if (!aliases.Any()) + { + var primaryAccountAlias = new MailAccountAlias() + { + Id = Guid.NewGuid(), + AccountId = accountId, + IsPrimary = true, + AliasAddress = primaryAccountAddress, + IsVerified = true, + }; + + await Connection.InsertAsync(primaryAccountAlias).ConfigureAwait(false); + aliases.Add(primaryAccountAlias); + } + + return aliases; + } + private Task GetMergedInboxInformationAsync(Guid mergedInboxId) => Connection.Table().FirstOrDefaultAsync(a => a.Id == mergedInboxId); diff --git a/Wino.Core/Services/DatabaseService.cs b/Wino.Core/Services/DatabaseService.cs index 246f9a63..e21a88eb 100644 --- a/Wino.Core/Services/DatabaseService.cs +++ b/Wino.Core/Services/DatabaseService.cs @@ -61,7 +61,8 @@ namespace Wino.Core.Services typeof(CustomServerInformation), typeof(AccountSignature), typeof(MergedInbox), - typeof(MailAccountPreferences) + typeof(MailAccountPreferences), + typeof(MailAccountAlias) ); } }