btcpayserver/BTCPayServer/Services/Mails/StoreEmailSender.cs
2020-12-08 08:12:29 +01:00

38 lines
1.2 KiB
C#

using System;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Services.Stores;
namespace BTCPayServer.Services.Mails
{
class StoreEmailSender : EmailSender
{
public StoreEmailSender(StoreRepository storeRepository,
EmailSender fallback,
IBackgroundJobClient backgroundJobClient,
string storeId) : base(backgroundJobClient)
{
StoreId = storeId ?? throw new ArgumentNullException(nameof(storeId));
StoreRepository = storeRepository;
FallbackSender = fallback;
}
public StoreRepository StoreRepository { get; }
public EmailSender FallbackSender { get; }
public string StoreId { get; }
public override async Task<EmailSettings> GetEmailSettings()
{
var store = await StoreRepository.FindStore(StoreId);
var emailSettings = store.GetStoreBlob().EmailSettings;
if (emailSettings?.IsComplete() == true)
{
return emailSettings;
}
if (FallbackSender != null) return await FallbackSender?.GetEmailSettings();
return null;
}
}
}