From: Dessalines Date: Mon, 15 Nov 2021 20:26:48 +0000 (-0500) Subject: Fixing activity serialization. Fixes #1900 (#1901) X-Git-Url: http://these/git/%7B%60/feeds/inbox/%22%7B%7D/static/%7Bthis.props.imageSrc%7D?a=commitdiff_plain;h=09cd32034b256c144906b6a61bf4595642c4a0e4;p=lemmy.git Fixing activity serialization. Fixes #1900 (#1901) --- diff --git a/crates/apub/src/context.rs b/crates/apub/src/context.rs index 55486872..a3a223a3 100644 --- a/crates/apub/src/context.rs +++ b/crates/apub/src/context.rs @@ -25,3 +25,19 @@ impl WithContext { self.inner } } + +#[derive(Serialize, Deserialize)] +pub(crate) struct WithContextJson { + #[serde(rename = "@context")] + context: OneOrMany, + inner: serde_json::Value, +} + +impl WithContextJson { + pub(crate) fn new(inner: serde_json::Value) -> WithContextJson { + WithContextJson { + context: CONTEXT.clone(), + inner, + } + } +} diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index d35815ab..3dd068dd 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -1,7 +1,7 @@ use crate::{ activity_lists::SharedInboxActivities, check_is_apub_id_valid, - context::WithContext, + context::{WithContext, WithContextJson}, fetcher::user_or_community::UserOrCommunity, http::{community::receive_group_inbox, person::receive_person_inbox}, insert_activity, @@ -129,6 +129,12 @@ where .json(WithContext::new(data)) } +fn create_json_apub_response(data: serde_json::Value) -> HttpResponse { + HttpResponse::Ok() + .content_type(APUB_JSON_CONTENT_TYPE) + .json(WithContextJson::new(data)) +} + fn create_apub_tombstone_response(data: &T) -> HttpResponse where T: Serialize, @@ -167,7 +173,7 @@ pub(crate) async fn get_activity( if !activity.local || sensitive { Ok(HttpResponse::NotFound().finish()) } else { - Ok(create_apub_response(&activity.data)) + Ok(create_json_apub_response(activity.data)) } }