From afccd5cf6955e795bdd29b62f6ecca5b0fd06997 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 19 Nov 2021 18:47:06 +0100 Subject: [PATCH] Replace activitystreams crate with activitystreams-kinds --- Cargo.lock | 12 ++++++- crates/apub/Cargo.toml | 2 +- .../activities/comment/create_or_update.rs | 7 ++-- .../apub/src/activities/community/add_mod.rs | 2 +- .../apub/src/activities/community/announce.rs | 2 +- .../src/activities/community/block_user.rs | 2 +- .../src/activities/community/remove_mod.rs | 2 +- .../apub/src/activities/community/report.rs | 2 +- .../activities/community/undo_block_user.rs | 2 +- .../apub/src/activities/community/update.rs | 2 +- crates/apub/src/activities/deletion/delete.rs | 2 +- .../src/activities/deletion/undo_delete.rs | 2 +- .../apub/src/activities/following/accept.rs | 2 +- .../apub/src/activities/following/follow.rs | 2 +- .../src/activities/following/undo_follow.rs | 2 +- crates/apub/src/activities/mod.rs | 2 +- .../src/activities/post/create_or_update.rs | 2 +- .../src/activities/private_message/delete.rs | 2 +- .../activities/private_message/undo_delete.rs | 2 +- .../apub/src/activities/voting/undo_vote.rs | 2 +- crates/apub/src/activities/voting/vote.rs | 2 +- .../src/collections/community_moderators.rs | 3 +- .../apub/src/collections/community_outbox.rs | 2 +- crates/apub/src/context.rs | 7 ++-- crates/apub/src/fetcher/user_or_community.rs | 3 +- crates/apub/src/mentions.rs | 34 ++++++++++++------- crates/apub/src/objects/comment.rs | 2 +- crates/apub/src/objects/community.rs | 12 ++----- crates/apub/src/objects/person.rs | 11 ++---- crates/apub/src/objects/post.rs | 10 ++---- .../protocol/activities/community/add_mod.rs | 4 +-- .../protocol/activities/community/announce.rs | 8 +++-- .../activities/community/block_user.rs | 7 ++-- .../src/protocol/activities/community/mod.rs | 6 ++-- .../activities/community/remove_mod.rs | 4 +-- .../protocol/activities/community/report.rs | 3 +- .../activities/community/undo_block_user.rs | 4 +-- .../protocol/activities/community/update.rs | 7 ++-- .../activities/create_or_update/comment.rs | 4 +-- .../activities/create_or_update/mod.rs | 2 -- .../activities/create_or_update/post.rs | 3 +- .../protocol/activities/deletion/delete.rs | 7 ++-- .../src/protocol/activities/deletion/mod.rs | 2 -- .../activities/deletion/undo_delete.rs | 7 ++-- .../protocol/activities/following/accept.rs | 4 +-- .../protocol/activities/following/follow.rs | 7 ++-- .../src/protocol/activities/following/mod.rs | 2 -- .../activities/following/undo_follow.rs | 4 +-- .../private_message/create_or_update.rs | 3 +- .../activities/private_message/delete.rs | 7 ++-- .../activities/private_message/mod.rs | 2 -- .../activities/private_message/undo_delete.rs | 4 +-- .../src/protocol/activities/voting/mod.rs | 2 -- .../protocol/activities/voting/undo_vote.rs | 7 ++-- .../src/protocol/activities/voting/vote.rs | 7 ++-- .../protocol/collections/group_followers.rs | 2 +- .../protocol/collections/group_moderators.rs | 2 +- .../src/protocol/collections/group_outbox.rs | 2 +- crates/apub/src/protocol/collections/mod.rs | 2 -- .../src/protocol/collections/person_outbox.rs | 2 +- crates/apub/src/protocol/mod.rs | 19 +++++++++-- .../apub/src/protocol/objects/chat_message.rs | 7 ++-- crates/apub/src/protocol/objects/group.rs | 4 +-- crates/apub/src/protocol/objects/mod.rs | 2 -- crates/apub/src/protocol/objects/note.rs | 5 +-- crates/apub/src/protocol/objects/page.rs | 4 +-- crates/apub/src/protocol/objects/person.rs | 4 +-- crates/apub/src/protocol/objects/tombstone.rs | 2 +- 68 files changed, 169 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32545d2ae..abb501359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,16 @@ dependencies = [ "url", ] +[[package]] +name = "activitystreams-kinds" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0784e99afd032199d3ed70cefb8eb3a8d1aef15f7f2c4e68d033c4e12bb6079e" +dependencies = [ + "serde", + "url", +] + [[package]] name = "actix" version = "0.12.0" @@ -1842,7 +1852,7 @@ dependencies = [ name = "lemmy_apub" version = "0.14.1" dependencies = [ - "activitystreams", + "activitystreams-kinds", "actix", "actix-rt", "actix-web", diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index 94684413b..b4ddff281 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -21,7 +21,7 @@ lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } lemmy_api_common = { version = "=0.14.1", path = "../api_common" } lemmy_websocket = { version = "=0.14.1", path = "../websocket" } diesel = "1.4.8" -activitystreams = "0.7.0-alpha.11" +activitystreams-kinds = "0.1.2" bcrypt = "0.10.1" chrono = { version = "0.4.19", features = ["serde"] } serde_json = { version = "1.0.68", features = ["preserve_order"] } diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index ad686251b..14fc14014 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -12,7 +12,7 @@ use crate::{ objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType}, }; -use activitystreams::{link::LinkExt, public}; +use activitystreams_kinds::public; use lemmy_api_common::{blocking, check_post_deleted_or_removed}; use lemmy_apub_lib::{ data::Data, @@ -65,9 +65,8 @@ impl CreateOrUpdateComment { let tagged_users: Vec> = create_or_update .tag .iter() - .map(|t| t.href()) - .flatten() - .map(|t| ObjectId::new(t.clone())) + .map(|t| t.href.clone()) + .map(ObjectId::new) .collect(); let mut inboxes = vec![]; for t in tagged_users { diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 7437750db..c244f652d 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -17,7 +17,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::add_mod::AddMod, }; -use activitystreams::{activity::kind::AddType, public}; +use activitystreams_kinds::{activity::AddType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 9d76b5240..2784039bc 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -6,7 +6,7 @@ use crate::{ objects::community::ApubCommunity, protocol::activities::{community::announce::AnnounceActivity, CreateOrUpdateType}, }; -use activitystreams::{activity::kind::AnnounceType, public}; +use activitystreams_kinds::{activity::AnnounceType, public}; use lemmy_apub_lib::{ data::Data, object_id::ObjectId, diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index 0dbf47b3c..0442fcc47 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -11,7 +11,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::block_user::BlockUserFromCommunity, }; -use activitystreams::{activity::kind::BlockType, public}; +use activitystreams_kinds::{activity::BlockType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index 985a21922..363120705 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -17,7 +17,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::remove_mod::RemoveMod, }; -use activitystreams::{activity::kind::RemoveType, public}; +use activitystreams_kinds::{activity::RemoveType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index f0be3e0a0..7207af618 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -9,7 +9,7 @@ use crate::{ protocol::activities::community::report::Report, PostOrComment, }; -use activitystreams::activity::kind::FlagType; +use activitystreams_kinds::activity::FlagType; use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse}; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index 4aabb1d4c..dbd6c5d50 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -14,7 +14,7 @@ use crate::{ undo_block_user::UndoBlockUserFromCommunity, }, }; -use activitystreams::{activity::kind::UndoType, public}; +use activitystreams_kinds::{activity::UndoType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index e625fe0c7..7b2af3c47 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -11,7 +11,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::update::UpdateCommunity, }; -use activitystreams::{activity::kind::UpdateType, public}; +use activitystreams_kinds::{activity::UpdateType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index b976a1b46..e50cfd852 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -10,7 +10,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::deletion::delete::Delete, }; -use activitystreams::{activity::kind::DeleteType, public}; +use activitystreams_kinds::{activity::DeleteType, public}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 28ad0f5a3..8a867fbc2 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -10,7 +10,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete}, }; -use activitystreams::{activity::kind::UndoType, public}; +use activitystreams_kinds::{activity::UndoType, public}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index 15e1f2b4a..6febd7d43 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -2,7 +2,7 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_activity}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, }; -use activitystreams::activity::kind::AcceptType; +use activitystreams_kinds::activity::AcceptType; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 43c600284..a5c2e77f0 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -9,7 +9,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, }; -use activitystreams::activity::kind::FollowType; +use activitystreams_kinds::activity::FollowType; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index 2a3483d45..c7b926a2b 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -3,7 +3,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity}, }; -use activitystreams::activity::kind::UndoType; +use activitystreams_kinds::activity::UndoType; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index cac5d6e1e..07fc39d2f 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -5,7 +5,7 @@ use crate::{ insert_activity, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::public; +use activitystreams_kinds::public; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index 84c185bef..2e9c8071d 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -12,7 +12,7 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType}, }; -use activitystreams::public; +use activitystreams_kinds::public; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/activities/private_message/delete.rs b/crates/apub/src/activities/private_message/delete.rs index 46675442f..7269078af 100644 --- a/crates/apub/src/activities/private_message/delete.rs +++ b/crates/apub/src/activities/private_message/delete.rs @@ -3,7 +3,7 @@ use crate::{ objects::{person::ApubPerson, private_message::ApubPrivateMessage}, protocol::activities::private_message::delete::DeletePrivateMessage, }; -use activitystreams::activity::kind::DeleteType; +use activitystreams_kinds::activity::DeleteType; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/private_message/undo_delete.rs b/crates/apub/src/activities/private_message/undo_delete.rs index fbb8660c3..ce3cc49cb 100644 --- a/crates/apub/src/activities/private_message/undo_delete.rs +++ b/crates/apub/src/activities/private_message/undo_delete.rs @@ -6,7 +6,7 @@ use crate::{ undo_delete::UndoDeletePrivateMessage, }, }; -use activitystreams::activity::kind::UndoType; +use activitystreams_kinds::activity::UndoType; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index e403a335a..f913ce5f1 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -15,7 +15,7 @@ use crate::{ }, PostOrComment, }; -use activitystreams::{activity::kind::UndoType, public}; +use activitystreams_kinds::{activity::UndoType, public}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 2253b9aa7..65a928002 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -12,7 +12,7 @@ use crate::{ protocol::activities::voting::vote::{Vote, VoteType}, PostOrComment, }; -use activitystreams::public; +use activitystreams_kinds::public; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index 695f7aca1..1b0911ab7 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -4,7 +4,8 @@ use crate::{ objects::person::ApubPerson, protocol::collections::group_moderators::GroupModerators, }; -use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType}; +use activitystreams_kinds::collection::OrderedCollectionType; +use chrono::NaiveDateTime; use lemmy_api_common::blocking; use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject, verify::verify_domains_match}; use lemmy_db_schema::{ diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 69dfd929f..de55ffa6e 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -8,7 +8,7 @@ use crate::{ collections::group_outbox::GroupOutbox, }, }; -use activitystreams::collection::kind::OrderedCollectionType; +use activitystreams_kinds::collection::OrderedCollectionType; use chrono::NaiveDateTime; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/context.rs b/crates/apub/src/context.rs index 55486872f..0a6e220a7 100644 --- a/crates/apub/src/context.rs +++ b/crates/apub/src/context.rs @@ -1,15 +1,14 @@ -use activitystreams::{base::AnyBase, primitives::OneOrMany}; use serde::{Deserialize, Serialize}; lazy_static! { - static ref CONTEXT: OneOrMany = + static ref CONTEXT: Vec = serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context"); } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub(crate) struct WithContext { #[serde(rename = "@context")] - context: OneOrMany, + context: Vec, #[serde(flatten)] inner: T, } diff --git a/crates/apub/src/fetcher/user_or_community.rs b/crates/apub/src/fetcher/user_or_community.rs index e5dc3d935..08138964c 100644 --- a/crates/apub/src/fetcher/user_or_community.rs +++ b/crates/apub/src/fetcher/user_or_community.rs @@ -2,11 +2,12 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson}, protocol::objects::{group::Group, person::Person}, }; -use activitystreams::{chrono::NaiveDateTime, url::Url}; +use chrono::NaiveDateTime; use lemmy_apub_lib::traits::{ActorType, ApubObject}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use serde::Deserialize; +use url::Url; #[derive(Clone, Debug)] pub enum UserOrCommunity { diff --git a/crates/apub/src/mentions.rs b/crates/apub/src/mentions.rs index 2cf0e757a..f8de43855 100644 --- a/crates/apub/src/mentions.rs +++ b/crates/apub/src/mentions.rs @@ -2,10 +2,7 @@ use crate::{ fetcher::webfinger::webfinger_resolve_actor, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - base::BaseExt, - link::{LinkExt, Mention}, -}; +use activitystreams_kinds::link::MentionType; use lemmy_api_common::blocking; use lemmy_apub_lib::{object_id::ObjectId, traits::ActorType}; use lemmy_db_schema::{ @@ -18,8 +15,17 @@ use lemmy_utils::{ LemmyError, }; use lemmy_websocket::LemmyContext; +use serde::{Deserialize, Serialize}; use url::Url; +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Mention { + pub href: Url, + name: Option, + #[serde(rename = "type")] + pub kind: MentionType, +} + pub struct MentionsAndAddresses { pub ccs: Vec, pub tags: Vec, @@ -38,14 +44,15 @@ pub async fn collect_non_local_mentions( let mut addressed_ccs: Vec = vec![community_id.into(), parent_creator.actor_id()]; // Add the mention tag - let mut parent_creator_tag = Mention::new(); - parent_creator_tag - .set_href(parent_creator.actor_id.clone().into()) - .set_name(format!( + let parent_creator_tag = Mention { + href: parent_creator.actor_id.clone().into(), + name: Some(format!( "@{}@{}", &parent_creator.name, &parent_creator.actor_id().domain().expect("has domain") - )); + )), + kind: MentionType::Mention, + }; let mut tags = vec![parent_creator_tag]; // Get the person IDs for any mentions @@ -64,10 +71,11 @@ pub async fn collect_non_local_mentions( let actor_id: ObjectId = ObjectId::new(actor_id); addressed_ccs.push(actor_id.to_string().parse()?); - let mut mention_tag = Mention::new(); - mention_tag - .set_href(actor_id.into()) - .set_name(mention.full_name()); + let mention_tag = Mention { + href: actor_id.into(), + name: Some(mention.full_name()), + kind: MentionType::Mention, + }; tags.push(mention_tag); } } diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index f15084cc4..007d3def4 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -11,7 +11,7 @@ use crate::{ }, PostOrComment, }; -use activitystreams::{object::kind::NoteType, public}; +use activitystreams_kinds::{object::NoteType, public}; use anyhow::anyhow; use chrono::NaiveDateTime; use html2md::parse_html; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index f37d82d8c..d8bc837fb 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -9,7 +9,7 @@ use crate::{ Source, }, }; -use activitystreams::{actor::kind::GroupType, object::kind::ImageType}; +use activitystreams_kinds::actor::GroupType; use chrono::NaiveDateTime; use itertools::Itertools; use lemmy_api_common::blocking; @@ -81,14 +81,8 @@ impl ApubObject for ApubCommunity { content: bio, media_type: MediaTypeMarkdown::Markdown, }); - let icon = self.icon.clone().map(|url| ImageObject { - kind: ImageType::Image, - url: url.into(), - }); - let image = self.banner.clone().map(|url| ImageObject { - kind: ImageType::Image, - url: url.into(), - }); + let icon = self.icon.clone().map(ImageObject::new); + let image = self.banner.clone().map(ImageObject::new); let group = Group { kind: GroupType::Group, diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index e3fcdd2ee..422862cbf 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -11,7 +11,6 @@ use crate::{ Source, }, }; -use activitystreams::object::kind::ImageType; use chrono::NaiveDateTime; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -89,14 +88,8 @@ impl ApubObject for ApubPerson { content: bio, media_type: MediaTypeMarkdown::Markdown, }); - let icon = self.avatar.clone().map(|url| ImageObject { - kind: ImageType::Image, - url: url.into(), - }); - let image = self.banner.clone().map(|url| ImageObject { - kind: ImageType::Image, - url: url.into(), - }); + let icon = self.avatar.clone().map(ImageObject::new); + let image = self.banner.clone().map(ImageObject::new); let person = Person { kind, diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 44dbe73bd..1d4eddb9c 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -7,10 +7,7 @@ use crate::{ Source, }, }; -use activitystreams::{ - object::kind::{ImageType, PageType}, - public, -}; +use activitystreams_kinds::{object::PageType, public}; use chrono::NaiveDateTime; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -100,10 +97,7 @@ impl ApubObject for ApubPost { content: body, media_type: MediaTypeMarkdown::Markdown, }); - let image = self.thumbnail_url.clone().map(|thumb| ImageObject { - kind: ImageType::Image, - url: thumb.into(), - }); + let image = self.thumbnail_url.clone().map(ImageObject::new); let page = Page { r#type: PageType::Page, diff --git a/crates/apub/src/protocol/activities/community/add_mod.rs b/crates/apub/src/protocol/activities/community/add_mod.rs index 75571bea8..0d6edc0a6 100644 --- a/crates/apub/src/protocol/activities/community/add_mod.rs +++ b/crates/apub/src/protocol/activities/community/add_mod.rs @@ -1,5 +1,5 @@ -use crate::objects::person::ApubPerson; -use activitystreams::{activity::kind::AddType, unparsed::Unparsed}; +use crate::{objects::person::ApubPerson, protocol::Unparsed}; +use activitystreams_kinds::activity::AddType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/announce.rs b/crates/apub/src/protocol/activities/community/announce.rs index 2dd094041..11890c680 100644 --- a/crates/apub/src/protocol/activities/community/announce.rs +++ b/crates/apub/src/protocol/activities/community/announce.rs @@ -1,5 +1,9 @@ -use crate::{activity_lists::AnnouncableActivities, objects::community::ApubCommunity}; -use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed}; +use crate::{ + activity_lists::AnnouncableActivities, + objects::community::ApubCommunity, + protocol::Unparsed, +}; +use activitystreams_kinds::activity::AnnounceType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/block_user.rs b/crates/apub/src/protocol/activities/community/block_user.rs index 0b974f697..c904fc218 100644 --- a/crates/apub/src/protocol/activities/community/block_user.rs +++ b/crates/apub/src/protocol/activities/community/block_user.rs @@ -1,5 +1,8 @@ -use crate::objects::{community::ApubCommunity, person::ApubPerson}; -use activitystreams::{activity::kind::BlockType, unparsed::Unparsed}; +use crate::{ + objects::{community::ApubCommunity, person::ApubPerson}, + protocol::Unparsed, +}; +use activitystreams_kinds::activity::BlockType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/mod.rs b/crates/apub/src/protocol/activities/community/mod.rs index a7bc81411..4f1f2be91 100644 --- a/crates/apub/src/protocol/activities/community/mod.rs +++ b/crates/apub/src/protocol/activities/community/mod.rs @@ -11,6 +11,7 @@ mod tests { use crate::protocol::{ activities::community::{ add_mod::AddMod, + announce::AnnounceActivity, block_user::BlockUserFromCommunity, remove_mod::RemoveMod, report::Report, @@ -19,13 +20,10 @@ mod tests { }, tests::test_parse_lemmy_item, }; - use activitystreams::activity::Announce; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_community() { - test_parse_lemmy_item::( + test_parse_lemmy_item::( "assets/lemmy/activities/community/announce_create_page.json", ); diff --git a/crates/apub/src/protocol/activities/community/remove_mod.rs b/crates/apub/src/protocol/activities/community/remove_mod.rs index 6e3e5458c..dc456b0b0 100644 --- a/crates/apub/src/protocol/activities/community/remove_mod.rs +++ b/crates/apub/src/protocol/activities/community/remove_mod.rs @@ -1,5 +1,5 @@ -use crate::objects::person::ApubPerson; -use activitystreams::{activity::kind::RemoveType, unparsed::Unparsed}; +use crate::{objects::person::ApubPerson, protocol::Unparsed}; +use activitystreams_kinds::activity::RemoveType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/report.rs b/crates/apub/src/protocol/activities/community/report.rs index fbf21ec8d..bf1a84f17 100644 --- a/crates/apub/src/protocol/activities/community/report.rs +++ b/crates/apub/src/protocol/activities/community/report.rs @@ -1,8 +1,9 @@ use crate::{ fetcher::post_or_comment::PostOrComment, objects::{community::ApubCommunity, person::ApubPerson}, + protocol::Unparsed, }; -use activitystreams::{activity::kind::FlagType, unparsed::Unparsed}; +use activitystreams_kinds::activity::FlagType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/undo_block_user.rs b/crates/apub/src/protocol/activities/community/undo_block_user.rs index 538a7e25c..f08e0c352 100644 --- a/crates/apub/src/protocol/activities/community/undo_block_user.rs +++ b/crates/apub/src/protocol/activities/community/undo_block_user.rs @@ -1,8 +1,8 @@ use crate::{ objects::person::ApubPerson, - protocol::activities::community::block_user::BlockUserFromCommunity, + protocol::{activities::community::block_user::BlockUserFromCommunity, Unparsed}, }; -use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; +use activitystreams_kinds::activity::UndoType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/community/update.rs b/crates/apub/src/protocol/activities/community/update.rs index 9a831a1f8..9bdcded9a 100644 --- a/crates/apub/src/protocol/activities/community/update.rs +++ b/crates/apub/src/protocol/activities/community/update.rs @@ -1,5 +1,8 @@ -use crate::{objects::person::ApubPerson, protocol::objects::group::Group}; -use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed}; +use crate::{ + objects::person::ApubPerson, + protocol::{objects::group::Group, Unparsed}, +}; +use activitystreams_kinds::activity::UpdateType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/create_or_update/comment.rs b/crates/apub/src/protocol/activities/create_or_update/comment.rs index 6e90dedb0..deef4c862 100644 --- a/crates/apub/src/protocol/activities/create_or_update/comment.rs +++ b/crates/apub/src/protocol/activities/create_or_update/comment.rs @@ -1,8 +1,8 @@ use crate::{ + mentions::Mention, objects::person::ApubPerson, - protocol::{activities::CreateOrUpdateType, objects::note::Note}, + protocol::{activities::CreateOrUpdateType, objects::note::Note, Unparsed}, }; -use activitystreams::{link::Mention, unparsed::Unparsed}; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/create_or_update/mod.rs b/crates/apub/src/protocol/activities/create_or_update/mod.rs index f5db71c20..6506c283b 100644 --- a/crates/apub/src/protocol/activities/create_or_update/mod.rs +++ b/crates/apub/src/protocol/activities/create_or_update/mod.rs @@ -10,10 +10,8 @@ mod tests { tests::test_parse_lemmy_item, }, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_create_or_update() { test_parse_lemmy_item::( "assets/lemmy/activities/create_or_update/create_page.json", diff --git a/crates/apub/src/protocol/activities/create_or_update/post.rs b/crates/apub/src/protocol/activities/create_or_update/post.rs index e64e48408..db159c860 100644 --- a/crates/apub/src/protocol/activities/create_or_update/post.rs +++ b/crates/apub/src/protocol/activities/create_or_update/post.rs @@ -1,8 +1,7 @@ use crate::{ objects::person::ApubPerson, - protocol::{activities::CreateOrUpdateType, objects::page::Page}, + protocol::{activities::CreateOrUpdateType, objects::page::Page, Unparsed}, }; -use activitystreams::unparsed::Unparsed; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/deletion/delete.rs b/crates/apub/src/protocol/activities/deletion/delete.rs index 26aee276e..49adb6e65 100644 --- a/crates/apub/src/protocol/activities/deletion/delete.rs +++ b/crates/apub/src/protocol/activities/deletion/delete.rs @@ -1,5 +1,8 @@ -use crate::{objects::person::ApubPerson, protocol::objects::tombstone::Tombstone}; -use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed}; +use crate::{ + objects::person::ApubPerson, + protocol::{objects::tombstone::Tombstone, Unparsed}, +}; +use activitystreams_kinds::activity::DeleteType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; diff --git a/crates/apub/src/protocol/activities/deletion/mod.rs b/crates/apub/src/protocol/activities/deletion/mod.rs index 647c3d507..a4e08fab2 100644 --- a/crates/apub/src/protocol/activities/deletion/mod.rs +++ b/crates/apub/src/protocol/activities/deletion/mod.rs @@ -7,10 +7,8 @@ mod tests { activities::deletion::{delete::Delete, undo_delete::UndoDelete}, tests::test_parse_lemmy_item, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_deletion() { test_parse_lemmy_item::("assets/lemmy/activities/deletion/remove_note.json"); test_parse_lemmy_item::("assets/lemmy/activities/deletion/delete_page.json"); diff --git a/crates/apub/src/protocol/activities/deletion/undo_delete.rs b/crates/apub/src/protocol/activities/deletion/undo_delete.rs index aa851cbc7..d76080170 100644 --- a/crates/apub/src/protocol/activities/deletion/undo_delete.rs +++ b/crates/apub/src/protocol/activities/deletion/undo_delete.rs @@ -1,5 +1,8 @@ -use crate::{objects::person::ApubPerson, protocol::activities::deletion::delete::Delete}; -use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; +use crate::{ + objects::person::ApubPerson, + protocol::{activities::deletion::delete::Delete, Unparsed}, +}; +use activitystreams_kinds::activity::UndoType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/following/accept.rs b/crates/apub/src/protocol/activities/following/accept.rs index 2d5acb3be..09d3419a1 100644 --- a/crates/apub/src/protocol/activities/following/accept.rs +++ b/crates/apub/src/protocol/activities/following/accept.rs @@ -1,8 +1,8 @@ use crate::{ objects::community::ApubCommunity, - protocol::activities::following::follow::FollowCommunity, + protocol::{activities::following::follow::FollowCommunity, Unparsed}, }; -use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed}; +use activitystreams_kinds::activity::AcceptType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/following/follow.rs b/crates/apub/src/protocol/activities/following/follow.rs index fe4e4e7b9..cc2cc8e0a 100644 --- a/crates/apub/src/protocol/activities/following/follow.rs +++ b/crates/apub/src/protocol/activities/following/follow.rs @@ -1,5 +1,8 @@ -use crate::objects::{community::ApubCommunity, person::ApubPerson}; -use activitystreams::{activity::kind::FollowType, unparsed::Unparsed}; +use crate::{ + objects::{community::ApubCommunity, person::ApubPerson}, + protocol::Unparsed, +}; +use activitystreams_kinds::activity::FollowType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/following/mod.rs b/crates/apub/src/protocol/activities/following/mod.rs index 473dfca35..3258dbb7e 100644 --- a/crates/apub/src/protocol/activities/following/mod.rs +++ b/crates/apub/src/protocol/activities/following/mod.rs @@ -12,10 +12,8 @@ mod tests { }, tests::test_parse_lemmy_item, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_accept_follow() { test_parse_lemmy_item::("assets/lemmy/activities/following/follow.json"); test_parse_lemmy_item::("assets/lemmy/activities/following/accept.json"); diff --git a/crates/apub/src/protocol/activities/following/undo_follow.rs b/crates/apub/src/protocol/activities/following/undo_follow.rs index f2feba14b..f14e3a48d 100644 --- a/crates/apub/src/protocol/activities/following/undo_follow.rs +++ b/crates/apub/src/protocol/activities/following/undo_follow.rs @@ -1,8 +1,8 @@ use crate::{ objects::person::ApubPerson, - protocol::activities::following::follow::FollowCommunity, + protocol::{activities::following::follow::FollowCommunity, Unparsed}, }; -use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; +use activitystreams_kinds::activity::UndoType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/private_message/create_or_update.rs b/crates/apub/src/protocol/activities/private_message/create_or_update.rs index 756bfd5e9..a319daff5 100644 --- a/crates/apub/src/protocol/activities/private_message/create_or_update.rs +++ b/crates/apub/src/protocol/activities/private_message/create_or_update.rs @@ -1,8 +1,7 @@ use crate::{ objects::person::ApubPerson, - protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage}, + protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage, Unparsed}, }; -use activitystreams::unparsed::Unparsed; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/private_message/delete.rs b/crates/apub/src/protocol/activities/private_message/delete.rs index f9ad29fde..1156b0e8e 100644 --- a/crates/apub/src/protocol/activities/private_message/delete.rs +++ b/crates/apub/src/protocol/activities/private_message/delete.rs @@ -1,5 +1,8 @@ -use crate::objects::{person::ApubPerson, private_message::ApubPrivateMessage}; -use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed}; +use crate::{ + objects::{person::ApubPerson, private_message::ApubPrivateMessage}, + protocol::Unparsed, +}; +use activitystreams_kinds::activity::DeleteType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/private_message/mod.rs b/crates/apub/src/protocol/activities/private_message/mod.rs index b54e66c0c..de074ba69 100644 --- a/crates/apub/src/protocol/activities/private_message/mod.rs +++ b/crates/apub/src/protocol/activities/private_message/mod.rs @@ -12,10 +12,8 @@ mod tests { }, tests::test_parse_lemmy_item, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_private_message() { test_parse_lemmy_item::( "assets/lemmy/activities/private_message/create.json", diff --git a/crates/apub/src/protocol/activities/private_message/undo_delete.rs b/crates/apub/src/protocol/activities/private_message/undo_delete.rs index 951f14d4a..3ce260758 100644 --- a/crates/apub/src/protocol/activities/private_message/undo_delete.rs +++ b/crates/apub/src/protocol/activities/private_message/undo_delete.rs @@ -1,8 +1,8 @@ use crate::{ objects::person::ApubPerson, - protocol::activities::private_message::delete::DeletePrivateMessage, + protocol::{activities::private_message::delete::DeletePrivateMessage, Unparsed}, }; -use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; +use activitystreams_kinds::activity::UndoType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/voting/mod.rs b/crates/apub/src/protocol/activities/voting/mod.rs index 48e30f0b1..b38e7fe3d 100644 --- a/crates/apub/src/protocol/activities/voting/mod.rs +++ b/crates/apub/src/protocol/activities/voting/mod.rs @@ -7,10 +7,8 @@ mod tests { activities::voting::{undo_vote::UndoVote, vote::Vote}, tests::test_parse_lemmy_item, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_voting() { test_parse_lemmy_item::("assets/lemmy/activities/voting/like_note.json"); test_parse_lemmy_item::("assets/lemmy/activities/voting/dislike_page.json"); diff --git a/crates/apub/src/protocol/activities/voting/undo_vote.rs b/crates/apub/src/protocol/activities/voting/undo_vote.rs index c6c8f0b03..9a1767f2a 100644 --- a/crates/apub/src/protocol/activities/voting/undo_vote.rs +++ b/crates/apub/src/protocol/activities/voting/undo_vote.rs @@ -1,5 +1,8 @@ -use crate::{objects::person::ApubPerson, protocol::activities::voting::vote::Vote}; -use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; +use crate::{ + objects::person::ApubPerson, + protocol::{activities::voting::vote::Vote, Unparsed}, +}; +use activitystreams_kinds::activity::UndoType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs index 977a549db..065e3b31f 100644 --- a/crates/apub/src/protocol/activities/voting/vote.rs +++ b/crates/apub/src/protocol/activities/voting/vote.rs @@ -1,5 +1,8 @@ -use crate::{fetcher::post_or_comment::PostOrComment, objects::person::ApubPerson}; -use activitystreams::unparsed::Unparsed; +use crate::{ + fetcher::post_or_comment::PostOrComment, + objects::person::ApubPerson, + protocol::Unparsed, +}; use anyhow::anyhow; use lemmy_apub_lib::object_id::ObjectId; use lemmy_utils::LemmyError; diff --git a/crates/apub/src/protocol/collections/group_followers.rs b/crates/apub/src/protocol/collections/group_followers.rs index 55b92a76c..032731b73 100644 --- a/crates/apub/src/protocol/collections/group_followers.rs +++ b/crates/apub/src/protocol/collections/group_followers.rs @@ -1,5 +1,5 @@ use crate::generate_followers_url; -use activitystreams::collection::kind::CollectionType; +use activitystreams_kinds::collection::CollectionType; use lemmy_api_common::blocking; use lemmy_db_schema::source::community::Community; use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; diff --git a/crates/apub/src/protocol/collections/group_moderators.rs b/crates/apub/src/protocol/collections/group_moderators.rs index 9b8494849..6a72b9551 100644 --- a/crates/apub/src/protocol/collections/group_moderators.rs +++ b/crates/apub/src/protocol/collections/group_moderators.rs @@ -1,5 +1,5 @@ use crate::objects::person::ApubPerson; -use activitystreams::collection::kind::OrderedCollectionType; +use activitystreams_kinds::collection::OrderedCollectionType; use lemmy_apub_lib::object_id::ObjectId; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/collections/group_outbox.rs b/crates/apub/src/protocol/collections/group_outbox.rs index f7c70792b..2806d2695 100644 --- a/crates/apub/src/protocol/collections/group_outbox.rs +++ b/crates/apub/src/protocol/collections/group_outbox.rs @@ -1,5 +1,5 @@ use crate::protocol::activities::community::announce::AnnounceActivity; -use activitystreams::collection::kind::OrderedCollectionType; +use activitystreams_kinds::collection::OrderedCollectionType; use serde::{Deserialize, Serialize}; use url::Url; diff --git a/crates/apub/src/protocol/collections/mod.rs b/crates/apub/src/protocol/collections/mod.rs index 2e2d5c20a..214bd6d3c 100644 --- a/crates/apub/src/protocol/collections/mod.rs +++ b/crates/apub/src/protocol/collections/mod.rs @@ -14,10 +14,8 @@ mod tests { }, tests::test_parse_lemmy_item, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_lemmy_collections() { test_parse_lemmy_item::("assets/lemmy/collections/group_followers.json"); let outbox = test_parse_lemmy_item::("assets/lemmy/collections/group_outbox.json"); diff --git a/crates/apub/src/protocol/collections/person_outbox.rs b/crates/apub/src/protocol/collections/person_outbox.rs index c8af0173b..e616794c6 100644 --- a/crates/apub/src/protocol/collections/person_outbox.rs +++ b/crates/apub/src/protocol/collections/person_outbox.rs @@ -1,5 +1,5 @@ use crate::generate_outbox_url; -use activitystreams::collection::kind::OrderedCollectionType; +use activitystreams_kinds::collection::OrderedCollectionType; use lemmy_db_schema::source::person::Person; use lemmy_utils::LemmyError; use serde::{Deserialize, Serialize}; diff --git a/crates/apub/src/protocol/mod.rs b/crates/apub/src/protocol/mod.rs index 37a29f8fa..2a4acf246 100644 --- a/crates/apub/src/protocol/mod.rs +++ b/crates/apub/src/protocol/mod.rs @@ -1,8 +1,10 @@ -use activitystreams::object::kind::ImageType; +use activitystreams_kinds::object::ImageType; use serde::{Deserialize, Serialize}; use url::Url; use lemmy_apub_lib::values::MediaTypeMarkdown; +use lemmy_db_schema::newtypes::DbUrl; +use std::collections::HashMap; pub mod activities; pub(crate) mod collections; @@ -19,10 +21,23 @@ pub struct Source { #[serde(rename_all = "camelCase")] pub struct ImageObject { #[serde(rename = "type")] - pub(crate) kind: ImageType, + kind: ImageType, pub(crate) url: Url, } +impl ImageObject { + pub(crate) fn new(url: DbUrl) -> Self { + ImageObject { + kind: ImageType::Image, + url: url.into(), + } + } +} + +#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] +#[serde(transparent)] +pub struct Unparsed(HashMap); + #[cfg(test)] pub(crate) mod tests { use crate::objects::tests::file_to_json_object; diff --git a/crates/apub/src/protocol/objects/chat_message.rs b/crates/apub/src/protocol/objects/chat_message.rs index b86929139..64499ea33 100644 --- a/crates/apub/src/protocol/objects/chat_message.rs +++ b/crates/apub/src/protocol/objects/chat_message.rs @@ -1,11 +1,8 @@ use crate::{ objects::{person::ApubPerson, private_message::ApubPrivateMessage}, - protocol::Source, -}; -use activitystreams::{ - chrono::{DateTime, FixedOffset}, - unparsed::Unparsed, + protocol::{Source, Unparsed}, }; +use chrono::{DateTime, FixedOffset}; use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index 4dc1c5bd1..def878599 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -5,9 +5,9 @@ use crate::{ community_outbox::ApubCommunityOutbox, }, objects::{community::ApubCommunity, get_summary_from_string_or_source}, - protocol::{objects::Endpoints, ImageObject, Source}, + protocol::{objects::Endpoints, ImageObject, Source, Unparsed}, }; -use activitystreams::{actor::kind::GroupType, unparsed::Unparsed}; +use activitystreams_kinds::actor::GroupType; use chrono::{DateTime, FixedOffset}; use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey, verify::verify_domains_match}; use lemmy_db_schema::{naive_now, source::community::CommunityForm}; diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index f8cc877a7..bd590d493 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -24,10 +24,8 @@ mod tests { tests::test_parse_lemmy_item, }, }; - use serial_test::serial; #[actix_rt::test] - #[serial] async fn test_parse_object() { test_parse_lemmy_item::("assets/lemmy/objects/person.json"); test_parse_lemmy_item::("assets/lemmy/objects/group.json"); diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index 883a1a994..be21f8f57 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -1,9 +1,10 @@ use crate::{ fetcher::post_or_comment::PostOrComment, + mentions::Mention, objects::{comment::ApubComment, person::ApubPerson, post::ApubPost}, - protocol::Source, + protocol::{Source, Unparsed}, }; -use activitystreams::{link::Mention, object::kind::NoteType, unparsed::Unparsed}; +use activitystreams_kinds::object::NoteType; use chrono::{DateTime, FixedOffset}; use lemmy_api_common::blocking; use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml}; diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index dd923618e..2bd5cc6dd 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -1,8 +1,8 @@ use crate::{ objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, - protocol::{ImageObject, Source}, + protocol::{ImageObject, Source, Unparsed}, }; -use activitystreams::{object::kind::PageType, unparsed::Unparsed}; +use activitystreams_kinds::object::PageType; use anyhow::anyhow; use chrono::{DateTime, FixedOffset}; use lemmy_apub_lib::{ diff --git a/crates/apub/src/protocol/objects/person.rs b/crates/apub/src/protocol/objects/person.rs index e45ea78c7..f66b09aa0 100644 --- a/crates/apub/src/protocol/objects/person.rs +++ b/crates/apub/src/protocol/objects/person.rs @@ -1,12 +1,12 @@ use crate::{ objects::person::ApubPerson, - protocol::{objects::Endpoints, ImageObject, Source}, + protocol::{objects::Endpoints, ImageObject, Source, Unparsed}, }; -use activitystreams::{unparsed::Unparsed, url::Url}; use chrono::{DateTime, FixedOffset}; use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; +use url::Url; #[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)] pub enum UserTypes { diff --git a/crates/apub/src/protocol/objects/tombstone.rs b/crates/apub/src/protocol/objects/tombstone.rs index 152066cb5..6eb812179 100644 --- a/crates/apub/src/protocol/objects/tombstone.rs +++ b/crates/apub/src/protocol/objects/tombstone.rs @@ -1,4 +1,4 @@ -use activitystreams::object::kind::TombstoneType; +use activitystreams_kinds::object::TombstoneType; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url;