Did the notification side of things with the custom user defined preference !wip

pull/2519/head
TidusJar 6 years ago
parent de2e3abfe0
commit 8573b7c729

@ -20,8 +20,9 @@ namespace Ombi.Notifications.Agents
{
public DiscordNotification(IDiscordApi api, ISettingsService<DiscordNotificationSettings> sn,
ILogger<DiscordNotification> log, INotificationTemplatesRepository r,
IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music)
: base(sn, r, m, t, s, log, sub, music)
IMovieRequestRepository m, ITvRequestRepository t, ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref)
: base(sn, r, m, t, s, log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -22,7 +22,8 @@ namespace Ombi.Notifications.Agents
public class EmailNotification : BaseNotification<EmailNotificationSettings>, IEmailNotification
{
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService<CustomizationSettings> c,
ILogger<EmailNotification> log, UserManager<OmbiUser> um, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(settings, r, m, t, c, log, sub, music)
ILogger<EmailNotification> log, UserManager<OmbiUser> um, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(settings, r, m, t, c, log, sub, music, userPref)
{
EmailProvider = prov;
Logger = log;

@ -21,7 +21,8 @@ namespace Ombi.Notifications.Agents
public class MattermostNotification : BaseNotification<MattermostNotificationSettings>, IMattermostNotification
{
public MattermostNotification(IMattermostApi api, ISettingsService<MattermostNotificationSettings> sn, ILogger<MattermostNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(sn, r, m, t, s, log, sub, music)
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -22,7 +22,8 @@ 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) : base(sn, r, m, t, s, log, sub, music)
UserManager<OmbiUser> um, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
{
_api = api;
_logger = log;

@ -17,7 +17,8 @@ namespace Ombi.Notifications.Agents
public class PushbulletNotification : BaseNotification<PushbulletSettings>, IPushbulletNotification
{
public PushbulletNotification(IPushbulletApi api, ISettingsService<PushbulletSettings> sn, ILogger<PushbulletNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(sn, r, m, t, s, log, sub, music)
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -18,7 +18,8 @@ namespace Ombi.Notifications.Agents
public class PushoverNotification : BaseNotification<PushoverSettings>, IPushoverNotification
{
public PushoverNotification(IPushoverApi api, ISettingsService<PushoverSettings> sn, ILogger<PushoverNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(sn, r, m, t, s, log, sub, music)
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -18,7 +18,8 @@ namespace Ombi.Notifications.Agents
public class SlackNotification : BaseNotification<SlackNotificationSettings>, ISlackNotification
{
public SlackNotification(ISlackApi api, ISettingsService<SlackNotificationSettings> sn, ILogger<SlackNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(sn, r, m, t, s, log, sub, music)
ISettingsService<CustomizationSettings> s, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -19,7 +19,8 @@ namespace Ombi.Notifications.Agents
public TelegramNotification(ITelegramApi api, ISettingsService<TelegramSettings> sn, ILogger<TelegramNotification> log,
INotificationTemplatesRepository r, IMovieRequestRepository m,
ITvRequestRepository t, ISettingsService<CustomizationSettings> s
, IRepository<RequestSubscription> sub, IMusicRequestRepository music) : base(sn, r, m, t,s,log, sub, music)
, IRepository<RequestSubscription> sub, IMusicRequestRepository music,
IRepository<UserNotificationPreferences> userPref) : base(sn, r, m, t,s,log, sub, music, userPref)
{
Api = api;
Logger = log;

@ -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);

@ -14,9 +14,10 @@ namespace Ombi.Notifications
{
public class NotificationMessageCurlys
{
public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s)
public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s, UserNotificationPreferences pref)
{
LoadIssues(opts);
UserPreference = pref.Enabled ? pref.Value : string.Empty;
string title;
if (req == null)
{
@ -58,9 +59,10 @@ namespace Ombi.Notifications
AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
}
public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s)
public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s, UserNotificationPreferences pref)
{
LoadIssues(opts);
UserPreference = pref.Enabled ? pref.Value : string.Empty;
string title;
if (req == null)
{
@ -101,9 +103,10 @@ namespace Ombi.Notifications
Alias = username.Alias.HasValue() ? username.Alias : username.UserName;
}
public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s)
public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s, UserNotificationPreferences pref)
{
LoadIssues(opts);
UserPreference = pref.Enabled ? pref.Value : string.Empty;
string title;
if (req == null)
{
@ -221,6 +224,7 @@ namespace Ombi.Notifications
public string IssueStatus { get; set; }
public string IssueSubject { get; set; }
public string NewIssueComment { get; set; }
public string UserPreference { get; set; }
// System Defined
private string LongDate => DateTime.Now.ToString("D");

@ -7,8 +7,6 @@ import { ConfirmationService, ConfirmDialogModule, MultiSelectModule, SidebarMod
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { UpdateDetailsComponent } from "./updatedetails.component";
import { UserManagementAddComponent } from "./usermanagement-add.component";
import { UserManagementEditComponent } from "./usermanagement-edit.component";
import { UserManagementComponent } from "./usermanagement.component";
import { UserManagementUserComponent } from "./usermanagement-user.component";
@ -22,7 +20,6 @@ import { AddPlexUserComponent } from "./addplexuser.component";
const routes: Routes = [
{ path: "", component: UserManagementComponent, canActivate: [AuthGuard] },
{ path: "add", component: UserManagementAddComponent, canActivate: [AuthGuard] },
{ path: "user", component: UserManagementUserComponent, canActivate: [AuthGuard] },
{ path: "updatedetails", component: UpdateDetailsComponent, canActivate: [AuthGuard] },
];

@ -8,7 +8,7 @@
<FileVersion>$(SemVer)</FileVersion>
<Version>$(FullVer)</Version>
<PackageVersion></PackageVersion>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<TypeScriptToolsVersion>3.0</TypeScriptToolsVersion>
</PropertyGroup>
<PropertyGroup>
<ServerGarbageCollection>false</ServerGarbageCollection>

Loading…
Cancel
Save