|
|
|
@ -51,18 +51,25 @@ namespace PlexRequests.Services.Notification
|
|
|
|
|
public string NotificationName => "PushbulletNotification";
|
|
|
|
|
public async Task NotifyAsync(NotificationModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!ValidateConfiguration())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var configuration = GetSettings();
|
|
|
|
|
await NotifyAsync(model, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
|
|
|
|
{
|
|
|
|
|
if (settings == null) await NotifyAsync(model);
|
|
|
|
|
|
|
|
|
|
var pushSettings = (PushbulletNotificationSettings)settings;
|
|
|
|
|
|
|
|
|
|
if (!ValidateConfiguration(pushSettings)) return;
|
|
|
|
|
|
|
|
|
|
switch (model.NotificationType)
|
|
|
|
|
{
|
|
|
|
|
case NotificationType.NewRequest:
|
|
|
|
|
await PushNewRequestAsync(model);
|
|
|
|
|
await PushNewRequestAsync(model, pushSettings);
|
|
|
|
|
break;
|
|
|
|
|
case NotificationType.Issue:
|
|
|
|
|
await PushIssueAsync(model);
|
|
|
|
|
await PushIssueAsync(model, pushSettings);
|
|
|
|
|
break;
|
|
|
|
|
case NotificationType.RequestAvailable:
|
|
|
|
|
break;
|
|
|
|
@ -70,18 +77,21 @@ namespace PlexRequests.Services.Notification
|
|
|
|
|
break;
|
|
|
|
|
case NotificationType.AdminNote:
|
|
|
|
|
break;
|
|
|
|
|
case NotificationType.Test:
|
|
|
|
|
await PushTestAsync(model, pushSettings);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateConfiguration()
|
|
|
|
|
private bool ValidateConfiguration(PushbulletNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
if (!Settings.Enabled)
|
|
|
|
|
if (!settings.Enabled)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(Settings.AccessToken))
|
|
|
|
|
if (string.IsNullOrEmpty(settings.AccessToken))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -93,13 +103,13 @@ namespace PlexRequests.Services.Notification
|
|
|
|
|
return SettingsService.GetSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task PushNewRequestAsync(NotificationModel model)
|
|
|
|
|
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!";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await PushbulletApi.PushAsync(Settings.AccessToken, pushTitle, message, Settings.DeviceIdentifier);
|
|
|
|
|
var result = await PushbulletApi.PushAsync(settings.AccessToken, pushTitle, message, settings.DeviceIdentifier);
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
|
|
|
@ -111,13 +121,13 @@ namespace PlexRequests.Services.Notification
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task PushIssueAsync(NotificationModel model)
|
|
|
|
|
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}";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await PushbulletApi.PushAsync(Settings.AccessToken, pushTitle, message, Settings.DeviceIdentifier);
|
|
|
|
|
var result = await PushbulletApi.PushAsync(settings.AccessToken, pushTitle, message, settings.DeviceIdentifier);
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
|
|
|
@ -129,9 +139,22 @@ namespace PlexRequests.Services.Notification
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task NotifyAsync(NotificationModel model, Settings settings)
|
|
|
|
|
private async Task PushTestAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
var message = "This is just a test! Success!";
|
|
|
|
|
var pushTitle = "Plex Requests: Test Message!";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await PushbulletApi.PushAsync(settings.AccessToken, pushTitle, message, settings.DeviceIdentifier);
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|