forked from mirrors/bookwyrm
Update books feed on shelve
This commit is contained in:
parent
d7307463d5
commit
120938bee9
1 changed files with 64 additions and 0 deletions
|
@ -201,6 +201,40 @@ class BooksStream(ActivityStream):
|
||||||
privacy_levels=["public"],
|
privacy_levels=["public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def add_book_statuses(self, user, book):
|
||||||
|
"""add statuses about a book to a user's feed"""
|
||||||
|
work = book.parent_work
|
||||||
|
statuses = privacy_filter(
|
||||||
|
user,
|
||||||
|
models.Status.objects.select_subclasses()
|
||||||
|
.filter(
|
||||||
|
Q(comment__book__parent_work=work)
|
||||||
|
| Q(quotation__book__parent_work=work)
|
||||||
|
| Q(review__book__parent_work=work)
|
||||||
|
| Q(mention_books__parent_work=work)
|
||||||
|
)
|
||||||
|
.distinct(),
|
||||||
|
privacy_levels=["public"],
|
||||||
|
)
|
||||||
|
self.bulk_add_objects_to_store(statuses, self.stream_id(user))
|
||||||
|
|
||||||
|
def remove_book_statuses(self, user, book):
|
||||||
|
"""add statuses about a book to a user's feed"""
|
||||||
|
work = book.parent_work
|
||||||
|
statuses = privacy_filter(
|
||||||
|
user,
|
||||||
|
models.Status.objects.select_subclasses()
|
||||||
|
.filter(
|
||||||
|
Q(comment__book__parent_work=work)
|
||||||
|
| Q(quotation__book__parent_work=work)
|
||||||
|
| Q(review__book__parent_work=work)
|
||||||
|
| Q(mention_books__parent_work=work)
|
||||||
|
)
|
||||||
|
.distinct(),
|
||||||
|
privacy_levels=["public"],
|
||||||
|
)
|
||||||
|
self.bulk_remove_objects_from_store(statuses, self.stream_id(user))
|
||||||
|
|
||||||
|
|
||||||
# determine which streams are enabled in settings.py
|
# determine which streams are enabled in settings.py
|
||||||
available_streams = [s["key"] for s in STREAMS]
|
available_streams = [s["key"] for s in STREAMS]
|
||||||
|
@ -331,6 +365,36 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg
|
||||||
populate_streams_task.delay(instance.id)
|
populate_streams_task.delay(instance.id)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.pre_save, sender=models.ShelfBook)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def add_statuses_on_shelve(sender, instance, created, *args, **kwargs):
|
||||||
|
"""update books stream when user shelves a book"""
|
||||||
|
if not created or 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():
|
||||||
|
return
|
||||||
|
|
||||||
|
BooksStream().add_book_statuses(instance.user, instance.book)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_delete, sender=models.ShelfBook)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def remove_statuses_on_shelve(sender, instance, *args, **kwargs):
|
||||||
|
"""update books stream when user unshelves a book"""
|
||||||
|
if not instance.user.local:
|
||||||
|
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():
|
||||||
|
return
|
||||||
|
|
||||||
|
BooksStream().remove_book_statuses(instance.user, instance.book)
|
||||||
|
|
||||||
|
|
||||||
# ---- TASKS
|
# ---- TASKS
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue