@ -175,16 +175,16 @@ namespace PlexRequests.UI.Modules
Get [ "/emailnotification" ] = _ = > EmailNotifications ( ) ;
Post [ "/emailnotification" ] = _ = > SaveEmailNotifications ( ) ;
Post [ "/testemailnotification" ] = _ = > TestEmailNotifications ( ) ;
Post [ "/testemailnotification" , true ] = async ( x , ct ) = > await TestEmailNotifications ( ) ;
Get [ "/status" , true ] = async ( x , ct ) = > await Status ( ) ;
Get [ "/pushbulletnotification" ] = _ = > PushbulletNotifications ( ) ;
Post [ "/pushbulletnotification" ] = _ = > SavePushbulletNotifications ( ) ;
Post [ "/testpushbulletnotification" ] = _ = > TestPushbulletNotifications ( ) ;
Post [ "/testpushbulletnotification" , true ] = async ( x , ct ) = > await TestPushbulletNotifications ( ) ;
Get [ "/pushovernotification" ] = _ = > PushoverNotifications ( ) ;
Post [ "/pushovernotification" ] = _ = > SavePushoverNotifications ( ) ;
Post [ "/testpushovernotification" ] = _ = > TestPushoverNotifications ( ) ;
Post [ "/testpushovernotification" , true ] = async ( x , ct ) = > await TestPushoverNotifications ( ) ;
Get [ "/logs" ] = _ = > Logs ( ) ;
Get [ "/loglevel" ] = _ = > GetLogLevels ( ) ;
@ -198,7 +198,7 @@ namespace PlexRequests.UI.Modules
Post [ "/autoupdate" ] = x = > AutoUpdate ( ) ;
Post [ "/testslacknotification" ] = _ = > TestSlackNotification ( ) ;
Post [ "/testslacknotification" , true ] = async ( x , ct ) = > await TestSlackNotification ( ) ;
Get [ "/slacknotification" ] = _ = > SlackNotifications ( ) ;
Post [ "/slacknotification" ] = _ = > SaveSlackNotifications ( ) ;
@ -477,7 +477,7 @@ namespace PlexRequests.UI.Modules
return View [ "EmailNotifications" , settings ] ;
}
private Response TestEmailNotifications ( )
private async Task < Response > TestEmailNotifications ( )
{
var settings = this . Bind < EmailNotificationSettings > ( ) ;
var valid = this . Validate ( settings ) ;
@ -485,6 +485,7 @@ namespace PlexRequests.UI.Modules
{
return Response . AsJson ( valid . SendJsonError ( ) ) ;
}
var currentSettings = await EmailService . GetSettingsAsync ( ) ;
var notificationModel = new NotificationModel
{
NotificationType = NotificationType . Test ,
@ -502,9 +503,12 @@ namespace PlexRequests.UI.Modules
Log . Error ( "Failed to subscribe and publish test Email Notification" ) ;
}
finally
{
if ( ! currentSettings . Enabled )
{
NotificationService . UnSubscribe ( new EmailMessageNotification ( EmailService ) ) ;
}
}
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "Successfully sent a test Email Notification!" } ) ;
}
@ -595,7 +599,7 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false , Message = "Could not update the settings, take a look at the logs." } ) ;
}
private Response TestPushbulletNotifications ( )
private async Task < Response > TestPushbulletNotifications ( )
{
var settings = this . Bind < PushbulletNotificationSettings > ( ) ;
var valid = this . Validate ( settings ) ;
@ -608,6 +612,7 @@ namespace PlexRequests.UI.Modules
NotificationType = NotificationType . Test ,
DateTime = DateTime . Now
} ;
var currentSettings = await PushbulletService . GetSettingsAsync ( ) ;
try
{
NotificationService . Subscribe ( new PushbulletNotification ( PushbulletApi , PushbulletService ) ) ;
@ -620,9 +625,12 @@ namespace PlexRequests.UI.Modules
Log . Error ( "Failed to subscribe and publish test Pushbullet Notification" ) ;
}
finally
{
if ( ! currentSettings . Enabled )
{
NotificationService . UnSubscribe ( new PushbulletNotification ( PushbulletApi , PushbulletService ) ) ;
}
}
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "Successfully sent a test Pushbullet Notification!" } ) ;
}
@ -657,7 +665,7 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false , Message = "Could not update the settings, take a look at the logs." } ) ;
}
private Response TestPushoverNotifications ( )
private async Task < Response > TestPushoverNotifications ( )
{
var settings = this . Bind < PushoverNotificationSettings > ( ) ;
var valid = this . Validate ( settings ) ;
@ -670,6 +678,7 @@ namespace PlexRequests.UI.Modules
NotificationType = NotificationType . Test ,
DateTime = DateTime . Now
} ;
var currentSettings = await PushbulletService . GetSettingsAsync ( ) ;
try
{
NotificationService . Subscribe ( new PushoverNotification ( PushoverApi , PushoverService ) ) ;
@ -682,9 +691,12 @@ namespace PlexRequests.UI.Modules
Log . Error ( "Failed to subscribe and publish test Pushover Notification" ) ;
}
finally
{
if ( ! currentSettings . Enabled )
{
NotificationService . UnSubscribe ( new PushoverNotification ( PushoverApi , PushoverService ) ) ;
}
}
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "Successfully sent a test Pushover Notification!" } ) ;
}
@ -803,7 +815,7 @@ namespace PlexRequests.UI.Modules
return Response . AsJson ( apiKey ) ;
}
private Response TestSlackNotification ( )
private async Task < Response > TestSlackNotification ( )
{
var settings = this . BindAndValidate < SlackNotificationSettings > ( ) ;
if ( ! ModelValidationResult . IsValid )
@ -815,11 +827,13 @@ namespace PlexRequests.UI.Modules
NotificationType = NotificationType . Test ,
DateTime = DateTime . Now
} ;
var currentSlackSettings = await SlackSettings . GetSettingsAsync ( ) ;
try
{
NotificationService . Subscribe ( new SlackNotification ( SlackApi , SlackSettings ) ) ;
settings . Enabled = true ;
NotificationService . Publish ( notificationModel , settings ) ;
await NotificationService . Publish ( notificationModel , settings ) ;
Log . Info ( "Sent slack notification test" ) ;
}
catch ( Exception e )
@ -827,9 +841,12 @@ namespace PlexRequests.UI.Modules
Log . Error ( e , "Failed to subscribe and publish test Slack Notification" ) ;
}
finally
{
if ( ! currentSlackSettings . Enabled )
{
NotificationService . UnSubscribe ( new SlackNotification ( SlackApi , SlackSettings ) ) ;
}
}
return Response . AsJson ( new JsonResponseModel { Result = true , Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs." } ) ;
}