forked from mirrors/bookwyrm
Merge pull request #1265 from bookwyrm-social/generated-notes-activitystream
Fixes generated notes not appearing in books stream
This commit is contained in:
commit
c685fb0296
2 changed files with 25 additions and 13 deletions
|
@ -260,9 +260,6 @@ def add_status_on_create(sender, instance, created, *args, **kwargs):
|
|||
stream.remove_object_from_related_stores(instance)
|
||||
return
|
||||
|
||||
if not created:
|
||||
return
|
||||
|
||||
for stream in streams.values():
|
||||
stream.add_status(instance)
|
||||
|
||||
|
@ -358,25 +355,39 @@ def add_statuses_on_shelve(sender, instance, *args, **kwargs):
|
|||
"""update books stream when user shelves a book"""
|
||||
if not instance.user.local:
|
||||
return
|
||||
# check if the book is already on the user's shelves
|
||||
if models.ShelfBook.objects.filter(
|
||||
user=instance.user, book__in=instance.book.parent_work.editions.all()
|
||||
).exists():
|
||||
book = None
|
||||
if hasattr(instance, "book"):
|
||||
book = instance.book
|
||||
elif instance.mention_books.exists():
|
||||
book = instance.mention_books.first()
|
||||
if not book:
|
||||
return
|
||||
|
||||
BooksStream().add_book_statuses(instance.user, instance.book)
|
||||
# check if the book is already on the user's shelves
|
||||
editions = book.parent_work.editions.all()
|
||||
if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists():
|
||||
return
|
||||
|
||||
BooksStream().add_book_statuses(instance.user, book)
|
||||
|
||||
|
||||
@receiver(signals.post_delete, sender=models.ShelfBook)
|
||||
# pylint: disable=unused-argument
|
||||
def remove_statuses_on_shelve(sender, instance, *args, **kwargs):
|
||||
def remove_statuses_on_unshelve(sender, instance, *args, **kwargs):
|
||||
"""update books stream when user unshelves a book"""
|
||||
if not instance.user.local:
|
||||
return
|
||||
|
||||
book = None
|
||||
if hasattr(instance, "book"):
|
||||
book = instance.book
|
||||
elif instance.mention_books.exists():
|
||||
book = instance.mention_books.first()
|
||||
if not book:
|
||||
return
|
||||
# check if the book is actually unshelved, not just moved
|
||||
if models.ShelfBook.objects.filter(
|
||||
user=instance.user, book__in=instance.book.parent_work.editions.all()
|
||||
).exists():
|
||||
editions = book.parent_work.editions.all()
|
||||
if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists():
|
||||
return
|
||||
|
||||
BooksStream().remove_book_statuses(instance.user, instance.book)
|
||||
|
|
|
@ -47,7 +47,8 @@ class InboxCreate(TestCase):
|
|||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_create_status(self, _):
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_create_status(self, *_):
|
||||
"""the "it justs works" mode"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../data/ap_quotation.json"
|
||||
|
|
Loading…
Reference in a new issue