mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
#96 add the necessary back-end code to produce a test message for all notification types (still have to add the test buttons for pushbullet/pushover)
This commit is contained in:
parent
45208e528f
commit
9742b42fdf
3 changed files with 76 additions and 34 deletions
|
@ -60,10 +60,7 @@ namespace PlexRequests.Services.Notification
|
|||
|
||||
var emailSettings = (EmailNotificationSettings)settings;
|
||||
|
||||
if (!ValidateConfiguration(emailSettings))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!ValidateConfiguration(emailSettings)) return;
|
||||
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,18 +51,25 @@ namespace PlexRequests.Services.Notification
|
|||
public string NotificationName => "PushoverNotification";
|
||||
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 = (PushoverNotificationSettings)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(PushoverNotificationSettings settings)
|
||||
{
|
||||
if (!Settings.Enabled)
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(Settings.AccessToken) || string.IsNullOrEmpty(Settings.UserToken))
|
||||
if (string.IsNullOrEmpty(settings.AccessToken) || string.IsNullOrEmpty(settings.UserToken))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -93,12 +103,12 @@ namespace PlexRequests.Services.Notification
|
|||
return SettingsService.GetSettings();
|
||||
}
|
||||
|
||||
private async Task PushNewRequestAsync(NotificationModel model)
|
||||
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
var message = $"Plex Requests: {model.Title} has been requested by user: {model.User}";
|
||||
try
|
||||
{
|
||||
var result = await PushoverApi.PushAsync(Settings.AccessToken, message, Settings.UserToken);
|
||||
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");
|
||||
|
@ -110,12 +120,12 @@ namespace PlexRequests.Services.Notification
|
|||
}
|
||||
}
|
||||
|
||||
private async Task PushIssueAsync(NotificationModel model)
|
||||
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}";
|
||||
try
|
||||
{
|
||||
var result = await PushoverApi.PushAsync(Settings.AccessToken, message, Settings.UserToken);
|
||||
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");
|
||||
|
@ -127,9 +137,21 @@ namespace PlexRequests.Services.Notification
|
|||
}
|
||||
}
|
||||
|
||||
public Task NotifyAsync(NotificationModel model, Settings settings)
|
||||
private async Task PushTestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var message = $"Plex Requests: Test Message!";
|
||||
try
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue