forked from mirrors/bookwyrm
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
|
if item.review
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
models.Review.objects.create(
|
review = models.Review(
|
||||||
user=user,
|
user=user,
|
||||||
book=item.book,
|
book=item.book,
|
||||||
name=review_title,
|
name=review_title,
|
||||||
|
@ -147,10 +147,12 @@ def handle_imported_book(source, user, item, include_reviews, privacy):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# just a rating
|
# just a rating
|
||||||
models.ReviewRating.objects.create(
|
review = models.ReviewRating(
|
||||||
user=user,
|
user=user,
|
||||||
book=item.book,
|
book=item.book,
|
||||||
rating=item.rating,
|
rating=item.rating,
|
||||||
published_date=published_date_guess,
|
published_date=published_date_guess,
|
||||||
privacy=privacy,
|
privacy=privacy,
|
||||||
)
|
)
|
||||||
|
# only broadcast this review to other bookwyrm instances
|
||||||
|
review.save(software="bookwyrm")
|
||||||
|
|
|
@ -195,7 +195,7 @@ class ActivitypubMixin:
|
||||||
class ObjectMixin(ActivitypubMixin):
|
class ObjectMixin(ActivitypubMixin):
|
||||||
"""add this mixin for object models that are AP serializable"""
|
"""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 created/updated/deleted objects as appropriate"""
|
||||||
broadcast = kwargs.get("broadcast", True)
|
broadcast = kwargs.get("broadcast", True)
|
||||||
# this bonus kwarg would cause an error in the base save method
|
# this bonus kwarg would cause an error in the base save method
|
||||||
|
@ -219,12 +219,13 @@ class ObjectMixin(ActivitypubMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
software = None
|
|
||||||
# do we have a "pure" activitypub version of this for mastodon?
|
# 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)
|
pure_activity = self.to_create_activity(user, pure=True)
|
||||||
self.broadcast(pure_activity, user, software="other")
|
self.broadcast(pure_activity, user, software="other")
|
||||||
|
# set bookwyrm so that that type is also sent
|
||||||
software = "bookwyrm"
|
software = "bookwyrm"
|
||||||
|
if software == "bookwyrm":
|
||||||
# sends to BW only if we just did a pure version for masto
|
# sends to BW only if we just did a pure version for masto
|
||||||
activity = self.to_create_activity(user)
|
activity = self.to_create_activity(user)
|
||||||
self.broadcast(activity, user, software=software)
|
self.broadcast(activity, user, software=software)
|
||||||
|
@ -241,8 +242,7 @@ class ObjectMixin(ActivitypubMixin):
|
||||||
if isinstance(self, user_model):
|
if isinstance(self, user_model):
|
||||||
user = self
|
user = self
|
||||||
# book data tracks last editor
|
# book data tracks last editor
|
||||||
elif hasattr(self, "last_edited_by"):
|
user = user or getattr(self, "last_edited_by", None)
|
||||||
user = self.last_edited_by
|
|
||||||
# again, if we don't know the user or they're remote, don't bother
|
# again, if we don't know the user or they're remote, don't bother
|
||||||
if not user or not user.local:
|
if not user or not user.local:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue