diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 03305f6b..36107990 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -415,7 +415,7 @@ class ImageField(ActivitypubFieldMixin, models.ImageField): activity[key] = formatted def field_to_activity(self, value, alt=None): - url = self.get_absolute_url(value) + url = get_absolute_url(value) if not url: return None @@ -456,19 +456,19 @@ class ImageField(ActivitypubFieldMixin, models.ImageField): } ) - # pylint: disable=no-self-use - def get_absolute_url(self, value): - """returns an absolute URL for the image""" - name = getattr(value, "name") - if not name: - return None - url = filepath_to_uri(name) - if url is not None: - url = url.lstrip("/") - url = urljoin(MEDIA_FULL_URL, url) +def get_absolute_url(value): + """returns an absolute URL for the image""" + name = getattr(value, "name") + if not name: + return None - return url + url = filepath_to_uri(name) + if url is not None: + url = url.lstrip("/") + url = urljoin(MEDIA_FULL_URL, url) + + return url class DateTimeField(ActivitypubFieldMixin, models.DateTimeField): diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index d3fcc254..a52af123 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -190,9 +190,22 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): activity.name = self.pure_name activity.type = self.pure_type books = [getattr(self, "book", None)] + list(self.mention_books.all()) - covers = [ - b.to_activity().get("cover") for b in books if b - ] + if len(books) == 1 and books[0].preview_image: + covers = [ + activitypub.Document( + url=fields.get_absolute_url(books[0].preview_image), + name=books[0].alt_text, + ) + ] + else: + covers = [ + activitypub.Document( + url=fields.get_absolute_url(b.cover), + name=b.alt_text, + ) + for b in books + if b and b.cover + ] activity.attachment = covers return activity