From a61594dcd6820237916f03b5601fc3b58d82e4b2 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 8 Mar 2021 10:13:24 +0000 Subject: [PATCH] Fixed the issue where the new mobile app was not recieving any notifications --- .../Agents/MobileNotification.cs | 43 +++++++++++-------- src/Ombi.Notifications/BaseNotification.cs | 2 +- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Ombi.Notifications/Agents/MobileNotification.cs b/src/Ombi.Notifications/Agents/MobileNotification.cs index 61526802c..6080acdf0 100644 --- a/src/Ombi.Notifications/Agents/MobileNotification.cs +++ b/src/Ombi.Notifications/Agents/MobileNotification.cs @@ -131,7 +131,7 @@ namespace Ombi.Notifications.Agents }; // Send to user - var playerIds = GetUsers(model, NotificationType.IssueResolved); + var playerIds = await GetUsers(model, NotificationType.IssueResolved); await Send(playerIds, notification, settings, model); } @@ -172,7 +172,7 @@ namespace Ombi.Notifications.Agents }; // Send to user - var playerIds = GetUsers(model, NotificationType.RequestDeclined); + var playerIds = await GetUsers(model, NotificationType.RequestDeclined); await AddSubscribedUsers(playerIds); await Send(playerIds, notification, settings, model); } @@ -192,7 +192,7 @@ namespace Ombi.Notifications.Agents }; // Send to user - var playerIds = GetUsers(model, NotificationType.RequestApproved); + var playerIds = await GetUsers(model, NotificationType.RequestApproved); await AddSubscribedUsers(playerIds); await Send(playerIds, notification, settings, model); @@ -215,7 +215,7 @@ namespace Ombi.Notifications.Agents Data = data }; // Send to user - var playerIds = GetUsers(model, NotificationType.RequestAvailable); + var playerIds = await GetUsers(model, NotificationType.RequestAvailable); await AddSubscribedUsers(playerIds); await Send(playerIds, notification, settings, model); @@ -285,19 +285,23 @@ namespace Ombi.Notifications.Agents return playerIds; } - private List GetUsers(NotificationOptions model, NotificationType type) + private async Task> GetUsers(NotificationOptions model, NotificationType type) { - var notificationIds = new List(); + var notificationIds = new List(); if (MovieRequest != null || TvRequest != null) { - notificationIds = model.RequestType == RequestType.Movie - ? MovieRequest?.RequestedUser?.NotificationUserIds - : TvRequest?.RequestedUser?.NotificationUserIds; + var userId = model.RequestType == RequestType.Movie + ? MovieRequest?.RequestedUser?.Id + : TvRequest?.RequestedUser?.Id; + + var userNotificationIds = await _notifications.GetAll().Where(x => x.UserId == userId).ToListAsync(); + notificationIds.AddRange(userNotificationIds); } if (model.UserId.HasValue() && (!notificationIds?.Any() ?? true)) { - var user = _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefault(x => x.Id == model.UserId); - notificationIds = user.NotificationUserIds; + var user = _userManager.Users.FirstOrDefault(x => x.Id == model.UserId); + var userNotificationIds = await _notifications.GetAll().Where(x => x.UserId == model.UserId).ToListAsync(); + notificationIds.AddRange(userNotificationIds); } if (!notificationIds?.Any() ?? true) @@ -306,21 +310,21 @@ namespace Ombi.Notifications.Agents $"there are no users to send a notification for {type}, for agent {NotificationAgent.Mobile}"); return null; } - var playerIds = notificationIds.Select(x => x.PlayerId).ToList(); + var playerIds = notificationIds.Select(x => x.Token).ToList(); return playerIds; } private async Task> GetUsersForIssue(NotificationOptions model, int issueId, NotificationType type) { - var notificationIds = new List(); + var notificationIds = new List(); var issue = await _issueRepository.GetAll() .FirstOrDefaultAsync(x => x.Id == issueId); // Get the user that raised the issue to send the notification to - var userRaised = await _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefaultAsync(x => x.Id == issue.UserReportedId); + var userRaised = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == issue.UserReportedId); - notificationIds = userRaised.NotificationUserIds; + notificationIds = await _notifications.GetAll().Where(x => x.UserId == userRaised.Id).ToListAsync(); if (!notificationIds?.Any() ?? true) { @@ -328,7 +332,7 @@ namespace Ombi.Notifications.Agents $"there are no users to send a notification for {type}, for agent {NotificationAgent.Mobile}"); return null; } - var playerIds = notificationIds.Select(x => x.PlayerId).ToList(); + var playerIds = notificationIds.Select(x => x.Token).ToList(); return playerIds; } @@ -338,10 +342,11 @@ namespace Ombi.Notifications.Agents { foreach (var user in SubsribedUsers) { - var notificationId = user.NotificationUserIds; - if (notificationId.Any()) + var notificationIds = await _notifications.GetAll().Where(x => x.UserId == user.Id).ToListAsync(); + + if (notificationIds.Any()) { - playerIds.AddRange(notificationId.Select(x => x.PlayerId)); + playerIds.AddRange(notificationIds.Select(x => x.Token)); } } } diff --git a/src/Ombi.Notifications/BaseNotification.cs b/src/Ombi.Notifications/BaseNotification.cs index 465ccd22c..c9404eb2c 100644 --- a/src/Ombi.Notifications/BaseNotification.cs +++ b/src/Ombi.Notifications/BaseNotification.cs @@ -191,7 +191,7 @@ namespace Ombi.Notifications protected IQueryable GetSubscriptions(int requestId, RequestType type) { - var subs = RequestSubscription.GetAll().Include(x => x.User).ThenInclude(x => x.NotificationUserIds).Where(x => x.RequestId == requestId && type == x.RequestType); + var subs = RequestSubscription.GetAll().Include(x => x.User).Where(x => x.RequestId == requestId && type == x.RequestType); return subs.Select(x => x.User); }