From 0badc71c92428667cb71dfb76f6f920f8756dc19 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 May 2024 17:09:35 +0200 Subject: [PATCH] fix(web): attachments without media type show if img nobody uses the type field and just mark everything as Document ughhh and so those who mark image as Image and avoid a media_type because the browser doesnt really need it get displayed as links, so added an ugly special case --- web/src/components/object.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/components/object.rs b/web/src/components/object.rs index a14dae3..047c566 100644 --- a/web/src/components/object.rs +++ b/web/src/components/object.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use leptos::*; use crate::{prelude::*, URL_SENSITIVE}; -use apb::{target::Addressed, ActivityMut, Base, Collection, CollectionMut, Object, ObjectMut}; +use apb::{target::Addressed, ActivityMut, Base, Collection, CollectionMut, Document, Object, ObjectMut}; #[component] pub fn Attachment( @@ -17,12 +17,22 @@ pub fn Attachment( let media_type = object.media_type() .unwrap_or("image/png") // TODO weird defaulting to png????? .to_string(); - let kind = media_type + let mut kind = media_type .split('/') .next() .unwrap_or("image") .to_string(); + // TODO in theory we should match on document_type, but mastodon and misskey send all attachments + // as "Documents" regardless of type, so we're forced to ignore the actual AP type and just match + // using media_type, uffff + // + // those who correctly send Image type objects without a media type get shown as links here, this + // is a dirty fix to properly display as images + if kind == "link" && matches!(object.document_type(), Some(apb::DocumentType::Image)) { + kind = "image".to_string(); + } + match kind.as_str() { "image" => view! {