mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-26 10:00:33 +00:00
Don't broadcast imported reviews outside bookwyrm
This commit is contained in:
parent
582d2e6d0d
commit
e19c4620ce
2 changed files with 12 additions and 10 deletions
|
@ -136,7 +136,7 @@ def handle_imported_book(source, user, item, include_reviews, privacy):
|
|||
if item.review
|
||||
else ""
|
||||
)
|
||||
models.Review.objects.create(
|
||||
review = models.Review(
|
||||
user=user,
|
||||
book=item.book,
|
||||
name=review_title,
|
||||
|
@ -147,10 +147,12 @@ def handle_imported_book(source, user, item, include_reviews, privacy):
|
|||
)
|
||||
else:
|
||||
# just a rating
|
||||
models.ReviewRating.objects.create(
|
||||
review = models.ReviewRating(
|
||||
user=user,
|
||||
book=item.book,
|
||||
rating=item.rating,
|
||||
published_date=published_date_guess,
|
||||
privacy=privacy,
|
||||
)
|
||||
# only broadcast this review to other bookwyrm instances
|
||||
review.save(software="bookwyrm")
|
||||
|
|
|
@ -195,7 +195,7 @@ class ActivitypubMixin:
|
|||
class ObjectMixin(ActivitypubMixin):
|
||||
"""add this mixin for object models that are AP serializable"""
|
||||
|
||||
def save(self, *args, created=None, **kwargs):
|
||||
def save(self, *args, created=None, software=None, **kwargs):
|
||||
"""broadcast created/updated/deleted objects as appropriate"""
|
||||
broadcast = kwargs.get("broadcast", True)
|
||||
# this bonus kwarg would cause an error in the base save method
|
||||
|
@ -219,15 +219,16 @@ class ObjectMixin(ActivitypubMixin):
|
|||
return
|
||||
|
||||
try:
|
||||
software = None
|
||||
# do we have a "pure" activitypub version of this for mastodon?
|
||||
if hasattr(self, "pure_content"):
|
||||
if not software and hasattr(self, "pure_content"):
|
||||
pure_activity = self.to_create_activity(user, pure=True)
|
||||
self.broadcast(pure_activity, user, software="other")
|
||||
# set bookwyrm so that that type is also sent
|
||||
software = "bookwyrm"
|
||||
# sends to BW only if we just did a pure version for masto
|
||||
activity = self.to_create_activity(user)
|
||||
self.broadcast(activity, user, software=software)
|
||||
if software == "bookwyrm":
|
||||
# sends to BW only if we just did a pure version for masto
|
||||
activity = self.to_create_activity(user)
|
||||
self.broadcast(activity, user, software=software)
|
||||
except AttributeError:
|
||||
# janky as heck, this catches the mutliple inheritence chain
|
||||
# for boosts and ignores this auxilliary broadcast
|
||||
|
@ -241,8 +242,7 @@ class ObjectMixin(ActivitypubMixin):
|
|||
if isinstance(self, user_model):
|
||||
user = self
|
||||
# book data tracks last editor
|
||||
elif hasattr(self, "last_edited_by"):
|
||||
user = self.last_edited_by
|
||||
user = user or getattr(self, "last_edited_by", None)
|
||||
# again, if we don't know the user or they're remote, don't bother
|
||||
if not user or not user.local:
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue