Send signalr message for episode monitored flag changes

(cherry picked from commit 9e81d41f262fb1f9d798374673b0a0427bf1a6e3)

Closes #1049
pull/1237/head
Taloth Saldono 3 years ago committed by ta264
parent 2317665f33
commit 0e5f45a457

@ -176,6 +176,8 @@ namespace NzbDrone.Core.Books
{ {
book.Monitored = monitored; book.Monitored = monitored;
SetFields(book, p => p.Monitored); SetFields(book, p => p.Monitored);
ModelUpdated(book, true);
} }
public void SetMonitored(IEnumerable<int> ids, bool monitored) public void SetMonitored(IEnumerable<int> ids, bool monitored)

@ -473,24 +473,24 @@ namespace NzbDrone.Core.Datastore
} }
} }
protected void ModelCreated(TModel model) protected void ModelCreated(TModel model, bool forcePublish = false)
{ {
PublishModelEvent(model, ModelAction.Created); PublishModelEvent(model, ModelAction.Created, forcePublish);
} }
protected void ModelUpdated(TModel model) protected void ModelUpdated(TModel model, bool forcePublish = false)
{ {
PublishModelEvent(model, ModelAction.Updated); PublishModelEvent(model, ModelAction.Updated, forcePublish);
} }
protected void ModelDeleted(TModel model) protected void ModelDeleted(TModel model, bool forcePublish = false)
{ {
PublishModelEvent(model, ModelAction.Deleted); PublishModelEvent(model, ModelAction.Deleted, forcePublish);
} }
private void PublishModelEvent(TModel model, ModelAction action) private void PublishModelEvent(TModel model, ModelAction action, bool forcePublish)
{ {
if (PublishModelEvents) if (PublishModelEvents || forcePublish)
{ {
_eventAggregator.PublishEvent(new ModelEvent<TModel>(model, action)); _eventAggregator.PublishEvent(new ModelEvent<TModel>(model, action));
} }

@ -1,14 +1,23 @@
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Datastore.Events namespace NzbDrone.Core.Datastore.Events
{ {
public class ModelEvent<TModel> : IEvent public class ModelEvent<TModel> : IEvent
where TModel : ModelBase
{ {
public int ModelId { get; set; }
public TModel Model { get; set; } public TModel Model { get; set; }
public ModelAction Action { get; set; } public ModelAction Action { get; set; }
public ModelEvent(int modelId, ModelAction action)
{
ModelId = modelId;
Action = action;
}
public ModelEvent(TModel model, ModelAction action) public ModelEvent(TModel model, ModelAction action)
{ {
ModelId = model.Id;
Model = model; Model = model;
Action = action; Action = action;
} }

@ -174,6 +174,15 @@ namespace Readarr.Api.V1.Books
{ {
_bookService.SetMonitored(resource.BookIds, resource.Monitored); _bookService.SetMonitored(resource.BookIds, resource.Monitored);
if (resource.BookIds.Count == 1)
{
_bookService.SetBookMonitored(resource.BookIds.First(), resource.Monitored);
}
else
{
_bookService.SetMonitored(resource.BookIds, resource.Monitored);
}
return Accepted(MapToResource(_bookService.GetBooks(resource.BookIds), false)); return Accepted(MapToResource(_bookService.GetBooks(resource.BookIds), false));
} }

@ -40,6 +40,13 @@ namespace Readarr.Api.V1.Books
return resource; return resource;
} }
protected override BookResource GetResourceByIdForBroadcast(int id)
{
var book = _bookService.GetBook(id);
var resource = MapToResource(book, false);
return resource;
}
protected BookResource MapToResource(Book book, bool includeAuthor) protected BookResource MapToResource(Book book, bool includeAuthor)
{ {
var resource = book.ToResource(); var resource = book.ToResource();

@ -29,6 +29,11 @@ namespace Readarr.Http.REST
} }
} }
protected virtual TResource GetResourceByIdForBroadcast(int id)
{
return GetResourceById(id);
}
[NonAction] [NonAction]
public void Handle(ModelEvent<TModel> message) public void Handle(ModelEvent<TModel> message)
{ {
@ -42,7 +47,7 @@ namespace Readarr.Http.REST
BroadcastResourceChange(message.Action); BroadcastResourceChange(message.Action);
} }
BroadcastResourceChange(message.Action, message.Model.Id); BroadcastResourceChange(message.Action, message.ModelId);
} }
protected void BroadcastResourceChange(ModelAction action, int id) protected void BroadcastResourceChange(ModelAction action, int id)
@ -58,7 +63,7 @@ namespace Readarr.Http.REST
} }
else else
{ {
var resource = GetResourceById(id); var resource = GetResourceByIdForBroadcast(id);
BroadcastResourceChange(action, resource); BroadcastResourceChange(action, resource);
} }
} }

Loading…
Cancel
Save