Federate shelve activities when switching editions

This commit is contained in:
Mouse Reeve
2020-12-16 13:59:18 -08:00
parent 5dbacb3524
commit 8a1800ea26
2 changed files with 31 additions and 1 deletions

View File

@ -18,6 +18,7 @@ from django.utils import timezone
from django.views.decorators.http import require_GET, require_POST
from bookwyrm import books_manager
from bookwyrm.broadcast import broadcast
from bookwyrm import forms, models, outgoing
from bookwyrm import goodreads_import
from bookwyrm.emailing import password_reset_email
@ -256,12 +257,16 @@ def switch_edition(request):
new_edition = get_object_or_404(models.Edition, id=edition_id)
shelfbooks = models.ShelfBook.objects.filter(
book__parent_work=new_edition.parent_work,
added_by=request.user
shelf__user=request.user
)
for shelfbook in shelfbooks.all():
broadcast(request.user, shelfbook.to_remove_activity(request.user))
shelfbook.book = new_edition
shelfbook.save()
broadcast(request.user, shelfbook.to_add_activity(request.user))
readthroughs = models.ReadThrough.objects.filter(
book__parent_work=new_edition.parent_work,
user=request.user