diff --git a/src/activitypub/activity.rs b/src/activitypub/activity.rs index 58dd35d..f7dc3d3 100644 --- a/src/activitypub/activity.rs +++ b/src/activitypub/activity.rs @@ -66,6 +66,9 @@ pub struct Object { #[serde(skip_serializing_if = "Option::is_none")] pub former_type: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub media_type: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub object: Option, diff --git a/src/activitypub/handlers/create_note.rs b/src/activitypub/handlers/create_note.rs index e2e630a..b3e9738 100644 --- a/src/activitypub/handlers/create_note.rs +++ b/src/activitypub/handlers/create_note.rs @@ -65,18 +65,24 @@ fn parse_object_url(value: &JsonValue) -> Result { } pub fn get_note_content(object: &Object) -> Result { - let mut content = object.content.as_deref() + let mut content = if let Some(ref content) = object.content { + if object.media_type == Some("text/markdown".to_string()) { + format!("

{}

", content) + } else { + // HTML + content.to_string() + } + } else { // Lemmy pages and PeerTube videos have "name" property - .or(object.name.as_deref()) - .unwrap_or("") - .to_owned(); + object.name.as_deref().unwrap_or("").to_string() + }; if object.object_type != NOTE { if let Some(ref value) = object.url { // Append link to object let object_url = parse_object_url(value) .map_err(|_| ValidationError("invalid object URL"))?; content += &format!( - r#"

{0}

"#, + r#"

{0}

"#, object_url, ); }; @@ -423,7 +429,7 @@ mod tests { let content = get_note_content(&object).unwrap(); assert_eq!( content, - r#"test-content

https://example.org/xyz

"#, + r#"test-content

https://example.org/xyz

"#, ); }