From 09cd32034b256c144906b6a61bf4595642c4a0e4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 15 Nov 2021 15:26:48 -0500 Subject: [PATCH] Fixing activity serialization. Fixes #1900 (#1901) --- crates/apub/src/context.rs | 16 ++++++++++++++++ crates/apub/src/http/mod.rs | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/apub/src/context.rs b/crates/apub/src/context.rs index 55486872f..a3a223a36 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 d35815ab2..3dd068dd1 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)) } }