From 6da9868716264e8ae6bf1a217e5de1df346fd283 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 18 Nov 2018 22:21:12 -0500 Subject: [PATCH] New: Added priority levels to Join Notifications --- src/NzbDrone.Core/Notifications/Join/JoinPriority.cs | 11 +++++++++++ src/NzbDrone.Core/Notifications/Join/JoinProxy.cs | 5 +++-- src/NzbDrone.Core/Notifications/Join/JoinSettings.cs | 8 ++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/NzbDrone.Core/Notifications/Join/JoinPriority.cs diff --git a/src/NzbDrone.Core/Notifications/Join/JoinPriority.cs b/src/NzbDrone.Core/Notifications/Join/JoinPriority.cs new file mode 100644 index 000000000..9f2cab16f --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Join/JoinPriority.cs @@ -0,0 +1,11 @@ +namespace NzbDrone.Core.Notifications.Join +{ + public enum JoinPriority + { + Silent = -2, + Quiet = -1, + Normal = 0, + High = 1, + Emergency = 2 + } +} diff --git a/src/NzbDrone.Core/Notifications/Join/JoinProxy.cs b/src/NzbDrone.Core/Notifications/Join/JoinProxy.cs index 0b989cc36..50ee7b981 100644 --- a/src/NzbDrone.Core/Notifications/Join/JoinProxy.cs +++ b/src/NzbDrone.Core/Notifications/Join/JoinProxy.cs @@ -88,12 +88,13 @@ namespace NzbDrone.Core.Notifications.Join { request.AddParameter("deviceId", "group.all"); } - + request.AddParameter("apikey", settings.ApiKey); request.AddParameter("title", title); request.AddParameter("text", message); request.AddParameter("icon", "https://cdn.rawgit.com/Lidarr/Lidarr/develop/Logo/256.png"); // Use the Lidarr logo. request.AddParameter("smallicon", "https://cdn.rawgit.com/Lidarr/Lidarr/develop/Logo/96-Outline-White.png"); // 96x96px with outline at 88x88px on a transparent background. + request.AddParameter("priority", settings.Priority); var response = client.ExecuteAndValidate(request); var res = Json.Deserialize(response.Content); @@ -114,7 +115,7 @@ namespace NzbDrone.Core.Notifications.Join throw new JoinInvalidDeviceException(res.errorMessage); } // Oddly enough, rather than give us an "Invalid API key", the Join API seems to assume the key is valid, - // but fails when doing a device lookup associated with that key. + // but fails when doing a device lookup associated with that key. // In our case we are using "deviceIds" rather than "deviceId" so when the singular form error shows up // we know the API key was the fault. else if (res.errorMessage.Equals("No device to send message to")) diff --git a/src/NzbDrone.Core/Notifications/Join/JoinSettings.cs b/src/NzbDrone.Core/Notifications/Join/JoinSettings.cs index ac305867f..db5c8550a 100644 --- a/src/NzbDrone.Core/Notifications/Join/JoinSettings.cs +++ b/src/NzbDrone.Core/Notifications/Join/JoinSettings.cs @@ -16,6 +16,11 @@ namespace NzbDrone.Core.Notifications.Join public class JoinSettings : IProviderConfig { + public JoinSettings() + { + Priority = (int)JoinPriority.Normal; + } + private static readonly JoinSettingsValidator Validator = new JoinSettingsValidator(); [FieldDefinition(0, Label = "API Key", HelpText = "The API Key from your Join account settings (click Join API button).", HelpLink = "https://joinjoaomgcd.appspot.com/")] @@ -27,6 +32,9 @@ namespace NzbDrone.Core.Notifications.Join [FieldDefinition(2, Label = "Device Names", HelpText = "Comma separated list of full or partial device names you'd like to send notifications to. If unset, all devices will receive notifications.", HelpLink = "https://joaoapps.com/join/api/")] public string DeviceNames { get; set; } + [FieldDefinition(3, Label = "Notification Priority", Type = FieldType.Select, SelectOptions = typeof(JoinPriority))] + public int Priority { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 362e30a6c..7347bc215 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -884,6 +884,7 @@ +