mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Fix for #3183
This commit is contained in:
parent
e6a705ffb7
commit
d7b4931030
2 changed files with 32 additions and 4 deletions
|
@ -12,6 +12,7 @@ using Ombi.Notifications.Models;
|
|||
using Ombi.Settings.Settings.Models;
|
||||
using Ombi.Settings.Settings.Models.Notifications;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
|
||||
|
@ -21,13 +22,14 @@ namespace Ombi.Notifications.Agents
|
|||
{
|
||||
public MobileNotification(IOneSignalApi api, ISettingsService<MobileNotificationSettings> sn, ILogger<MobileNotification> log, INotificationTemplatesRepository r,
|
||||
IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<NotificationUserId> notification,
|
||||
UserManager<OmbiUser> um, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
|
||||
UserManager<OmbiUser> um, IRepository<RequestSubscription> sub, IMusicRequestRepository music, IRepository<Issues> issueRepository,
|
||||
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
|
||||
{
|
||||
_api = api;
|
||||
_logger = log;
|
||||
_notifications = notification;
|
||||
_userManager = um;
|
||||
_issueRepository = issueRepository;
|
||||
}
|
||||
|
||||
public override string NotificationName => "MobileNotification";
|
||||
|
@ -36,6 +38,7 @@ namespace Ombi.Notifications.Agents
|
|||
private readonly ILogger<MobileNotification> _logger;
|
||||
private readonly IRepository<NotificationUserId> _notifications;
|
||||
private readonly UserManager<OmbiUser> _userManager;
|
||||
private readonly IRepository<Issues> _issueRepository;
|
||||
|
||||
protected override bool ValidateConfiguration(MobileNotificationSettings settings)
|
||||
{
|
||||
|
@ -95,8 +98,9 @@ namespace Ombi.Notifications.Agents
|
|||
var isAdmin = bool.Parse(isAdminString);
|
||||
if (isAdmin)
|
||||
{
|
||||
model.Substitutes.TryGetValue("IssueId", out var issueId);
|
||||
// Send to user
|
||||
var playerIds = GetUsers(model, NotificationType.IssueComment);
|
||||
var playerIds = await GetUsersForIssue(model, int.Parse(issueId), NotificationType.IssueComment);
|
||||
await Send(playerIds, notification, settings, model);
|
||||
}
|
||||
else
|
||||
|
@ -250,6 +254,7 @@ namespace Ombi.Notifications.Agents
|
|||
}
|
||||
return playerIds;
|
||||
}
|
||||
|
||||
private List<string> GetUsers(NotificationOptions model, NotificationType type)
|
||||
{
|
||||
var notificationIds = new List<NotificationUserId>();
|
||||
|
@ -261,14 +266,36 @@ namespace Ombi.Notifications.Agents
|
|||
}
|
||||
if (model.UserId.HasValue() && (!notificationIds?.Any() ?? true))
|
||||
{
|
||||
var user= _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefault(x => x.Id == model.UserId);
|
||||
var user = _userManager.Users.Include(x => x.NotificationUserIds).FirstOrDefault(x => x.Id == model.UserId);
|
||||
notificationIds = user.NotificationUserIds;
|
||||
}
|
||||
|
||||
if (!notificationIds?.Any() ?? true)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
$"there are no admins to send a notification for {type}, for agent {NotificationAgent.Mobile}");
|
||||
$"there are no users to send a notification for {type}, for agent {NotificationAgent.Mobile}");
|
||||
return null;
|
||||
}
|
||||
var playerIds = notificationIds.Select(x => x.PlayerId).ToList();
|
||||
return playerIds;
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetUsersForIssue(NotificationOptions model, int issueId, NotificationType type)
|
||||
{
|
||||
var notificationIds = new List<NotificationUserId>();
|
||||
|
||||
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);
|
||||
|
||||
notificationIds = userRaised.NotificationUserIds;
|
||||
|
||||
if (!notificationIds?.Any() ?? true)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
$"there are no users to send a notification for {type}, for agent {NotificationAgent.Mobile}");
|
||||
return null;
|
||||
}
|
||||
var playerIds = notificationIds.Select(x => x.PlayerId).ToList();
|
||||
|
|
|
@ -226,6 +226,7 @@ namespace Ombi.Controllers
|
|||
var isAdmin = await _userManager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser;
|
||||
AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported.UserAlias);
|
||||
notificationModel.Substitutes.Add("NewIssueComment", comment.Comment);
|
||||
notificationModel.Substitutes.Add("IssueId", comment.IssueId.ToString());
|
||||
notificationModel.Substitutes.Add("AdminComment", isAdmin.ToString());
|
||||
|
||||
if (isAdmin)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue