From 06f62576454448d6967880de2cdf303d254a79a9 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Sun, 15 Jan 2023 16:49:04 -0500 Subject: [PATCH] Render non-media PostAttachments (#420) --- activities/models/post_attachment.py | 17 +++++++++++++++-- static/css/style.css | 26 ++++++++++++++++++++++++++ templates/activities/_post.html | 11 ++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/activities/models/post_attachment.py b/activities/models/post_attachment.py index 2a140fd..cef6860 100644 --- a/activities/models/post_attachment.py +++ b/activities/models/post_attachment.py @@ -73,7 +73,11 @@ class PostAttachment(StatorModel): ] def is_video(self): - return self.mimetype in ["video/webm"] + return self.mimetype in [ + "video/mp4", + "video/ogg", + "video/webm", + ] def thumbnail_url(self) -> RelativeAbsoluteUrl: if self.thumbnail: @@ -89,11 +93,20 @@ class PostAttachment(StatorModel): def full_url(self): if self.file: return RelativeAbsoluteUrl(self.file.url) - else: + if self.is_image(): return ProxyAbsoluteUrl( f"/proxy/post_attachment/{self.pk}/", remote_url=self.remote_url, ) + return RelativeAbsoluteUrl(self.remote_url) + + @property + def file_display_name(self): + if self.remote_url: + return self.remote_url.rsplit("/", 1)[-1] + if self.file: + return self.file.name + return f"attachment ({self.mimetype})" ### ActivityPub ### diff --git a/static/css/style.css b/static/css/style.css index 6fbe788..014c51a 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1497,6 +1497,32 @@ form .post { max-width: 100%; } +.post .attachments .other { + grid-column: span 2; + padding: 8px; + border: 1px solid var(--color-text-duller); + background: var(--color-bg-menu); + border-radius: 4px; + margin-top: 8px; + word-break: break-all; +} + +.post .attachments .other-label { + display: flex; + align-items: center; +} + +.post .attachments .other-label > i { + margin-right: 12px; +} + +.post .attachments .other:hover { + text-decoration: none; + background: var(--color-bg-main); + color: #FFF; + border-color: var(--color-highlight); +} + .post .actions { display: flex; position: relative; diff --git a/templates/activities/_post.html b/templates/activities/_post.html index 8848bf8..f514cc1 100644 --- a/templates/activities/_post.html +++ b/templates/activities/_post.html @@ -50,11 +50,20 @@ {% elif attachment.is_video %} {% endif %} {% endfor %} + {% for attachment in post.attachments.all %} + {% if not attachment.is_image and not attachment.is_video %} + +
+ {{ attachment.file_display_name }} +
+
+ {% endif %} + {% endfor %} {% endif %}