Tweak the attachment handling for Hubzilla support

This commit is contained in:
Thomas Sileo 2018-07-24 22:10:39 +02:00
parent 4910729b2c
commit cf46ddcb60
2 changed files with 6 additions and 3 deletions

View file

@ -48,9 +48,9 @@ def process_new_activity(self, iri: str) -> None:
tag_stream = False tag_stream = False
if activity.has_type(ap.ActivityType.ANNOUNCE): if activity.has_type(ap.ActivityType.ANNOUNCE):
tag_stream = True
try: try:
activity.get_object() activity.get_object()
tag_stream = True
except NotAnActivityError: except NotAnActivityError:
# Most likely on OStatus notice # Most likely on OStatus notice
tag_stream = False tag_stream = False
@ -235,7 +235,10 @@ def cache_attachments(self, iri: str) -> None:
if activity.has_type(ap.ActivityType.CREATE): if activity.has_type(ap.ActivityType.CREATE):
for attachment in activity.get_object()._data.get("attachment", []): for attachment in activity.get_object()._data.get("attachment", []):
if attachment.get("mediaType", "").startswith("image/"): if (
attachment.get("mediaType", "").startswith("image/")
or attachment.get("type") == ap.ActivityType.IMAGE.value
):
MEDIA_CACHE.cache(attachment["url"], Kind.ATTACHMENT) MEDIA_CACHE.cache(attachment["url"], Kind.ATTACHMENT)
log.info(f"attachments cached for {iri}") log.info(f"attachments cached for {iri}")

View file

@ -54,7 +54,7 @@
<ul> <ul>
{% endif %} {% endif %}
{% for a in obj.attachment %} {% for a in obj.attachment %}
{% if a.mediaType.startswith("image/") %} {% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
<a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a> <a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a>
{% else %} {% else %}
<li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li> <li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>