mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 17:22:54 -07:00
Did the notification side of things with the custom user defined preference !wip
This commit is contained in:
parent
de2e3abfe0
commit
8573b7c729
12 changed files with 41 additions and 22 deletions
|
@ -19,7 +19,8 @@ namespace Ombi.Notifications.Interfaces
|
|||
public abstract class BaseNotification<T> : INotification where T : Settings.Settings.Models.Settings, new()
|
||||
{
|
||||
protected BaseNotification(ISettingsService<T> settings, INotificationTemplatesRepository templateRepo, IMovieRequestRepository movie, ITvRequestRepository tv,
|
||||
ISettingsService<CustomizationSettings> customization, ILogger<BaseNotification<T>> log, IRepository<RequestSubscription> sub, IMusicRequestRepository album)
|
||||
ISettingsService<CustomizationSettings> customization, ILogger<BaseNotification<T>> log, IRepository<RequestSubscription> sub, IMusicRequestRepository album,
|
||||
IRepository<UserNotificationPreferences> notificationUserPreferences)
|
||||
{
|
||||
Settings = settings;
|
||||
TemplateRepository = templateRepo;
|
||||
|
@ -31,6 +32,7 @@ namespace Ombi.Notifications.Interfaces
|
|||
RequestSubscription = sub;
|
||||
_log = log;
|
||||
AlbumRepository = album;
|
||||
UserNotificationPreferences = notificationUserPreferences;
|
||||
}
|
||||
|
||||
protected ISettingsService<T> Settings { get; }
|
||||
|
@ -40,6 +42,7 @@ namespace Ombi.Notifications.Interfaces
|
|||
protected IMusicRequestRepository AlbumRepository { get; }
|
||||
protected CustomizationSettings Customization { get; set; }
|
||||
protected IRepository<RequestSubscription> RequestSubscription { get; set; }
|
||||
protected IRepository<UserNotificationPreferences> UserNotificationPreferences { get; set; }
|
||||
private ISettingsService<CustomizationSettings> CustomizationSettings { get; }
|
||||
private readonly ILogger<BaseNotification<T>> _log;
|
||||
|
||||
|
@ -167,7 +170,7 @@ namespace Ombi.Notifications.Interfaces
|
|||
{
|
||||
return new NotificationMessageContent { Disabled = true };
|
||||
}
|
||||
var parsed = Parse(model, template);
|
||||
var parsed = Parse(model, template, agent);
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
@ -178,25 +181,32 @@ namespace Ombi.Notifications.Interfaces
|
|||
return subs.Select(x => x.User);
|
||||
}
|
||||
|
||||
private NotificationMessageContent Parse(NotificationOptions model, NotificationTemplates template)
|
||||
protected UserNotificationPreferences GetUserPreference(string userId, NotificationAgent agent)
|
||||
{
|
||||
return UserNotificationPreferences.GetAll()
|
||||
.FirstOrDefault(x => x.Enabled && x.Agent == agent && x.UserId == userId);
|
||||
}
|
||||
|
||||
private NotificationMessageContent Parse(NotificationOptions model, NotificationTemplates template, NotificationAgent agent)
|
||||
{
|
||||
var resolver = new NotificationMessageResolver();
|
||||
var curlys = new NotificationMessageCurlys();
|
||||
var preference = GetUserPreference(model.UserId, agent);
|
||||
if (model.RequestType == RequestType.Movie)
|
||||
{
|
||||
_log.LogDebug("Notification options: {@model}, Req: {@MovieRequest}, Settings: {@Customization}", model, MovieRequest, Customization);
|
||||
|
||||
curlys.Setup(model, MovieRequest, Customization);
|
||||
curlys.Setup(model, MovieRequest, Customization, preference);
|
||||
}
|
||||
else if (model.RequestType == RequestType.TvShow)
|
||||
{
|
||||
_log.LogDebug("Notification options: {@model}, Req: {@TvRequest}, Settings: {@Customization}", model, TvRequest, Customization);
|
||||
curlys.Setup(model, TvRequest, Customization);
|
||||
curlys.Setup(model, TvRequest, Customization, preference);
|
||||
}
|
||||
else if (model.RequestType == RequestType.Album)
|
||||
{
|
||||
_log.LogDebug("Notification options: {@model}, Req: {@AlbumRequest}, Settings: {@Customization}", model, AlbumRequest, Customization);
|
||||
curlys.Setup(model, AlbumRequest, Customization);
|
||||
curlys.Setup(model, AlbumRequest, Customization, preference);
|
||||
}
|
||||
var parsed = resolver.ParseMessage(template, curlys);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue