From: Felix Ableitner Date: Tue, 26 Oct 2021 10:47:26 +0000 (+0200) Subject: Make Note.context optional for pleroma compat (hack) X-Git-Url: http://these/git/%22https:/image.com/%22?a=commitdiff_plain;h=74523fb534e3c701fb1f42807b3173543b957d88;p=lemmy.git Make Note.context optional for pleroma compat (hack) --- diff --git a/crates/apub/assets/pleroma-create-comment.json b/crates/apub/assets/pleroma-create-comment.json new file mode 100644 index 00000000..55594ced --- /dev/null +++ b/crates/apub/assets/pleroma-create-comment.json @@ -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": "@lanodan 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 diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index 9ccf49f0..537563e9 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -47,6 +47,7 @@ pub struct CreateOrUpdateComment { to: Vec, object: Note, cc: Vec, + #[serde(default)] tag: Vec, #[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"); + } +} diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index b79f53e0..927127d8 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -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, + context: Option>, r#type: NoteType, id: Url, pub(crate) attributed_to: ObjectId, @@ -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; diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index 96700cb7..d0cb1341 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -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},