forked from mirrors/bookwyrm
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
|
activity[key] = formatted
|
||||||
|
|
||||||
def field_to_activity(self, value, alt=None):
|
def field_to_activity(self, value, alt=None):
|
||||||
url = self.get_absolute_url(value)
|
url = get_absolute_url(value)
|
||||||
|
|
||||||
if not url:
|
if not url:
|
||||||
return None
|
return None
|
||||||
|
@ -456,8 +456,8 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
|
||||||
def get_absolute_url(self, value):
|
def get_absolute_url(value):
|
||||||
"""returns an absolute URL for the image"""
|
"""returns an absolute URL for the image"""
|
||||||
name = getattr(value, "name")
|
name = getattr(value, "name")
|
||||||
if not name:
|
if not name:
|
||||||
|
|
|
@ -190,8 +190,21 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
activity.name = self.pure_name
|
activity.name = self.pure_name
|
||||||
activity.type = self.pure_type
|
activity.type = self.pure_type
|
||||||
books = [getattr(self, "book", None)] + list(self.mention_books.all())
|
books = [getattr(self, "book", None)] + list(self.mention_books.all())
|
||||||
|
if len(books) == 1 and books[0].preview_image:
|
||||||
covers = [
|
covers = [
|
||||||
b.to_activity().get("cover") for b in books if b
|
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
|
activity.attachment = covers
|
||||||
return activity
|
return activity
|
||||||
|
|
Loading…
Reference in a new issue