]> Untitled Git - lemmy.git/commitdiff
Fixing activity serialization. Fixes #1900 (#1901)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 15 Nov 2021 20:26:48 +0000 (15:26 -0500)
committerGitHub <noreply@github.com>
Mon, 15 Nov 2021 20:26:48 +0000 (20:26 +0000)
crates/apub/src/context.rs
crates/apub/src/http/mod.rs

index 55486872ff592b714c038fcebaf683b28a38be50..a3a223a36f22bfa57956407e631698effde33440 100644 (file)
@@ -25,3 +25,19 @@ impl<T> WithContext<T> {
     self.inner
   }
 }
+
+#[derive(Serialize, Deserialize)]
+pub(crate) struct WithContextJson {
+  #[serde(rename = "@context")]
+  context: OneOrMany<AnyBase>,
+  inner: serde_json::Value,
+}
+
+impl WithContextJson {
+  pub(crate) fn new(inner: serde_json::Value) -> WithContextJson {
+    WithContextJson {
+      context: CONTEXT.clone(),
+      inner,
+    }
+  }
+}
index d35815ab2a31141ef5896de7a2e4bcfc8df07bbd..3dd068dd136af89455440c96446a6f8e6e522789 100644 (file)
@@ -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<Body> {
+  HttpResponse::Ok()
+    .content_type(APUB_JSON_CONTENT_TYPE)
+    .json(WithContextJson::new(data))
+}
+
 fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
 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))
   }
 }