diff --git a/crates/apub/assets/lemmy-community.json b/crates/apub/assets/lemmy-community.json index 20feb1863..bf266eede 100644 --- a/crates/apub/assets/lemmy-community.json +++ b/crates/apub/assets/lemmy-community.json @@ -2,19 +2,19 @@ "@context": [ "https://www.w3.org/ns/activitystreams", { - "sensitive": "as:sensitive", "sc": "http://schema.org#", - "matrixUserId": { - "type": "sc:Text", - "id": "as:alsoKnownAs" - }, - "stickied": "as:stickied", + "sensitive": "as:sensitive", "pt": "https://join-lemmy.org#", "comments_enabled": { "type": "sc:Boolean", "id": "pt:commentsEnabled" }, - "moderators": "as:moderators" + "stickied": "as:stickied", + "moderators": "as:moderators", + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" + } }, "https://w3id.org/security/v1" ], diff --git a/crates/apub/assets/lemmy-person.json b/crates/apub/assets/lemmy-person.json index cc98dc1b7..110762386 100644 --- a/crates/apub/assets/lemmy-person.json +++ b/crates/apub/assets/lemmy-person.json @@ -2,15 +2,15 @@ "@context": [ "https://www.w3.org/ns/activitystreams", { - "sc": "http://schema.org#", - "pt": "https://join-lemmy.org#", + "stickied": "as:stickied", "comments_enabled": { "type": "sc:Boolean", "id": "pt:commentsEnabled" }, - "stickied": "as:stickied", + "pt": "https://join-lemmy.org#", "sensitive": "as:sensitive", "moderators": "as:moderators", + "sc": "http://schema.org#", "matrixUserId": { "type": "sc:Text", "id": "as:alsoKnownAs" diff --git a/crates/apub/assets/lemmy-post.json b/crates/apub/assets/lemmy-post.json new file mode 100644 index 000000000..956aa64dd --- /dev/null +++ b/crates/apub/assets/lemmy-post.json @@ -0,0 +1,41 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" + }, + "sc": "http://schema.org#", + "comments_enabled": { + "type": "sc:Boolean", + "id": "pt:commentsEnabled" + }, + "sensitive": "as:sensitive", + "stickied": "as:stickied", + "pt": "https://join-lemmy.org#", + "moderators": "as:moderators" + }, + "https://w3id.org/security/v1" + ], + "type": "Page", + "id": "https://lemmy.ml/post/70280", + "attributedTo": + "https://lemmy.ml/u/nutomic" + , + "to": [ + "https://lemmy.ml/c/meta", + "https://www.w3.org/ns/activitystreams#Public" + ], + "name": "What is lemmy.ml?", + "content": "

Recently there seems to be some of misunderstanding what the lemmy.ml instance is about, especially from newer users.

\n

Lemmy.ml has always been a niche site, and it will most likely stay this way. We don't have any intentions to turn it into a mainstream instance, or set a goal of getting as many users as possible. Our goal is simple: make an instance that people like to use. I would say that we have been successful in this, but obviously it is impossible to satisfy everyone.

\n

The reason for this is that @dessalines and I are paid to develop Lemmy, while donations from lemmy.ml users only make up a negligible part of our income. Besides, having more users would force us to spend more time moderating, and less time for development. Lemmy works quite differently from big tech sites like Reddit in this regard: while they get more money with each extra user through advertising, for us it is the opposite. So we would much rather have a smaller, non-toxic, and friendly userbase, than a large one.

\n

Part of the problem might be that lemmy.ml is described as "flagship instance", which can certainly be interpreted to mean "mainstream" or "general purpose". I struggle to come up with a better, more accurate description. If you can think of one, please comment here.

\n

If you dont like the way lemmy.ml works, thats okay. Federation exists exactly to solve that problem, let different groups have their own instances, with their own rules and political views. You can see the list of existing instances, and instructions for setting up a new one on join-lemmy.org.

\n

In particular, I would like to see someone (or a group of people) create a mainstream, or liberal instance. That should help to avoid further drama, and avoid attempts to turn lemmy.ml into something that it is not. @dessalines and I would certainly be willing to help with any technical problems that such an instance runs into, and include it on join-lemmy.org (just like any other instance that meets the code of conduct).

\n", + "mediaType": "text/html", + "source": { + "content": "Recently there seems to be some of misunderstanding what the lemmy.ml instance is about, especially from newer users.\n\nLemmy.ml has always been a niche site, and it will most likely stay this way. We don't have any intentions to turn it into a mainstream instance, or set a goal of getting as many users as possible. Our goal is simple: make an instance that people like to use. I would say that we have been successful in this, but obviously it is impossible to satisfy everyone.\n\nThe reason for this is that @dessalines and I are paid to develop Lemmy, while donations from lemmy.ml users only make up a negligible part of our income. Besides, having more users would force us to spend more time moderating, and less time for development. Lemmy works quite differently from big tech sites like Reddit in this regard: while they get more money with each extra user through advertising, for us it is the opposite. So we would much rather have a smaller, non-toxic, and friendly userbase, than a large one.\n\nPart of the problem might be that lemmy.ml is described as \"flagship instance\", which can certainly be interpreted to mean \"mainstream\" or \"general purpose\". I struggle to come up with a better, more accurate description. If you can think of one, please comment here.\n\nIf you dont like the way lemmy.ml works, thats okay. Federation exists exactly to solve that problem, let different groups have their own instances, with their own rules and political views. You can see the list of existing instances, and instructions for setting up a new one on [join-lemmy.org](https://join-lemmy.org/).\n\nIn particular, I would like to see someone (or a group of people) create a mainstream, or liberal instance. That should help to avoid further drama, and avoid attempts to turn lemmy.ml into something that it is not. @dessalines and I would certainly be willing to help with any technical problems that such an instance runs into, and include it on [join-lemmy.org](https://join-lemmy.org/) (just like any other instance that meets the code of conduct).", + "mediaType": "text/markdown" + }, + "commentsEnabled": false, + "sensitive": false, + "stickied": true, + "published": "2021-06-15T12:00:08.364559+00:00" +} diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 8e3d11162..af9828147 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -316,7 +316,8 @@ mod tests { async fn test_fetch_lemmy_community() { let json = file_to_json_object("assets/lemmy-community.json"); let url = Url::parse("https://lemmy.ml/c/meta").unwrap(); - let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut 0) + let mut request_counter = 0; + let community = ApubCommunity::from_apub(&json, &init_context(), &url, &mut request_counter) .await .unwrap(); @@ -325,5 +326,9 @@ mod tests { assert!(community.public_key.is_some()); assert!(!community.local); assert_eq!(community.description.as_ref().unwrap().len(), 158); + // TODO: its fetching the outbox, mod collection, and probably users from the outbox. due to + // caching and other things, this may change over multiple runs, so we cant assert it. + // find a way to avoid any network requests + //assert_eq!(request_counter, 4); } } diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index ada949890..431de761e 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -278,7 +278,8 @@ mod tests { async fn test_fetch_lemmy_person() { let json = file_to_json_object("assets/lemmy-person.json"); let url = Url::parse("https://lemmy.ml/u/nutomic").unwrap(); - let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut 0) + let mut request_counter = 0; + let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter) .await .unwrap(); @@ -287,6 +288,7 @@ mod tests { assert!(person.public_key.is_some()); assert!(!person.local); assert!(person.bio.is_some()); + assert_eq!(request_counter, 0); } #[actix_rt::test] @@ -294,7 +296,8 @@ mod tests { async fn test_fetch_pleroma_person() { let json = file_to_json_object("assets/pleroma-person.json"); let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap(); - let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut 0) + let mut request_counter = 0; + let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter) .await .unwrap(); @@ -302,6 +305,7 @@ mod tests { assert_eq!(person.name, "lanodan"); assert!(person.public_key.is_some()); assert!(!person.local); + assert_eq!(request_counter, 0); // TODO: pleroma uses summary for user profile, while we use content //assert!(person.bio.is_some()); } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 8d3265dfc..478c4c554 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -276,3 +276,30 @@ impl FromApub for ApubPost { Ok(post.into()) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::objects::tests::{file_to_json_object, init_context}; + use serial_test::serial; + + #[actix_rt::test] + #[serial] + async fn test_fetch_lemmy_post() { + let json = file_to_json_object("assets/lemmy-post.json"); + let url = Url::parse("https://lemmy.ml/post/70280").unwrap(); + let mut request_counter = 0; + let post = ApubPost::from_apub(&json, &init_context(), &url, &mut request_counter) + .await + .unwrap(); + + assert_eq!(post.ap_id.clone().into_inner(), url); + assert_eq!(post.name, "What is lemmy.ml?"); + assert!(post.body.is_some()); + assert_eq!(post.body.as_ref().unwrap().len(), 2052); + assert!(post.locked); + assert!(post.stickied); + // see comment in test_fetch_lemmy_community() about this + //assert_eq!(request_counter, 5); + } +} diff --git a/scripts/update_apub_test_files.sh b/scripts/update_apub_test_files.sh index c98d96108..aa7f0299c 100755 --- a/scripts/update_apub_test_files.sh +++ b/scripts/update_apub_test_files.sh @@ -5,5 +5,7 @@ curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \ > crates/apub/assets/lemmy-person.json curl -H "Accept: application/activity+json" https://lemmy.ml/c/meta | jq \ > crates/apub/assets/lemmy-community.json +curl -H "Accept: application/activity+json" https://lemmy.ml/post/70280 | jq \ + > crates/apub/assets/lemmy-post.json curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \ > crates/apub/assets/pleroma-person.json