mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
This commit is contained in:
parent
96f27f8f1a
commit
f76e54408e
6 changed files with 458 additions and 428 deletions
|
@ -36,6 +36,7 @@ using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
|
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
|
||||||
|
using PlexRequests.Store;
|
||||||
|
|
||||||
namespace PlexRequests.Services.Notification
|
namespace PlexRequests.Services.Notification
|
||||||
{
|
{
|
||||||
|
@ -119,8 +120,8 @@ namespace PlexRequests.Services.Notification
|
||||||
{
|
{
|
||||||
var message = new MimeMessage
|
var message = new MimeMessage
|
||||||
{
|
{
|
||||||
Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested {model.Title}! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" },
|
Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" },
|
||||||
Subject = $"Plex Requests: New request for {model.Title}!"
|
Subject = $"Plex Requests: New {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} request for {model.Title}!"
|
||||||
};
|
};
|
||||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||||
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
||||||
|
|
|
@ -1,40 +1,42 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: NotificationModel.cs
|
// File: NotificationModel.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using PlexRequests.Store;
|
||||||
|
using System;
|
||||||
namespace PlexRequests.Services.Notification
|
|
||||||
{
|
namespace PlexRequests.Services.Notification
|
||||||
public class NotificationModel
|
{
|
||||||
{
|
public class NotificationModel
|
||||||
public string Title { get; set; }
|
{
|
||||||
public string Body { get; set; }
|
public string Title { get; set; }
|
||||||
public DateTime DateTime { get; set; }
|
public string Body { get; set; }
|
||||||
public NotificationType NotificationType { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
public string User { get; set; }
|
public NotificationType NotificationType { get; set; }
|
||||||
public string UserEmail { get; set; }
|
public string User { get; set; }
|
||||||
}
|
public string UserEmail { get; set; }
|
||||||
|
public RequestType RequestType { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,142 +1,143 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: PushbulletNotification.cs
|
// File: PushbulletNotification.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using PlexRequests.Store;
|
||||||
namespace PlexRequests.Services.Notification
|
|
||||||
{
|
namespace PlexRequests.Services.Notification
|
||||||
public class PushbulletNotification : INotification
|
{
|
||||||
{
|
public class PushbulletNotification : INotification
|
||||||
public PushbulletNotification(IPushbulletApi pushbulletApi, ISettingsService<PushbulletNotificationSettings> settings)
|
{
|
||||||
{
|
public PushbulletNotification(IPushbulletApi pushbulletApi, ISettingsService<PushbulletNotificationSettings> settings)
|
||||||
PushbulletApi = pushbulletApi;
|
{
|
||||||
SettingsService = settings;
|
PushbulletApi = pushbulletApi;
|
||||||
}
|
SettingsService = settings;
|
||||||
private IPushbulletApi PushbulletApi { get; }
|
}
|
||||||
private ISettingsService<PushbulletNotificationSettings> SettingsService { get; }
|
private IPushbulletApi PushbulletApi { get; }
|
||||||
|
private ISettingsService<PushbulletNotificationSettings> SettingsService { get; }
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
||||||
public string NotificationName => "PushbulletNotification";
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
public async Task NotifyAsync(NotificationModel model)
|
public string NotificationName => "PushbulletNotification";
|
||||||
{
|
public async Task NotifyAsync(NotificationModel model)
|
||||||
var configuration = GetSettings();
|
{
|
||||||
await NotifyAsync(model, configuration);
|
var configuration = GetSettings();
|
||||||
}
|
await NotifyAsync(model, configuration);
|
||||||
|
}
|
||||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
|
||||||
{
|
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||||
if (settings == null) await NotifyAsync(model);
|
{
|
||||||
|
if (settings == null) await NotifyAsync(model);
|
||||||
var pushSettings = (PushbulletNotificationSettings)settings;
|
|
||||||
|
var pushSettings = (PushbulletNotificationSettings)settings;
|
||||||
if (!ValidateConfiguration(pushSettings)) return;
|
|
||||||
|
if (!ValidateConfiguration(pushSettings)) return;
|
||||||
switch (model.NotificationType)
|
|
||||||
{
|
switch (model.NotificationType)
|
||||||
case NotificationType.NewRequest:
|
{
|
||||||
await PushNewRequestAsync(model, pushSettings);
|
case NotificationType.NewRequest:
|
||||||
break;
|
await PushNewRequestAsync(model, pushSettings);
|
||||||
case NotificationType.Issue:
|
break;
|
||||||
await PushIssueAsync(model, pushSettings);
|
case NotificationType.Issue:
|
||||||
break;
|
await PushIssueAsync(model, pushSettings);
|
||||||
case NotificationType.RequestAvailable:
|
break;
|
||||||
break;
|
case NotificationType.RequestAvailable:
|
||||||
case NotificationType.RequestApproved:
|
break;
|
||||||
break;
|
case NotificationType.RequestApproved:
|
||||||
case NotificationType.AdminNote:
|
break;
|
||||||
break;
|
case NotificationType.AdminNote:
|
||||||
case NotificationType.Test:
|
break;
|
||||||
await PushTestAsync(pushSettings);
|
case NotificationType.Test:
|
||||||
break;
|
await PushTestAsync(pushSettings);
|
||||||
default:
|
break;
|
||||||
throw new ArgumentOutOfRangeException();
|
default:
|
||||||
}
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private bool ValidateConfiguration(PushbulletNotificationSettings settings)
|
|
||||||
{
|
private bool ValidateConfiguration(PushbulletNotificationSettings settings)
|
||||||
if (!settings.Enabled)
|
{
|
||||||
{
|
if (!settings.Enabled)
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
if (string.IsNullOrEmpty(settings.AccessToken))
|
}
|
||||||
{
|
if (string.IsNullOrEmpty(settings.AccessToken))
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private PushbulletNotificationSettings GetSettings()
|
|
||||||
{
|
private PushbulletNotificationSettings GetSettings()
|
||||||
return SettingsService.GetSettings();
|
{
|
||||||
}
|
return SettingsService.GetSettings();
|
||||||
|
}
|
||||||
private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
|
||||||
{
|
private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
||||||
var message = $"{model.Title} has been requested by user: {model.User}";
|
{
|
||||||
var pushTitle = $"Plex Requests: {model.Title} has been requested!";
|
var message = $"The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
|
||||||
await Push(settings, message, pushTitle);
|
var pushTitle = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} {model.Title} has been requested!";
|
||||||
}
|
await Push(settings, message, pushTitle);
|
||||||
|
}
|
||||||
private async Task PushIssueAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
|
||||||
{
|
private async Task PushIssueAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
||||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
{
|
||||||
var pushTitle = $"Plex Requests: A new issue has been reported for {model.Title}";
|
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||||
await Push(settings, message, pushTitle);
|
var pushTitle = $"Plex Requests: A new issue has been reported for {model.Title}";
|
||||||
}
|
await Push(settings, message, pushTitle);
|
||||||
|
}
|
||||||
private async Task PushTestAsync(PushbulletNotificationSettings settings)
|
|
||||||
{
|
private async Task PushTestAsync(PushbulletNotificationSettings settings)
|
||||||
var message = "This is just a test! Success!";
|
{
|
||||||
var pushTitle = "Plex Requests: Test Message!";
|
var message = "This is just a test! Success!";
|
||||||
await Push(settings, message, pushTitle);
|
var pushTitle = "Plex Requests: Test Message!";
|
||||||
}
|
await Push(settings, message, pushTitle);
|
||||||
|
}
|
||||||
private async Task Push(PushbulletNotificationSettings settings, string message, string title)
|
|
||||||
{
|
private async Task Push(PushbulletNotificationSettings settings, string message, string title)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
var result = await PushbulletApi.PushAsync(settings.AccessToken, title, message, settings.DeviceIdentifier);
|
{
|
||||||
if (result != null)
|
var result = await PushbulletApi.PushAsync(settings.AccessToken, title, message, settings.DeviceIdentifier);
|
||||||
{
|
if (result != null)
|
||||||
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
{
|
||||||
}
|
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
Log.Error(e);
|
{
|
||||||
}
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,139 +1,140 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: PushbulletNotification.cs
|
// File: PushbulletNotification.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
|
using PlexRequests.Store;
|
||||||
namespace PlexRequests.Services.Notification
|
|
||||||
{
|
namespace PlexRequests.Services.Notification
|
||||||
public class PushoverNotification : INotification
|
{
|
||||||
{
|
public class PushoverNotification : INotification
|
||||||
public PushoverNotification(IPushoverApi pushoverApi, ISettingsService<PushoverNotificationSettings> settings)
|
{
|
||||||
{
|
public PushoverNotification(IPushoverApi pushoverApi, ISettingsService<PushoverNotificationSettings> settings)
|
||||||
PushoverApi = pushoverApi;
|
{
|
||||||
SettingsService = settings;
|
PushoverApi = pushoverApi;
|
||||||
}
|
SettingsService = settings;
|
||||||
private IPushoverApi PushoverApi { get; }
|
}
|
||||||
private ISettingsService<PushoverNotificationSettings> SettingsService { get; }
|
private IPushoverApi PushoverApi { get; }
|
||||||
|
private ISettingsService<PushoverNotificationSettings> SettingsService { get; }
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
||||||
public string NotificationName => "PushoverNotification";
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
public async Task NotifyAsync(NotificationModel model)
|
public string NotificationName => "PushoverNotification";
|
||||||
{
|
public async Task NotifyAsync(NotificationModel model)
|
||||||
var configuration = GetSettings();
|
{
|
||||||
await NotifyAsync(model, configuration);
|
var configuration = GetSettings();
|
||||||
}
|
await NotifyAsync(model, configuration);
|
||||||
|
}
|
||||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
|
||||||
{
|
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||||
if (settings == null) await NotifyAsync(model);
|
{
|
||||||
|
if (settings == null) await NotifyAsync(model);
|
||||||
var pushSettings = (PushoverNotificationSettings)settings;
|
|
||||||
|
var pushSettings = (PushoverNotificationSettings)settings;
|
||||||
if (!ValidateConfiguration(pushSettings)) return;
|
|
||||||
|
if (!ValidateConfiguration(pushSettings)) return;
|
||||||
switch (model.NotificationType)
|
|
||||||
{
|
switch (model.NotificationType)
|
||||||
case NotificationType.NewRequest:
|
{
|
||||||
await PushNewRequestAsync(model, pushSettings);
|
case NotificationType.NewRequest:
|
||||||
break;
|
await PushNewRequestAsync(model, pushSettings);
|
||||||
case NotificationType.Issue:
|
break;
|
||||||
await PushIssueAsync(model, pushSettings);
|
case NotificationType.Issue:
|
||||||
break;
|
await PushIssueAsync(model, pushSettings);
|
||||||
case NotificationType.RequestAvailable:
|
break;
|
||||||
break;
|
case NotificationType.RequestAvailable:
|
||||||
case NotificationType.RequestApproved:
|
break;
|
||||||
break;
|
case NotificationType.RequestApproved:
|
||||||
case NotificationType.AdminNote:
|
break;
|
||||||
break;
|
case NotificationType.AdminNote:
|
||||||
case NotificationType.Test:
|
break;
|
||||||
await PushTestAsync(model, pushSettings);
|
case NotificationType.Test:
|
||||||
break;
|
await PushTestAsync(model, pushSettings);
|
||||||
default:
|
break;
|
||||||
throw new ArgumentOutOfRangeException();
|
default:
|
||||||
}
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private bool ValidateConfiguration(PushoverNotificationSettings settings)
|
|
||||||
{
|
private bool ValidateConfiguration(PushoverNotificationSettings settings)
|
||||||
if (!settings.Enabled)
|
{
|
||||||
{
|
if (!settings.Enabled)
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
if (string.IsNullOrEmpty(settings.AccessToken) || string.IsNullOrEmpty(settings.UserToken))
|
}
|
||||||
{
|
if (string.IsNullOrEmpty(settings.AccessToken) || string.IsNullOrEmpty(settings.UserToken))
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
private PushoverNotificationSettings GetSettings()
|
|
||||||
{
|
private PushoverNotificationSettings GetSettings()
|
||||||
return SettingsService.GetSettings();
|
{
|
||||||
}
|
return SettingsService.GetSettings();
|
||||||
|
}
|
||||||
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
|
||||||
{
|
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||||
var message = $"Plex Requests: {model.Title} has been requested by user: {model.User}";
|
{
|
||||||
await Push(settings, message);
|
var message = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
|
||||||
}
|
await Push(settings, message);
|
||||||
|
}
|
||||||
private async Task PushIssueAsync(NotificationModel model, PushoverNotificationSettings settings)
|
|
||||||
{
|
private async Task PushIssueAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||||
var message = $"Plex Requests: A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
{
|
||||||
await Push(settings, message);
|
var message = $"Plex Requests: A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||||
}
|
await Push(settings, message);
|
||||||
|
}
|
||||||
private async Task PushTestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
|
||||||
{
|
private async Task PushTestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||||
var message = $"Plex Requests: Test Message!";
|
{
|
||||||
await Push(settings, message);
|
var message = $"Plex Requests: Test Message!";
|
||||||
}
|
await Push(settings, message);
|
||||||
|
}
|
||||||
private async Task Push(PushoverNotificationSettings settings, string message)
|
|
||||||
{
|
private async Task Push(PushoverNotificationSettings settings, string message)
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
var result = await PushoverApi.PushAsync(settings.AccessToken, message, settings.UserToken);
|
{
|
||||||
if (result?.status != 1)
|
var result = await PushoverApi.PushAsync(settings.AccessToken, message, settings.UserToken);
|
||||||
{
|
if (result?.status != 1)
|
||||||
Log.Error("Pushover api returned a status that was not 1, the notification did not get pushed");
|
{
|
||||||
}
|
Log.Error("Pushover api returned a status that was not 1, the notification did not get pushed");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
Log.Error(e);
|
{
|
||||||
}
|
Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,90 +1,108 @@
|
||||||
using System;
|
using System;
|
||||||
using Dapper.Contrib.Extensions;
|
using Dapper.Contrib.Extensions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace PlexRequests.Store
|
namespace PlexRequests.Store
|
||||||
{
|
{
|
||||||
[Table("Requested")]
|
[Table("Requested")]
|
||||||
public class RequestedModel : Entity
|
public class RequestedModel : Entity
|
||||||
{
|
{
|
||||||
public RequestedModel()
|
public RequestedModel()
|
||||||
{
|
{
|
||||||
RequestedUsers = new List<string>();
|
RequestedUsers = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once IdentifierTypo
|
// ReSharper disable once IdentifierTypo
|
||||||
public int ProviderId { get; set; }
|
public int ProviderId { get; set; }
|
||||||
public string ImdbId { get; set; }
|
public string ImdbId { get; set; }
|
||||||
public string TvDbId { get; set; }
|
public string TvDbId { get; set; }
|
||||||
public string Overview { get; set; }
|
public string Overview { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string PosterPath { get; set; }
|
public string PosterPath { get; set; }
|
||||||
public DateTime ReleaseDate { get; set; }
|
public DateTime ReleaseDate { get; set; }
|
||||||
public RequestType Type { get; set; }
|
public RequestType Type { get; set; }
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
public bool Approved { get; set; }
|
public bool Approved { get; set; }
|
||||||
|
|
||||||
[Obsolete("Use RequestedUsers")]
|
[Obsolete("Use RequestedUsers")]
|
||||||
public string RequestedBy { get; set; }
|
public string RequestedBy { get; set; }
|
||||||
|
|
||||||
public DateTime RequestedDate { get; set; }
|
public DateTime RequestedDate { get; set; }
|
||||||
public bool Available { get; set; }
|
public bool Available { get; set; }
|
||||||
public IssueState Issues { get; set; }
|
public IssueState Issues { get; set; }
|
||||||
public string OtherMessage { get; set; }
|
public string OtherMessage { get; set; }
|
||||||
public string AdminNote { get; set; }
|
public string AdminNote { get; set; }
|
||||||
public int[] SeasonList { get; set; }
|
public int[] SeasonList { get; set; }
|
||||||
public int SeasonCount { get; set; }
|
public int SeasonCount { get; set; }
|
||||||
public string SeasonsRequested { get; set; }
|
public string SeasonsRequested { get; set; }
|
||||||
public string MusicBrainzId { get; set; }
|
public string MusicBrainzId { get; set; }
|
||||||
public List<string> RequestedUsers { get; set; }
|
public List<string> RequestedUsers { get; set; }
|
||||||
public string ArtistName { get; set; }
|
public string ArtistName { get; set; }
|
||||||
public string ArtistId { get; set; }
|
public string ArtistId { get; set; }
|
||||||
public int IssueId { get; set; }
|
public int IssueId { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public List<string> AllUsers
|
public List<string> AllUsers
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var u = new List<string>();
|
var u = new List<string>();
|
||||||
if (!string.IsNullOrEmpty(RequestedBy))
|
if (!string.IsNullOrEmpty(RequestedBy))
|
||||||
{
|
{
|
||||||
u.Add(RequestedBy);
|
u.Add(RequestedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RequestedUsers.Any())
|
if (RequestedUsers.Any())
|
||||||
{
|
{
|
||||||
u.AddRange(RequestedUsers.Where(requestedUser => requestedUser != RequestedBy));
|
u.AddRange(RequestedUsers.Where(requestedUser => requestedUser != RequestedBy));
|
||||||
}
|
}
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool CanApprove => !Approved && !Available;
|
public bool CanApprove => !Approved && !Available;
|
||||||
|
|
||||||
public bool UserHasRequested(string username)
|
public bool UserHasRequested(string username)
|
||||||
{
|
{
|
||||||
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
|
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RequestType
|
public enum RequestType
|
||||||
{
|
{
|
||||||
Movie,
|
Movie,
|
||||||
TvShow,
|
TvShow,
|
||||||
Album
|
Album
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum IssueState
|
public static class RequestTypeDisplay
|
||||||
{
|
{
|
||||||
None = 99,
|
public static string Get(RequestType type)
|
||||||
WrongAudio = 0,
|
{
|
||||||
NoSubtitles = 1,
|
switch (type)
|
||||||
WrongContent = 2,
|
{
|
||||||
PlaybackIssues = 3,
|
case RequestType.Movie:
|
||||||
Other = 4, // Provide a message
|
return "Movie";
|
||||||
}
|
case RequestType.TvShow:
|
||||||
}
|
return "TV Show";
|
||||||
|
case RequestType.Album:
|
||||||
|
return "Album";
|
||||||
|
default:
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum IssueState
|
||||||
|
{
|
||||||
|
None = 99,
|
||||||
|
WrongAudio = 0,
|
||||||
|
NoSubtitles = 1,
|
||||||
|
WrongContent = 2,
|
||||||
|
PlaybackIssues = 3,
|
||||||
|
Other = 4, // Provide a message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -488,14 +488,15 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Info("Adding movie to database (No approval required)");
|
Log.Info("Adding movie to database (No approval required)");
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.Movie, settings))
|
||||||
{
|
{
|
||||||
var notificationModel = new NotificationModel
|
var notificationModel = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.Movie
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notificationModel);
|
await NotificationService.Publish(notificationModel);
|
||||||
}
|
}
|
||||||
|
@ -515,14 +516,15 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Info("Adding movie to database (No approval required)");
|
Log.Info("Adding movie to database (No approval required)");
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.Movie, settings))
|
||||||
{
|
{
|
||||||
var notificationModel = new NotificationModel
|
var notificationModel = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.Movie
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notificationModel);
|
await NotificationService.Publish(notificationModel);
|
||||||
}
|
}
|
||||||
|
@ -536,7 +538,7 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Info("Adding movie to database");
|
Log.Info("Adding movie to database");
|
||||||
var id = await RequestService.AddRequestAsync(model);
|
var id = await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
var notificationModel = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
|
var notificationModel = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest, RequestType = RequestType.Movie };
|
||||||
await NotificationService.Publish(notificationModel);
|
await NotificationService.Publish(notificationModel);
|
||||||
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" });
|
||||||
|
@ -663,14 +665,15 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
|
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.TvShow, settings))
|
||||||
{
|
{
|
||||||
var notify1 = new NotificationModel
|
var notify1 = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.TvShow
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notify1);
|
await NotificationService.Publish(notify1);
|
||||||
}
|
}
|
||||||
|
@ -691,14 +694,15 @@ namespace PlexRequests.UI.Modules
|
||||||
model.Approved = true;
|
model.Approved = true;
|
||||||
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
|
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.TvShow, settings))
|
||||||
{
|
{
|
||||||
var notify2 = new NotificationModel
|
var notify2 = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.TvShow
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notify2);
|
await NotificationService.Publish(notify2);
|
||||||
}
|
}
|
||||||
|
@ -713,14 +717,15 @@ namespace PlexRequests.UI.Modules
|
||||||
model.Approved = true;
|
model.Approved = true;
|
||||||
Log.Debug("Adding tv to database requests (No approval required) and Sonarr/Sickrage not setup");
|
Log.Debug("Adding tv to database requests (No approval required) and Sonarr/Sickrage not setup");
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.TvShow, settings))
|
||||||
{
|
{
|
||||||
var notify2 = new NotificationModel
|
var notify2 = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.TvShow
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notify2);
|
await NotificationService.Publish(notify2);
|
||||||
}
|
}
|
||||||
|
@ -733,15 +738,15 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
var notificationModel = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
|
var notificationModel = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest, RequestType = RequestType.TvShow };
|
||||||
await NotificationService.Publish(notificationModel);
|
await NotificationService.Publish(notificationModel);
|
||||||
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
|
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldSendNotification(PlexRequestSettings prSettings)
|
private bool ShouldSendNotification(RequestType type, PlexRequestSettings prSettings)
|
||||||
{
|
{
|
||||||
var sendNotification = !prSettings.IgnoreNotifyForAutoApprovedRequests;
|
var sendNotification = ShouldAutoApprove(type, prSettings) ? !prSettings.IgnoreNotifyForAutoApprovedRequests : true;
|
||||||
var claims = Context.CurrentUser?.Claims;
|
var claims = Context.CurrentUser?.Claims;
|
||||||
if (claims != null)
|
if (claims != null)
|
||||||
{
|
{
|
||||||
|
@ -838,14 +843,15 @@ namespace PlexRequests.UI.Modules
|
||||||
model.Approved = true;
|
model.Approved = true;
|
||||||
await RequestService.AddRequestAsync(model);
|
await RequestService.AddRequestAsync(model);
|
||||||
|
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.Album, settings))
|
||||||
{
|
{
|
||||||
var notify2 = new NotificationModel
|
var notify2 = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.Album
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notify2);
|
await NotificationService.Publish(notify2);
|
||||||
}
|
}
|
||||||
|
@ -858,14 +864,15 @@ namespace PlexRequests.UI.Modules
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShouldSendNotification(settings))
|
if (ShouldSendNotification(RequestType.Album, settings))
|
||||||
{
|
{
|
||||||
var notify2 = new NotificationModel
|
var notify2 = new NotificationModel
|
||||||
{
|
{
|
||||||
Title = model.Title,
|
Title = model.Title,
|
||||||
User = Username,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
DateTime = DateTime.Now,
|
||||||
NotificationType = NotificationType.NewRequest
|
NotificationType = NotificationType.NewRequest,
|
||||||
|
RequestType = RequestType.Album
|
||||||
};
|
};
|
||||||
await NotificationService.Publish(notify2);
|
await NotificationService.Publish(notify2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue