Creating MailAccountAlias entity.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using SQLite;
|
using SQLite;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
|
|
||||||
@@ -73,6 +74,14 @@ namespace Wino.Core.Domain.Entities
|
|||||||
[Ignore]
|
[Ignore]
|
||||||
public CustomServerInformation ServerInformation { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Account preferences.
|
/// Account preferences.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
15
Wino.Core.Domain/Entities/MailAccountAlias.cs
Normal file
15
Wino.Core.Domain/Entities/MailAccountAlias.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -227,12 +227,40 @@ namespace Wino.Core.Services
|
|||||||
if (account.MergedInboxId != null)
|
if (account.MergedInboxId != null)
|
||||||
account.MergedInbox = await GetMergedInboxInformationAsync(account.MergedInboxId.Value);
|
account.MergedInbox = await GetMergedInboxInformationAsync(account.MergedInboxId.Value);
|
||||||
|
|
||||||
|
// Load aliases
|
||||||
|
account.Aliases = await GetAccountAliases(account.Id, account.Address);
|
||||||
|
|
||||||
account.Preferences = await GetAccountPreferencesAsync(account.Id);
|
account.Preferences = await GetAccountPreferencesAsync(account.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return accounts;
|
return accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<List<MailAccountAlias>> 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<MailAccountAlias>().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<MergedInbox> GetMergedInboxInformationAsync(Guid mergedInboxId)
|
private Task<MergedInbox> GetMergedInboxInformationAsync(Guid mergedInboxId)
|
||||||
=> Connection.Table<MergedInbox>().FirstOrDefaultAsync(a => a.Id == mergedInboxId);
|
=> Connection.Table<MergedInbox>().FirstOrDefaultAsync(a => a.Id == mergedInboxId);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ namespace Wino.Core.Services
|
|||||||
typeof(CustomServerInformation),
|
typeof(CustomServerInformation),
|
||||||
typeof(AccountSignature),
|
typeof(AccountSignature),
|
||||||
typeof(MergedInbox),
|
typeof(MergedInbox),
|
||||||
typeof(MailAccountPreferences)
|
typeof(MailAccountPreferences),
|
||||||
|
typeof(MailAccountAlias)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user