diff --git a/src/Ombi.Notifications/Agents/EmailNotification.cs b/src/Ombi.Notifications/Agents/EmailNotification.cs index 232ccc8de..d8f005e2b 100644 --- a/src/Ombi.Notifications/Agents/EmailNotification.cs +++ b/src/Ombi.Notifications/Agents/EmailNotification.cs @@ -150,6 +150,10 @@ namespace Ombi.Notifications.Agents var isAdmin = bool.Parse(isAdminString); message.To = isAdmin ? model.Recipient : settings.AdminEmail; } + else + { + message.To = model.Recipient; + } await Send(message, settings); diff --git a/src/Ombi.Notifications/NotificationMessageCurlys.cs b/src/Ombi.Notifications/NotificationMessageCurlys.cs index 3b9eee236..f18f145e5 100644 --- a/src/Ombi.Notifications/NotificationMessageCurlys.cs +++ b/src/Ombi.Notifications/NotificationMessageCurlys.cs @@ -81,6 +81,7 @@ namespace Ombi.Notifications IssueStatus = opts.Substitutes.TryGetValue("IssueStatus", out val) ? val : string.Empty; IssueSubject = opts.Substitutes.TryGetValue("IssueSubject", out val) ? val : string.Empty; NewIssueComment = opts.Substitutes.TryGetValue("NewIssueComment", out val) ? val : string.Empty; + IssueUser = opts.Substitutes.TryGetValue("IssueUser", out val) ? val : string.Empty; } // User Defined @@ -101,6 +102,7 @@ namespace Ombi.Notifications public string IssueStatus { get; set; } public string IssueSubject { get; set; } public string NewIssueComment { get; set; } + public string IssueUser { get; set; } // System Defined private string LongDate => DateTime.Now.ToString("D"); @@ -131,6 +133,7 @@ namespace Ombi.Notifications {nameof(IssueStatus),IssueStatus}, {nameof(IssueSubject),IssueSubject}, {nameof(NewIssueComment),NewIssueComment}, + {nameof(IssueUser),IssueUser}, }; } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts index 8a5d9ff6a..4446f6340 100644 --- a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts @@ -35,16 +35,17 @@ export enum NotificationAgent { } export enum NotificationType { - NewRequest, - Issue, - RequestAvailable, - RequestApproved, - AdminNote, - Test, - RequestDeclined, - ItemAddedToFaultQueue, - WelcomeEmail, - IssueResolved, + NewRequest = 0, + Issue = 1, + RequestAvailable = 2, + RequestApproved = 3, + AdminNote = 4, + Test = 5, + RequestDeclined = 6, + ItemAddedToFaultQueue = 7, + WelcomeEmail = 8, + IssueResolved = 9, + IssueComment = 10, } export interface IDiscordNotifcationSettings extends INotificationSettings { diff --git a/src/Ombi/Controllers/IssuesController.cs b/src/Ombi/Controllers/IssuesController.cs index ed7eb7e6a..0b338e8b9 100644 --- a/src/Ombi/Controllers/IssuesController.cs +++ b/src/Ombi/Controllers/IssuesController.cs @@ -145,7 +145,7 @@ namespace Ombi.Controllers UserId = i.UserReportedId }; - AddIssueNotificationSubstitutes(notificationModel, i); + AddIssueNotificationSubstitutes(notificationModel, i, User.Identity.Name); BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); @@ -195,7 +195,7 @@ namespace Ombi.Controllers { var user = await _userManager.Users.Where(x => User.Identity.Name == x.UserName) .FirstOrDefaultAsync(); - var issue = await _issues.Find(comment.IssueId ?? 0); + var issue = await _issues.GetAll().Include(x => x.UserReported).FirstOrDefaultAsync(x => x.Id == comment.IssueId); if (issue == null) { return null; @@ -214,15 +214,24 @@ namespace Ombi.Controllers DateTime = DateTime.Now, NotificationType = NotificationType.IssueComment, RequestType = issue.RequestType, - Recipient = user.Email, UserId = user.Id }; var isAdmin = await _userManager.IsInRoleAsync(user, OmbiRoles.Admin); - AddIssueNotificationSubstitutes(notificationModel, issue); + AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported.UserAlias); notificationModel.Substitutes.Add("NewIssueComment", comment.Comment); notificationModel.Substitutes.Add("AdminComment", isAdmin.ToString()); + if (isAdmin) + { + // Send to user + notificationModel.Recipient = issue.UserReported.Email; + } + else + { + notificationModel.Recipient = user.Email; + } + BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); return await _issueComments.Add(newComment); @@ -257,7 +266,7 @@ namespace Ombi.Controllers UserId = user.Id, }; - AddIssueNotificationSubstitutes(notificationModel, issue); + AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported?.UserAlias ?? string.Empty); BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); } @@ -266,13 +275,14 @@ namespace Ombi.Controllers return true; } - private static void AddIssueNotificationSubstitutes(NotificationOptions notificationModel, Issues issue) + private static void AddIssueNotificationSubstitutes(NotificationOptions notificationModel, Issues issue, string issueReportedUsername) { notificationModel.Substitutes.Add("Title", issue.Title); notificationModel.Substitutes.Add("IssueDescription", issue.Description); notificationModel.Substitutes.Add("IssueCategory", issue.IssueCategory?.Value); notificationModel.Substitutes.Add("IssueStatus", issue.Status.ToString()); notificationModel.Substitutes.Add("IssueSubject", issue.Subject); + notificationModel.Substitutes.Add("IssueUser", issueReportedUsername); } } } \ No newline at end of file