diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 68f4b7218..dcae39cb0 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -152,6 +152,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } diff --git a/src/Ombi.Notifications/Agents/Interfaces/IMobileNotification.cs b/src/Ombi.Notifications/Agents/Interfaces/IMobileNotification.cs new file mode 100644 index 000000000..1daf7e46a --- /dev/null +++ b/src/Ombi.Notifications/Agents/Interfaces/IMobileNotification.cs @@ -0,0 +1,6 @@ +namespace Ombi.Notifications.Agents +{ + public interface IMobileNotification : INotification + { + } +} \ No newline at end of file diff --git a/src/Ombi.Notifications/Agents/MobileNotification.cs b/src/Ombi.Notifications/Agents/MobileNotification.cs index 1a716d9d6..35619ad1f 100644 --- a/src/Ombi.Notifications/Agents/MobileNotification.cs +++ b/src/Ombi.Notifications/Agents/MobileNotification.cs @@ -18,7 +18,7 @@ using Ombi.Store.Repository.Requests; namespace Ombi.Notifications.Agents { - public class MobileNotification : BaseNotification + public class MobileNotification : BaseNotification, IMobileNotification { public MobileNotification(IOneSignalApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, ISettingsService s, IRepository notification, @@ -232,7 +232,13 @@ namespace Ombi.Notifications.Agents Message = message, }; // Send to user - var playerIds = await GetAdmins(NotificationType.RequestAvailable); + var user = await _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefaultAsync(x => x.Id.Equals(model.UserId)); + if (user == null) + { + return; + } + + var playerIds = user.NotificationUserIds.Select(x => x.PlayerId).ToList(); await Send(playerIds, notification, settings); } diff --git a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts index da1e147da..8c5fcd5bc 100644 --- a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts @@ -101,3 +101,8 @@ export interface IMattermostNotifcationSettings extends INotificationSettings { export interface IMobileNotifcationSettings extends INotificationSettings { notificationTemplates: INotificationTemplates[]; } + +export interface IMobileNotificationTestSettings { + settings: IMobileNotifcationSettings; + userId: string; +} diff --git a/src/Ombi/ClientApp/app/services/applications/tester.service.ts b/src/Ombi/ClientApp/app/services/applications/tester.service.ts index bab94d32f..640d6ec04 100644 --- a/src/Ombi/ClientApp/app/services/applications/tester.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/tester.service.ts @@ -12,6 +12,7 @@ import { IEmailNotificationSettings, IEmbyServer, IMattermostNotifcationSettings, + IMobileNotificationTestSettings, INewsletterNotificationSettings, IPlexServer, IPushbulletNotificationSettings, @@ -81,5 +82,8 @@ export class TesterService extends ServiceHelpers { } public newsletterTest(settings: INewsletterNotificationSettings): Observable { return this.http.post(`${this.url}newsletter`, JSON.stringify(settings), {headers: this.headers}); + } + public mobileNotificationTest(settings: IMobileNotificationTestSettings): Observable { + return this.http.post(`${this.url}mobile`, JSON.stringify(settings), {headers: this.headers}); } } diff --git a/src/Ombi/ClientApp/app/settings/notifications/mobile.component.html b/src/Ombi/ClientApp/app/settings/notifications/mobile.component.html index fd02191d2..3aad31ff8 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/mobile.component.html +++ b/src/Ombi/ClientApp/app/settings/notifications/mobile.component.html @@ -34,8 +34,21 @@
- +
+ +
+ +
+
+
+
+ +
+
diff --git a/src/Ombi/ClientApp/app/settings/notifications/mobile.component.ts b/src/Ombi/ClientApp/app/settings/notifications/mobile.component.ts index 47ad3a25b..8c082e7ac 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/mobile.component.ts +++ b/src/Ombi/ClientApp/app/settings/notifications/mobile.component.ts @@ -15,6 +15,7 @@ export class MobileComponent implements OnInit { public templates: INotificationTemplates[]; public form: FormGroup; public userList: IMobileUsersViewModel[]; + public testUserId: string = "d164439a-6f23-43c6-bc12-6a8d3d89dbf5"; constructor(private settingsService: SettingsService, private notificationService: NotificationService, @@ -64,8 +65,12 @@ export class MobileComponent implements OnInit { this.notificationService.error("Please check your entered values"); return; } + if(!this.testUserId) { + this.notificationService.warning("Warning","Please select a user to send the test notification"); + return; + } - this.testerService.discordTest(form.value).subscribe(x => { + this.testerService.mobileNotificationTest({settings: form.value, userId: this.testUserId}).subscribe(x => { if (x) { this.notificationService.success("Successfully sent a Mobile message, please check the admin mobile device"); } else { diff --git a/src/Ombi/Controllers/External/TesterController.cs b/src/Ombi/Controllers/External/TesterController.cs index bad933e86..fca42bb63 100644 --- a/src/Ombi/Controllers/External/TesterController.cs +++ b/src/Ombi/Controllers/External/TesterController.cs @@ -14,6 +14,7 @@ using Ombi.Core.Models.UI; using Ombi.Core.Notifications; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Models; using Ombi.Notifications; using Ombi.Notifications.Agents; using Ombi.Notifications.Models; @@ -37,7 +38,7 @@ namespace Ombi.Controllers.External public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN, IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm, IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger log, IEmailProvider provider, - ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter) + ICouchPotatoApi cpApi, ITelegramNotification telegram, ISickRageApi srApi, INewsletterJob newsletter, IMobileNotification mobileNotification) { Service = service; DiscordNotification = notification; @@ -56,6 +57,7 @@ namespace Ombi.Controllers.External TelegramNotification = telegram; SickRageApi = srApi; Newsletter = newsletter; + MobileNotification = mobileNotification; } private INotificationService Service { get; } @@ -75,6 +77,7 @@ namespace Ombi.Controllers.External private ITelegramNotification TelegramNotification { get; } private ISickRageApi SickRageApi { get; } private INewsletterJob Newsletter { get; } + private IMobileNotification MobileNotification { get; } /// @@ -388,5 +391,21 @@ namespace Ombi.Controllers.External return false; } } + + [HttpPost("mobile")] + public async Task MobileNotificationTest([FromBody] MobileNotificationTestViewModel settings) + { + try + { + await MobileNotification.NotifyAsync(new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1, UserId = settings.UserId}, settings.Settings); + + return true; + } + catch (Exception e) + { + Log.LogError(LoggingEvents.Api, e, "Could not test Mobile Notifications"); + return false; + } + } } } \ No newline at end of file diff --git a/src/Ombi/Models/MobileNotificationTestViewModel.cs b/src/Ombi/Models/MobileNotificationTestViewModel.cs new file mode 100644 index 000000000..bba7a3a41 --- /dev/null +++ b/src/Ombi/Models/MobileNotificationTestViewModel.cs @@ -0,0 +1,10 @@ +using Ombi.Settings.Settings.Models.Notifications; + +namespace Ombi.Models +{ + public class MobileNotificationTestViewModel + { + public string UserId { get; set; } + public MobileNotificationSettings Settings { get; set; } + } +} \ No newline at end of file