mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
Fixed #1914
Also added new notification variables and a new notification when someone adds a comment on an issue.
This commit is contained in:
parent
b223306ee8
commit
480a107fa6
15 changed files with 322 additions and 42 deletions
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MailKit.Net.Smtp;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MimeKit;
|
||||
using Ombi.Core.Settings;
|
||||
|
@ -19,14 +21,16 @@ namespace Ombi.Notifications.Agents
|
|||
public class EmailNotification : BaseNotification<EmailNotificationSettings>, IEmailNotification
|
||||
{
|
||||
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService<CustomizationSettings> c,
|
||||
ILogger<EmailNotification> log) : base(settings, r, m, t, c,log)
|
||||
ILogger<EmailNotification> log, UserManager<OmbiUser> um) : base(settings, r, m, t, c)
|
||||
{
|
||||
EmailProvider = prov;
|
||||
Logger = log;
|
||||
_userManager = um;
|
||||
}
|
||||
private IEmailProvider EmailProvider { get; }
|
||||
private ILogger<EmailNotification> Logger { get; }
|
||||
public override string NotificationName => nameof(EmailNotification);
|
||||
private readonly UserManager<OmbiUser> _userManager;
|
||||
|
||||
protected override bool ValidateConfiguration(EmailNotificationSettings settings)
|
||||
{
|
||||
|
@ -65,9 +69,24 @@ namespace Ombi.Notifications.Agents
|
|||
{
|
||||
Message = html,
|
||||
Subject = parsed.Subject,
|
||||
To = model.Recipient.HasValue() ? model.Recipient : settings.AdminEmail,
|
||||
};
|
||||
|
||||
if (model.Substitutes.TryGetValue("AdminComment", out var isAdminString))
|
||||
{
|
||||
var isAdmin = bool.Parse(isAdminString);
|
||||
if (isAdmin)
|
||||
{
|
||||
var user = _userManager.Users.FirstOrDefault(x => x.Id == model.UserId);
|
||||
// Send to user
|
||||
message.To = user.Email;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send to admin
|
||||
message.To = settings.AdminEmail;
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -109,6 +128,27 @@ namespace Ombi.Notifications.Agents
|
|||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task IssueComment(NotificationOptions model, EmailNotificationSettings settings)
|
||||
{
|
||||
var message = await LoadTemplate(NotificationType.IssueComment, model, settings);
|
||||
if (message == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var plaintext = await LoadPlainTextMessage(NotificationType.IssueComment, model, settings);
|
||||
message.Other.Add("PlainTextBody", plaintext);
|
||||
|
||||
if (model.Substitutes.TryGetValue("AdminComment", out var isAdminString))
|
||||
{
|
||||
var isAdmin = bool.Parse(isAdminString);
|
||||
message.To = isAdmin ? model.Recipient : settings.AdminEmail;
|
||||
}
|
||||
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task IssueResolved(NotificationOptions model, EmailNotificationSettings settings)
|
||||
{
|
||||
var message = await LoadTemplate(NotificationType.IssueResolved, model, settings);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue