diff --git a/crates/apub/assets/lemmy-community.json b/crates/apub/assets/lemmy-community.json new file mode 100644 index 000000000..20feb1863 --- /dev/null +++ b/crates/apub/assets/lemmy-community.json @@ -0,0 +1,46 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "sensitive": "as:sensitive", + "sc": "http://schema.org#", + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" + }, + "stickied": "as:stickied", + "pt": "https://join-lemmy.org#", + "comments_enabled": { + "type": "sc:Boolean", + "id": "pt:commentsEnabled" + }, + "moderators": "as:moderators" + }, + "https://w3id.org/security/v1" + ], + "type": "Group", + "id": "https://lemmy.ml/c/meta", + "preferredUsername": "meta", + "name": "lemmy.ml meta", + "content": "

Anything about the lemmy.ml instance and its moderation.

\n

For discussion about the Lemmy software project, go to !lemmy@lemmy.ml.

\n", + "mediaType": "text/html", + "source": { + "content": "Anything about the lemmy.ml instance and its moderation. \n\nFor discussion about the Lemmy software project, go to [!lemmy@lemmy.ml](https://lemmy.ml/c/lemmy).", + "mediaType": "text/markdown" + }, + "sensitive": false, + "moderators": "https://lemmy.ml/c/meta/moderators", + "inbox": "https://lemmy.ml/c/meta/inbox", + "outbox": "https://lemmy.ml/c/meta/outbox", + "followers": "https://lemmy.ml/c/meta/followers", + "endpoints": { + "sharedInbox": "https://lemmy.ml/inbox" + }, + "publicKey": { + "id": "https://lemmy.ml/c/meta#main-key", + "owner": "https://lemmy.ml/c/meta", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApLImCO5LEXMWb6lPCfCI\necpxU17j8CFfrDJLUWcuCmKO9KxJFmsv9uY2sYr9YX9CD4o+jnJ4D/e+/D+UeJiD\naJ3aYLEjLm+u6KuAGVREjSLzp1Js/6F2k0MIIQueiO5BBiootEY6pv3CwqqMC9L4\npWvIjmd03dMBhU1DTAblrj61oGj3c5l0OPdjeW7XnTPSrCZvaQ/1PWwVyUj0y/SC\nHiUiUiqUD88aPB8c7s85Svzs5RFT8WHcelPXJ7ydhYlU8R2tE1Octjy9Gb1R38k4\ns62LiwlRUAIzvnpMWOBi60aRpL8+IuZXoB2cCEyX5SQ+ETVp5DobHDgI0zzBEjfD\nkQIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "published": "2021-06-14T22:50:50.985762+00:00", + "updated": "2021-06-14T23:29:55.801468+00:00" +} diff --git a/crates/apub/assets/lemmy-person.json b/crates/apub/assets/lemmy-person.json index fb1afbe9a..cc98dc1b7 100644 --- a/crates/apub/assets/lemmy-person.json +++ b/crates/apub/assets/lemmy-person.json @@ -2,18 +2,18 @@ "@context": [ "https://www.w3.org/ns/activitystreams", { - "moderators": "as:moderators", - "sensitive": "as:sensitive", - "pt": "https://join-lemmy.org#", "sc": "http://schema.org#", - "stickied": "as:stickied", - "matrixUserId": { - "type": "sc:Text", - "id": "as:alsoKnownAs" - }, + "pt": "https://join-lemmy.org#", "comments_enabled": { "type": "sc:Boolean", "id": "pt:commentsEnabled" + }, + "stickied": "as:stickied", + "sensitive": "as:sensitive", + "moderators": "as:moderators", + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" } }, "https://w3id.org/security/v1" diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index c4591c7c8..43bde2465 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -11,6 +11,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{ comment::{ApubComment, Note}, community::ApubCommunity, @@ -22,7 +23,6 @@ use lemmy_api_common::{blocking, check_post_deleted_or_removed}; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub}, - values::PublicUrl, verify::verify_domains_match, }; use lemmy_db_schema::{ @@ -38,7 +38,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct CreateOrUpdateComment { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: Note, cc: Vec, tag: Vec, @@ -76,7 +76,7 @@ impl CreateOrUpdateComment { let create_or_update = CreateOrUpdateComment { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: comment.to_apub(context.pool()).await?, cc: maa.ccs, tag: maa.tags, diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index e1cf03e0d..a5b597f52 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -10,6 +10,7 @@ use crate::{ context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -22,7 +23,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{ source::community::{CommunityModerator, CommunityModeratorForm}, @@ -37,7 +37,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct AddMod { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: ObjectId, target: Url, cc: [ObjectId; 1], @@ -63,7 +63,7 @@ impl AddMod { )?; let add = AddMod { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: ObjectId::new(added_mod.actor_id()), target: generate_moderators_url(&community.actor_id)?.into(), cc: [ObjectId::new(community.actor_id())], diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 183dbfd5f..3fefac15f 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -21,6 +21,7 @@ use crate::{ fetcher::object_id::ObjectId, http::is_activity_already_known, insert_activity, + migrations::PublicUrlMigration, objects::community::ApubCommunity, send_lemmy_activity, CommunityType, @@ -34,7 +35,6 @@ use activitystreams::{ use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; @@ -63,7 +63,7 @@ pub enum AnnouncableActivities { #[serde(rename_all = "camelCase")] pub struct AnnounceActivity { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: AnnouncableActivities, cc: Vec, #[serde(rename = "type")] @@ -84,7 +84,7 @@ impl AnnounceActivity { ) -> Result<(), LemmyError> { let announce = AnnounceActivity { actor: ObjectId::new(community.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object, cc: vec![community.followers_url()], kind: AnnounceType::Announce, diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index a1c76c23b..d8e131fc3 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -8,6 +8,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -20,7 +21,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{ source::community::{ @@ -40,7 +40,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct BlockUserFromCommunity { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, pub(in crate::activities::community) object: ObjectId, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -61,7 +61,7 @@ impl BlockUserFromCommunity { ) -> Result { Ok(BlockUserFromCommunity { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: ObjectId::new(target.actor_id()), cc: [ObjectId::new(community.actor_id())], kind: BlockType::Block, diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index b145e7171..d7186114d 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -11,6 +11,7 @@ use crate::{ context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -23,7 +24,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{ source::community::{CommunityModerator, CommunityModeratorForm}, @@ -38,7 +38,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct RemoveMod { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, pub(in crate::activities) object: ObjectId, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -65,7 +65,7 @@ impl RemoveMod { )?; let remove = RemoveMod { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: ObjectId::new(removed_mod.actor_id()), target: Some(generate_moderators_url(&community.actor_id)?.into()), id: id.clone(), diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index 1614de672..6b405cf48 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -12,6 +12,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -24,7 +25,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{ source::community::{CommunityPersonBan, CommunityPersonBanForm}, @@ -39,7 +39,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UndoBlockUserFromCommunity { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: BlockUserFromCommunity, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -66,7 +66,7 @@ impl UndoBlockUserFromCommunity { )?; let undo = UndoBlockUserFromCommunity { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: block, cc: [ObjectId::new(community.actor_id())], kind: UndoType::Undo, diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 1120bd8bb..3a7b44fee 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -8,6 +8,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{ community::{ApubCommunity, Group}, person::ApubPerson, @@ -23,7 +24,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType, ToApub}, - values::PublicUrl, }; use lemmy_db_schema::{ source::community::{Community, CommunityForm}, @@ -40,7 +40,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UpdateCommunity { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, // TODO: would be nice to use a separate struct here, which only contains the fields updated here object: Group, cc: [ObjectId; 1], @@ -65,7 +65,7 @@ impl UpdateCommunity { )?; let update = UpdateCommunity { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: community.to_apub(context.pool()).await?, cc: [ObjectId::new(community.actor_id())], kind: UpdateType::Update, diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 02df7dc38..acfc1ba7e 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -12,6 +12,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -25,7 +26,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{ source::{ @@ -66,7 +66,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct Delete { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, pub(in crate::activities::deletion) object: Url, pub(in crate::activities::deletion) cc: [ObjectId; 1], #[serde(rename = "type")] @@ -144,7 +144,7 @@ impl Delete { ) -> Result { Ok(Delete { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: object_id, cc: [ObjectId::new(community.actor_id())], kind: DeleteType::Delete, diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 327bf86c0..2527a9717 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -13,6 +13,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -26,7 +27,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post}; use lemmy_utils::LemmyError; @@ -42,7 +42,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UndoDelete { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: Delete, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -117,7 +117,7 @@ impl UndoDelete { )?; let undo = UndoDelete { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object, cc: [ObjectId::new(community.actor_id())], kind: UndoType::Undo, diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index cc7ef5c97..cda78ce1e 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -10,6 +10,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{ community::ApubCommunity, person::ApubPerson, @@ -22,7 +23,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub}, - values::PublicUrl, verify::{verify_domains_match, verify_urls_match}, }; use lemmy_db_schema::{source::community::Community, traits::Crud}; @@ -35,7 +35,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct CreateOrUpdatePost { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: Page, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -67,7 +67,7 @@ impl CreateOrUpdatePost { )?; let create_or_update = CreateOrUpdatePost { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: post.to_apub(context.pool()).await?, cc: [ObjectId::new(community.actor_id())], kind, diff --git a/crates/apub/src/activities/undo_remove.rs b/crates/apub/src/activities/undo_remove.rs index 5b41e0868..57346490c 100644 --- a/crates/apub/src/activities/undo_remove.rs +++ b/crates/apub/src/activities/undo_remove.rs @@ -5,6 +5,7 @@ use crate::{ verify_activity, }, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::{ @@ -16,7 +17,6 @@ use activitystreams::{ use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler}, - values::PublicUrl, }; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; @@ -27,7 +27,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UndoRemovePostCommentOrCommunity { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, // Note, there is no such thing as Undo/Remove/Mod, so we ignore that object: RemoveMod, cc: [ObjectId; 1], diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index d72b5245d..fa7a11195 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -12,6 +12,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, PostOrComment, }; @@ -25,7 +26,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, verify::verify_urls_match, }; use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud}; @@ -39,7 +39,7 @@ use url::Url; #[serde(rename_all = "camelCase")] pub struct UndoVote { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, object: Vote, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -72,7 +72,7 @@ impl UndoVote { )?; let undo_vote = UndoVote { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object, cc: [ObjectId::new(community.actor_id())], kind: UndoType::Undo, diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 5d4c9066e..847ffbd4c 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -8,6 +8,7 @@ use crate::{ }, context::lemmy_context, fetcher::object_id::ObjectId, + migrations::PublicUrlMigration, objects::{community::ApubCommunity, person::ApubPerson}, PostOrComment, }; @@ -17,7 +18,6 @@ use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, - values::PublicUrl, }; use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud}; use lemmy_utils::LemmyError; @@ -58,7 +58,7 @@ impl From<&VoteType> for i16 { #[serde(rename_all = "camelCase")] pub struct Vote { actor: ObjectId, - to: [PublicUrl; 1], + to: PublicUrlMigration, pub(in crate::activities::voting) object: ObjectId, cc: [ObjectId; 1], #[serde(rename = "type")] @@ -80,7 +80,7 @@ impl Vote { ) -> Result { Ok(Vote { actor: ObjectId::new(actor.actor_id()), - to: [PublicUrl::Public], + to: PublicUrlMigration::create(), object: ObjectId::new(object.ap_id()), cc: [ObjectId::new(community.actor_id())], kind: kind.clone(), diff --git a/crates/apub/src/fetcher/object_id.rs b/crates/apub/src/fetcher/object_id.rs index 4e439fb7f..38eb14cc7 100644 --- a/crates/apub/src/fetcher/object_id.rs +++ b/crates/apub/src/fetcher/object_id.rs @@ -22,6 +22,7 @@ use url::Url; static REQUEST_LIMIT: i32 = 25; #[derive(Clone, PartialEq, Serialize, Deserialize, Debug)] +#[serde(transparent)] pub struct ObjectId(Url, #[serde(skip)] PhantomData) where Kind: FromApub + ApubObject + Send + 'static, diff --git a/crates/apub/src/migrations.rs b/crates/apub/src/migrations.rs index 493518fe3..e8b075c45 100644 --- a/crates/apub/src/migrations.rs +++ b/crates/apub/src/migrations.rs @@ -1,4 +1,5 @@ use crate::fetcher::{object_id::ObjectId, post_or_comment::PostOrComment}; +use lemmy_apub_lib::values::PublicUrl; use serde::{Deserialize, Serialize}; use url::Url; @@ -28,3 +29,21 @@ pub enum CommentInReplyToMigration { // // For v0.13, delete [`UndoRemovePostCommentOrCommunity`], and don't handle object deletion in // [`RemoveMod`] handler. + +/// Migrate value of field `to` from single value to vec. +/// +/// v0.14: send as single value, accept both +/// v0.15: send as vec, accept both +/// v0.16: send and accept only vec +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum PublicUrlMigration { + Old(PublicUrl), + New([PublicUrl; 1]), +} + +impl PublicUrlMigration { + pub(crate) fn create() -> PublicUrlMigration { + PublicUrlMigration::Old(PublicUrl::Public) + } +} diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index e46dd7d00..8e3d11162 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -304,3 +304,26 @@ impl CommunityType for Community { Ok(inboxes) } } + +#[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_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) + .await + .unwrap(); + + assert_eq!(community.actor_id.clone().into_inner(), url); + assert_eq!(community.title, "lemmy.ml meta"); + assert!(community.public_key.is_some()); + assert!(!community.local); + assert_eq!(community.description.as_ref().unwrap().len(), 158); + } +} diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index 147215e91..61f0f2808 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -112,7 +112,7 @@ mod tests { } let chat_server = ChatServer::startup( pool.clone(), - rate_limiter.clone(), + rate_limiter, |_, _, _, _| Box::pin(x()), |_, _, _, _| Box::pin(x()), client.clone(), diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 775adeca5..ada949890 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -285,7 +285,7 @@ mod tests { assert_eq!(person.actor_id.clone().into_inner(), url); assert_eq!(person.name, "nutomic"); assert!(person.public_key.is_some()); - assert_eq!(person.local, false); + assert!(!person.local); assert!(person.bio.is_some()); } @@ -301,7 +301,7 @@ mod tests { assert_eq!(person.actor_id.clone().into_inner(), url); assert_eq!(person.name, "lanodan"); assert!(person.public_key.is_some()); - assert_eq!(person.local, false); + assert!(!person.local); // 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 97419cfff..8d3265dfc 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -54,7 +54,7 @@ pub struct Page { to: [Url; 2], name: String, content: Option, - media_type: MediaTypeHtml, + media_type: Option, source: Option, url: Option, image: Option, @@ -189,7 +189,7 @@ impl ToApub for ApubPost { to: [community.actor_id.into(), public()], name: self.name.clone(), content: self.body.as_ref().map(|b| markdown_to_html(b)), - media_type: MediaTypeHtml::Html, + media_type: Some(MediaTypeHtml::Html), source, url: self.url.clone().map(|u| u.into()), image, diff --git a/scripts/update_apub_test_files.sh b/scripts/update_apub_test_files.sh index b62fc3b6c..c98d96108 100755 --- a/scripts/update_apub_test_files.sh +++ b/scripts/update_apub_test_files.sh @@ -3,5 +3,7 @@ set -e 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://queer.hacktivis.me/users/lanodan | jq \ - > crates/apub/assets/pleroma-person.json \ No newline at end of file + > crates/apub/assets/pleroma-person.json