Skip to content

Commit

Permalink
- Notifications will no longer be send to the admins if they request …
Browse files Browse the repository at this point in the history
…something.

- Looks like we missed out adding the notifications to Music requests, so I added that in
  • Loading branch information
TidusJar committed May 16, 2016
1 parent 96a40a2 commit d446122
Showing 1 changed file with 67 additions and 21 deletions.
88 changes: 67 additions & 21 deletions PlexRequests.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,16 @@ private Response RequestMovie(int movieId, bool notify = false)
Log.Info("Adding movie to database (No approval required)");
RequestService.AddRequest(model);

var notificationModel = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish(notificationModel);

if (ShouldSendNotification) {
var notificationModel = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notificationModel);
}
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" });
}
return
Expand All @@ -524,14 +525,15 @@ private Response RequestMovie(int movieId, bool notify = false)
Log.Info("Adding movie to database (No approval required)");
RequestService.AddRequest(model);

var notificationModel = new NotificationModel
{
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish(notificationModel);
if (ShouldSendNotification) {
var notificationModel = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notificationModel);
}

return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" });
}
Expand Down Expand Up @@ -657,9 +659,16 @@ private Response RequestTvShow(int showId, string seasons, bool notify)
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model);
var notify1 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);

if (ShouldSendNotification) {
var notify1 = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notify1);
}
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}

Expand All @@ -677,9 +686,15 @@ private Response RequestTvShow(int showId, string seasons, bool notify)
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & SickRage)");
RequestService.AddRequest(model);

var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify2);
if (ShouldSendNotification) {
var notify2 = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notify2);
}

return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}
Expand All @@ -698,6 +713,18 @@ private Response RequestTvShow(int showId, string seasons, bool notify)
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}

private bool ShouldSendNotification(){
var sendNotification = true;
var claims = Context.CurrentUser?.Claims;
if (claims != null) {
if (claims.Contains (UserClaims.Admin) || claims.Contains (UserClaims.PowerUser)) {
sendNotification = false; // Don't bother sending a notification if the user is an admin
}
}
return sendNotification;
}


private Response RequestAlbum(string releaseId, bool notify)
{
var settings = PrService.GetSettings();
Expand Down Expand Up @@ -798,6 +825,16 @@ private Response RequestAlbum(string releaseId, bool notify)
model.Approved = true;
RequestService.AddRequest(model);

if (ShouldSendNotification ()) {
var notify2 = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notify2);
}

return
Response.AsJson(new JsonResponseModel
{
Expand All @@ -806,6 +843,15 @@ private Response RequestAlbum(string releaseId, bool notify)
});
}

if (ShouldSendNotification ()) {
var notify2 = new NotificationModel {
Title = model.Title,
User = Username,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish (notify2);
}
var result = RequestService.AddRequest(model);
return Response.AsJson(new JsonResponseModel
{
Expand Down

0 comments on commit d446122

Please sign in to comment.