]> Untitled Git - lemmy.git/commitdiff
Make Note.context optional for pleroma compat (hack)
authorFelix Ableitner <me@nutomic.com>
Tue, 26 Oct 2021 10:47:26 +0000 (12:47 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 29 Oct 2021 10:45:54 +0000 (12:45 +0200)
crates/apub/assets/pleroma-create-comment.json [new file with mode: 0644]
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/mod.rs

diff --git a/crates/apub/assets/pleroma-create-comment.json b/crates/apub/assets/pleroma-create-comment.json
new file mode 100644 (file)
index 0000000..55594ce
--- /dev/null
@@ -0,0 +1,52 @@
+{
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    "https://greenish.red/schemas/litepub-0.1.jsonld",
+    {
+      "@language": "und"
+    }
+  ],
+  "actor": "https://greenish.red/users/nutomic",
+  "cc": [
+    "https://greenish.red/users/nutomic/followers"
+  ],
+  "context": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
+  "context_id": 6336544,
+  "directMessage": false,
+  "id": "https://greenish.red/activities/db61d52b-9c35-486a-bf27-bbd4edc6c6a1",
+  "object": {
+    "actor": "https://greenish.red/users/nutomic",
+    "attachment": [],
+    "attributedTo": "https://greenish.red/users/nutomic",
+    "cc": [
+      "https://greenish.red/users/nutomic/followers"
+    ],
+    "content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"ACimPLEXPDd7enu3cm\" href=\"https://enterprise.lemmy.ml/u/picard\" rel=\"ugc\">@<span>lanodan</span></a></span> test",
+    "context": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
+    "conversation": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
+    "id": "https://greenish.red/objects/1a522f2e-d5ab-454b-93d7-e58bc0650c2a",
+    "inReplyTo": "https://enterprise.lemmy.ml/post/55143",
+    "published": "2021-10-26T10:28:35.602455Z",
+    "sensitive": false,
+    "source": "@lanodan@ds9.lemmy.ml test",
+    "summary": "",
+    "tag": [
+      {
+        "href": "https://enterprise.lemmy.ml/u/picard",
+        "name": "@lanodan@ds9.lemmy.ml",
+        "type": "Mention"
+      }
+    ],
+    "to": [
+      "https://enterprise.lemmy.ml/u/picard",
+      "https://www.w3.org/ns/activitystreams#Public"
+    ],
+    "type": "Note"
+  },
+  "published": "2021-10-26T10:28:35.595650Z",
+  "to": [
+    "https://enterprise.lemmy.ml/u/picard",
+    "https://www.w3.org/ns/activitystreams#Public"
+  ],
+  "type": "Create"
+}
\ No newline at end of file
index 9ccf49f05fc2168a989644b6454c619dd4444fb5..537563e9b7466c15a2b73c7435064fecc878e54f 100644 (file)
@@ -47,6 +47,7 @@ pub struct CreateOrUpdateComment {
   to: Vec<Url>,
   object: Note,
   cc: Vec<Url>,
+  #[serde(default)]
   tag: Vec<Mention>,
   #[serde(rename = "type")]
   kind: CreateOrUpdateType,
@@ -142,3 +143,16 @@ impl ActivityHandler for CreateOrUpdateComment {
     Ok(())
   }
 }
+
+#[cfg(test)]
+mod tests {
+  use super::*;
+  use crate::objects::tests::file_to_json_object;
+  use serial_test::serial;
+
+  #[actix_rt::test]
+  #[serial]
+  async fn test_parse_pleroma_create_comment() {
+    let _: CreateOrUpdateComment = file_to_json_object("assets/pleroma-create-comment.json");
+  }
+}
index b79f53e067cbfe2293d1177747175c3343f15165..927127d8ffc6fc8ae1146fd4fba05ea15c45b5de 100644 (file)
@@ -46,8 +46,11 @@ use url::Url;
 #[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct Note {
+  /// Necessary to make this optional to make Pleroma Create/Note work.
+  /// TODO: change this so that context is not defined in the struct itself, but added in activity
+  ///       queue and http handlers
   #[serde(rename = "@context")]
-  context: OneOrMany<AnyBase>,
+  context: Option<OneOrMany<AnyBase>>,
   r#type: NoteType,
   id: Url,
   pub(crate) attributed_to: ObjectId<ApubPerson>,
@@ -202,7 +205,7 @@ impl ApubObject for ApubComment {
     };
 
     let note = Note {
-      context: lemmy_context(),
+      context: Some(lemmy_context()),
       r#type: NoteType::Note,
       id: self.ap_id.to_owned().into_inner(),
       attributed_to: ObjectId::new(creator.actor_id),
@@ -274,7 +277,7 @@ impl ApubObject for ApubComment {
 }
 
 #[cfg(test)]
-mod tests {
+pub(crate) mod tests {
   use super::*;
   use crate::objects::{
     community::ApubCommunity,
@@ -283,7 +286,7 @@ mod tests {
   use assert_json_diff::assert_json_include;
   use serial_test::serial;
 
-  async fn prepare_comment_test(
+  pub(crate) async fn prepare_comment_test(
     url: &Url,
     context: &LemmyContext,
   ) -> (ApubPerson, ApubCommunity, ApubPost) {
@@ -310,9 +313,7 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_parse_lemmy_comment() {
-    // TODO: changed ObjectId::dereference() so that it always fetches if
-    //       last_refreshed_at() == None. But post doesnt store that and expects to never be refetched
+  pub(crate) async fn test_parse_lemmy_comment() {
     let context = init_context();
     let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
     let data = prepare_comment_test(&url, &context).await;
index 96700cb71dbabcac11ba46ec942824784b8aa20c..d0cb1341d68e98660037f96bf96be8a12ecc7ba2 100644 (file)
@@ -38,7 +38,7 @@ fn get_summary_from_string_or_source(
 }
 
 #[cfg(test)]
-mod tests {
+pub(crate) mod tests {
   use actix::Actor;
   use diesel::{
     r2d2::{ConnectionManager, Pool},