mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-10 17:25:35 +00:00
Use social media preview images
This commit is contained in:
parent
d61595abb9
commit
717da918cf
2 changed files with 28 additions and 15 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue