Remoddeled the notificaiton settings to make it easier to add more. This is some techinical changes that no one except me will ever notice :(

This commit is contained in:
Jamie.Rees 2017-03-15 08:42:48 +00:00
commit dc63693bf6
11 changed files with 448 additions and 452 deletions

View file

@ -37,7 +37,7 @@ using SmtpClient = MailKit.Net.Smtp.SmtpClient;
namespace Ombi.Services.Notification
{
public class EmailMessageNotification : BaseNotification<EmailNotificationSettings, MimeMessage>
public class EmailMessageNotification : BaseNotification<EmailNotificationSettings>
{
public EmailMessageNotification(ISettingsService<EmailNotificationSettings> settings) : base(settings)
{
@ -63,135 +63,150 @@ namespace Ombi.Services.Notification
return true;
}
protected override async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task NewRequest(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
$"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!",
$"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!"
Message = html,
Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}");
await Send(message, settings);
}
protected override async Task EmailIssue(NotificationModel model, EmailNotificationSettings settings)
protected override async Task Issue(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
$"Ombi: New issue for {model.Title}!",
$"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!"};
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: New issue for {model.Title}!"
Message = html,
Subject = $"Ombi: New issue for {model.Title}!",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!");
await Send(message, settings);
}
protected override async Task EmailAddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
protected override async Task AddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
"Ombi: A request could not be added.",
$"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying" };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: A request could not be added"
Message = html,
Subject = $"Ombi: A request could not be added",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying");
await Send(message, settings);
}
protected override async Task EmailRequestDeclined(NotificationModel model, EmailNotificationSettings settings)
protected override async Task RequestDeclined(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
"Ombi: Your request has been declined",
$"Hello! Your request for {model.Title} has been declined, Sorry!",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! Your request for {model.Title} has been declined, Sorry!", };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: Your request has been declined"
Message = html,
Subject = $"Ombi: Your request has been declined",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been declined, Sorry!");
await Send(message, settings);
}
protected override async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings)
protected override async Task RequestApproved(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
"Ombi: Your request has been approved!",
$"Hello! Your request for {model.Title} has been approved!",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! Your request for {model.Title} has been approved!", };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: Your request has been approved!"
Message = html,
Subject = $"Ombi: Your request has been approved!",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been approved!");
await Send(message, settings);
}
protected override async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task AvailableRequest(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
$"Ombi: {model.Title} is now available!",
$"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)" };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody(),
Subject = $"Ombi: {model.Title} is now available!"
Message = html,
Subject = $"Ombi: {model.Title} is now available!",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
message.Other.Add("PlainTextBody", $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)");
await Send(message, settings);
}
protected override async Task Send(MimeMessage message, EmailNotificationSettings settings)
protected override async Task Send(NotificationMessage model, EmailNotificationSettings settings)
{
try
{
var body = new BodyBuilder
{
HtmlBody = model.Message,
TextBody = model.Other["PlainTextBody"]
};
var message = new MimeMessage
{
Body = body.ToMessageBody(),
Subject = model.Subject
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(model.To, model.To));
using (var client = new SmtpClient())
{
client.Connect(settings.EmailHost, settings.EmailPort); // Let MailKit figure out the correct SecureSocketOptions.
@ -215,20 +230,21 @@ namespace Ombi.Services.Notification
}
}
protected override async Task EmailTest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task Test(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
"Test Message",
"This is just a test! Success!",
model.ImgSrc);
var body = new BodyBuilder { HtmlBody = html, };
var message = new MimeMessage
var message = new NotificationMessage
{
Body = body.ToMessageBody()
Message = html,
Subject = $"Ombi: Test",
To = model.UserEmail,
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
message.Other.Add("PlainTextBody", "This is just a test! Success!");
await Send(message, settings);
}