show request type in notifications #346 and fix an issue from previous commit for #345

pull/356/head
Drewster727 8 years ago
parent 96f27f8f1a
commit f76e54408e

@ -36,6 +36,7 @@ using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Interfaces;
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
using PlexRequests.Store;
namespace PlexRequests.Services.Notification
{
@ -119,8 +120,8 @@ namespace PlexRequests.Services.Notification
{
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")}" },
Subject = $"Plex Requests: New request for {model.Title}!"
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 {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} request for {model.Title}!"
};
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));

@ -24,6 +24,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using PlexRequests.Store;
using System;
namespace PlexRequests.Services.Notification
@ -36,5 +37,6 @@ namespace PlexRequests.Services.Notification
public NotificationType NotificationType { get; set; }
public string User { get; set; }
public string UserEmail { get; set; }
public RequestType RequestType { get; set; }
}
}

@ -33,6 +33,7 @@ using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Interfaces;
using PlexRequests.Store;
namespace PlexRequests.Services.Notification
{
@ -104,8 +105,8 @@ namespace PlexRequests.Services.Notification
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}";
var pushTitle = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} {model.Title} has been requested!";
await Push(settings, message, pushTitle);
}

@ -33,6 +33,7 @@ using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Interfaces;
using PlexRequests.Store;
namespace PlexRequests.Services.Notification
{
@ -104,7 +105,7 @@ namespace PlexRequests.Services.Notification
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
{
var message = $"Plex Requests: {model.Title} has been requested by user: {model.User}";
var message = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
await Push(settings, message);
}

@ -78,6 +78,24 @@ namespace PlexRequests.Store
Album
}
public static class RequestTypeDisplay
{
public static string Get(RequestType type)
{
switch (type)
{
case RequestType.Movie:
return "Movie";
case RequestType.TvShow:
return "TV Show";
case RequestType.Album:
return "Album";
default:
return string.Empty;
}
}
}
public enum IssueState
{
None = 99,

@ -488,14 +488,15 @@ namespace PlexRequests.UI.Modules
Log.Info("Adding movie to database (No approval required)");
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.Movie, settings))
{
var notificationModel = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.Movie
};
await NotificationService.Publish(notificationModel);
}
@ -515,14 +516,15 @@ namespace PlexRequests.UI.Modules
Log.Info("Adding movie to database (No approval required)");
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.Movie, settings))
{
var notificationModel = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.Movie
};
await NotificationService.Publish(notificationModel);
}
@ -536,7 +538,7 @@ namespace PlexRequests.UI.Modules
Log.Info("Adding movie to database");
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);
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)");
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.TvShow, settings))
{
var notify1 = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.TvShow
};
await NotificationService.Publish(notify1);
}
@ -691,14 +694,15 @@ namespace PlexRequests.UI.Modules
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.TvShow, settings))
{
var notify2 = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.TvShow
};
await NotificationService.Publish(notify2);
}
@ -713,14 +717,15 @@ namespace PlexRequests.UI.Modules
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required) and Sonarr/Sickrage not setup");
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.TvShow, settings))
{
var notify2 = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.TvShow
};
await NotificationService.Publish(notify2);
}
@ -733,15 +738,15 @@ namespace PlexRequests.UI.Modules
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);
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;
if (claims != null)
{
@ -838,14 +843,15 @@ namespace PlexRequests.UI.Modules
model.Approved = true;
await RequestService.AddRequestAsync(model);
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.Album, settings))
{
var notify2 = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.Album
};
await NotificationService.Publish(notify2);
}
@ -858,14 +864,15 @@ namespace PlexRequests.UI.Modules
});
}
if (ShouldSendNotification(settings))
if (ShouldSendNotification(RequestType.Album, settings))
{
var notify2 = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
NotificationType = NotificationType.NewRequest,
RequestType = RequestType.Album
};
await NotificationService.Publish(notify2);
}

Loading…
Cancel
Save