From 0f315ebe3bf0797f3c0aeca95bbcc5984822ce7e Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Tue, 14 Jul 2020 22:35:01 +0100 Subject: [PATCH] Small changes for the mobile notification --- .../Agents/MobileNotification.cs | 23 ++++++++++++- .../NotificationMessageCurlys.cs | 8 +++-- .../usermanagement-user.component.ts | 34 +++++++------------ .../usermanagement.component.ts | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Ombi.Notifications/Agents/MobileNotification.cs b/src/Ombi.Notifications/Agents/MobileNotification.cs index 778adb7a9..3ac2bd7fe 100644 --- a/src/Ombi.Notifications/Agents/MobileNotification.cs +++ b/src/Ombi.Notifications/Agents/MobileNotification.cs @@ -53,9 +53,11 @@ namespace Ombi.Notifications.Agents _logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Mobile}"); return; } + var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.NewRequest) }; // Get admin devices @@ -74,6 +76,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.Issue) }; // Get admin devices @@ -92,6 +95,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.IssueComment) }; if (model.Substitutes.TryGetValue("AdminComment", out var isAdminString)) { @@ -123,6 +127,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.IssueResolved) }; // Send to user @@ -144,6 +149,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.ItemAddedToFaultQueue) }; // Get admin devices @@ -162,6 +168,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.RequestDeclined) }; // Send to user @@ -181,6 +188,7 @@ namespace Ombi.Notifications.Agents var notification = new NotificationMessage { Message = parsed.Message, + Data = GetNotificationData(parsed, NotificationType.RequestApproved) }; // Send to user @@ -198,9 +206,13 @@ namespace Ombi.Notifications.Agents _logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Mobile}"); return; } + + var data = GetNotificationData(parsed, NotificationType.RequestAvailable); + var notification = new NotificationMessage { Message = parsed.Message, + Data = data }; // Send to user var playerIds = GetUsers(model, NotificationType.RequestAvailable); @@ -208,6 +220,14 @@ namespace Ombi.Notifications.Agents await AddSubscribedUsers(playerIds); await Send(playerIds, notification, settings, model); } + + private static Dictionary GetNotificationData(NotificationMessageContent parsed, NotificationType type) + { + var notificationData = parsed.Data.ToDictionary(x => x.Key, x => x.Value); + notificationData[nameof(NotificationType)] = type.ToString(); + return notificationData; + } + protected override Task Send(NotificationMessage model, MobileNotificationSettings settings) { throw new NotImplementedException(); @@ -225,7 +245,8 @@ namespace Ombi.Notifications.Agents { Body = model.Message, Title = model.Subject, - To = token + To = token, + Data = new Dictionary(model.Data) }); } diff --git a/src/Ombi.Notifications/NotificationMessageCurlys.cs b/src/Ombi.Notifications/NotificationMessageCurlys.cs index 57a36cd87..1bf5b8ee9 100644 --- a/src/Ombi.Notifications/NotificationMessageCurlys.cs +++ b/src/Ombi.Notifications/NotificationMessageCurlys.cs @@ -14,12 +14,12 @@ namespace Ombi.Notifications { public class NotificationMessageCurlys { - public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s, UserNotificationPreferences pref) + public void Setup(NotificationOptions opts, MovieRequests req, CustomizationSettings s, UserNotificationPreferences pref) { LoadIssues(opts); RequestId = req?.Id.ToString(); - + ProviderId = req?.TheMovieDbId.ToString() ?? string.Empty; string title; if (req == null) { @@ -73,6 +73,7 @@ namespace Ombi.Notifications LoadIssues(opts); RequestId = req?.Id.ToString(); + ProviderId = req?.ForeignArtistId ?? string.Empty; string title; if (req == null) @@ -122,6 +123,7 @@ namespace Ombi.Notifications { LoadIssues(opts); RequestId = req.Id.ToString(); + ProviderId = req?.ParentRequest?.TvDbId.ToString() ?? string.Empty; string title; if (req == null) { @@ -274,6 +276,7 @@ namespace Ombi.Notifications public string DenyReason { get; set; } public string AvailableDate { get; set; } public string RequestStatus { get; set; } + public string ProviderId { get; set; } // System Defined private string LongDate => DateTime.Now.ToString("D"); @@ -312,6 +315,7 @@ namespace Ombi.Notifications {nameof(DenyReason),DenyReason}, {nameof(AvailableDate),AvailableDate}, {nameof(RequestStatus),RequestStatus}, + {nameof(ProviderId),ProviderId}, }; } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts index 7d3896372..e9ee08e4f 100644 --- a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts +++ b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts @@ -118,28 +118,18 @@ export class UserManagementUserComponent implements OnInit { } public delete() { - // TODO - // this.confirmationService.confirm({ - // message: "Are you sure that you want to delete this user? If this user has any requests they will also be deleted.", - // header: "Are you sure?", - // icon: "fa fa-trash", - // accept: () => { - // this.identityService.deleteUser(this.user).subscribe(x => { - // if (x.successful) { - // this.notificationService.send(`The user ${this.user.userName} was deleted`); - // this.router.navigate(["usermanagement"]); - // } else { - // x.errors.forEach((val) => { - // this.notificationService.send(val); - // }); - // } - - // }); - // }, - // reject: () => { - // return; - // }, - // }); + + this.identityService.deleteUser(this.user).subscribe(x => { + if (x.successful) { + this.notificationService.send(`The user ${this.user.userName} was deleted`); + this.router.navigate(["usermanagement"]); + } else { + x.errors.forEach((val) => { + this.notificationService.send(val); + }); + } + + }); } public resetPassword() { diff --git a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement.component.ts b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement.component.ts index 2edcc0732..f3a910b1a 100644 --- a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement.component.ts +++ b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement.component.ts @@ -35,7 +35,7 @@ export class UserManagementComponent implements OnInit { public async ngOnInit() { this.users = await this.identityService.getUsers().toPromise(); - + this.dataSource = new MatTableDataSource(this.users); this.dataSource.sort = this.sort;