From d89156810d1299117d877c75d1d3193a413d6997 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 28 Oct 2021 17:25:26 +0200 Subject: [PATCH] Move @context out of object/activity definitions --- crates/apub/assets/lemmy-comment.json | 19 ----- crates/apub/assets/lemmy-community.json | 19 ----- crates/apub/assets/lemmy-person.json | 19 ----- crates/apub/assets/lemmy-post.json | 19 ----- crates/apub/assets/lemmy-private-message.json | 19 ----- .../activities/comment/create_or_update.rs | 12 +--- .../apub/src/activities/community/add_mod.rs | 12 +--- .../apub/src/activities/community/announce.rs | 14 +--- .../src/activities/community/block_user.rs | 12 +--- crates/apub/src/activities/community/mod.rs | 6 +- .../src/activities/community/remove_mod.rs | 12 +--- .../activities/community/undo_block_user.rs | 12 +--- .../apub/src/activities/community/update.rs | 12 +--- crates/apub/src/activities/deletion/delete.rs | 12 +--- .../src/activities/deletion/undo_delete.rs | 12 +--- .../apub/src/activities/following/accept.rs | 19 ++--- .../apub/src/activities/following/follow.rs | 13 +--- crates/apub/src/activities/following/undo.rs | 13 +--- crates/apub/src/activities/mod.rs | 53 +++++++++++++- .../src/activities/post/create_or_update.rs | 6 +- .../private_message/create_or_update.rs | 15 ++-- .../src/activities/private_message/delete.rs | 14 +--- .../activities/private_message/undo_delete.rs | 13 +--- crates/apub/src/activities/report.rs | 19 ++--- .../apub/src/activities/voting/undo_vote.rs | 12 +--- crates/apub/src/activities/voting/vote.rs | 6 +- .../src/collections/community_moderators.rs | 13 +--- .../apub/src/collections/community_outbox.rs | 14 +--- crates/apub/src/context.rs | 69 ++++++++++++------- crates/apub/src/fetcher/object_id.rs | 1 - crates/apub/src/fetcher/post_or_comment.rs | 2 +- crates/apub/src/fetcher/search.rs | 2 +- crates/apub/src/http/community.rs | 8 +-- crates/apub/src/http/mod.rs | 9 +-- crates/apub/src/http/person.rs | 8 +-- crates/apub/src/lib.rs | 50 +------------- crates/apub/src/objects/comment.rs | 18 +---- crates/apub/src/objects/community.rs | 9 +-- crates/apub/src/objects/person.rs | 19 ++--- crates/apub/src/objects/post.rs | 6 -- crates/apub/src/objects/private_message.rs | 18 ++--- crates/apub/src/objects/tombstone.rs | 12 +--- 42 files changed, 179 insertions(+), 473 deletions(-) diff --git a/crates/apub/assets/lemmy-comment.json b/crates/apub/assets/lemmy-comment.json index c40e893c..2a20be29 100644 --- a/crates/apub/assets/lemmy-comment.json +++ b/crates/apub/assets/lemmy-comment.json @@ -1,23 +1,4 @@ { - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "comments_enabled": { - "id": "pt:commentsEnabled", - "type": "sc:Boolean" - }, - "matrixUserId": { - "id": "as:alsoKnownAs", - "type": "sc:Text" - }, - "moderators": "as:moderators", - "pt": "https://join-lemmy.org#", - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied" - }, - "https://w3id.org/security/v1" - ], "id": "https://enterprise.lemmy.ml/comment/38741", "type": "Note", "attributedTo": "https://enterprise.lemmy.ml/u/picard", diff --git a/crates/apub/assets/lemmy-community.json b/crates/apub/assets/lemmy-community.json index 3f56ed8e..7eddd86b 100644 --- a/crates/apub/assets/lemmy-community.json +++ b/crates/apub/assets/lemmy-community.json @@ -1,23 +1,4 @@ { - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "comments_enabled": { - "id": "pt:commentsEnabled", - "type": "sc:Boolean" - }, - "matrixUserId": { - "id": "as:alsoKnownAs", - "type": "sc:Text" - }, - "moderators": "as:moderators", - "pt": "https://join-lemmy.org#", - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied" - }, - "https://w3id.org/security/v1" - ], "id": "https://enterprise.lemmy.ml/c/tenforward", "type": "Group", "preferredUsername": "main", diff --git a/crates/apub/assets/lemmy-person.json b/crates/apub/assets/lemmy-person.json index 25c93517..769f2f3e 100644 --- a/crates/apub/assets/lemmy-person.json +++ b/crates/apub/assets/lemmy-person.json @@ -1,23 +1,4 @@ { - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "comments_enabled": { - "id": "pt:commentsEnabled", - "type": "sc:Boolean" - }, - "matrixUserId": { - "id": "as:alsoKnownAs", - "type": "sc:Text" - }, - "moderators": "as:moderators", - "pt": "https://join-lemmy.org#", - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied" - }, - "https://w3id.org/security/v1" - ], "id": "https://enterprise.lemmy.ml/u/picard", "type": "Person", "preferredUsername": "picard", diff --git a/crates/apub/assets/lemmy-post.json b/crates/apub/assets/lemmy-post.json index baf28ea0..2c39acce 100644 --- a/crates/apub/assets/lemmy-post.json +++ b/crates/apub/assets/lemmy-post.json @@ -1,23 +1,4 @@ { - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "comments_enabled": { - "id": "pt:commentsEnabled", - "type": "sc:Boolean" - }, - "matrixUserId": { - "id": "as:alsoKnownAs", - "type": "sc:Text" - }, - "moderators": "as:moderators", - "pt": "https://join-lemmy.org#", - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied" - }, - "https://w3id.org/security/v1" - ], "id": "https://enterprise.lemmy.ml/post/55143", "type": "Page", "attributedTo": "https://enterprise.lemmy.ml/u/picard", diff --git a/crates/apub/assets/lemmy-private-message.json b/crates/apub/assets/lemmy-private-message.json index 37475421..45790231 100644 --- a/crates/apub/assets/lemmy-private-message.json +++ b/crates/apub/assets/lemmy-private-message.json @@ -1,23 +1,4 @@ { - "@context": [ - "https://www.w3.org/ns/activitystreams", - { - "comments_enabled": { - "id": "pt:commentsEnabled", - "type": "sc:Boolean" - }, - "matrixUserId": { - "id": "as:alsoKnownAs", - "type": "sc:Text" - }, - "moderators": "as:moderators", - "pt": "https://join-lemmy.org#", - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied" - }, - "https://w3id.org/security/v1" - ], "id": "https://enterprise.lemmy.ml/private_message/1621", "type": "ChatMessage", "attributedTo": "https://enterprise.lemmy.ml/u/picard", diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index f8469be9..18661cbf 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -12,7 +12,6 @@ use crate::{ verify_person_in_community, CreateOrUpdateType, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{ comment::{ApubComment, Note}, @@ -20,13 +19,7 @@ use crate::{ person::ApubPerson, }, }; -use activitystreams::{ - base::AnyBase, - link::Mention, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{link::Mention, public, unparsed::Unparsed}; use lemmy_api_common::{blocking, check_post_deleted_or_removed}; use lemmy_apub_lib::{ data::Data, @@ -54,8 +47,6 @@ pub struct CreateOrUpdateComment { #[serde(rename = "type")] kind: CreateOrUpdateType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -91,7 +82,6 @@ impl CreateOrUpdateComment { tag: maa.tags, kind, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 11abb5ba..b65fa48e 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -12,18 +12,11 @@ use crate::{ verify_mod_action, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::AddType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::AddType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -49,8 +42,6 @@ pub struct AddMod { #[serde(rename = "type")] kind: AddType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -74,7 +65,6 @@ impl AddMod { cc: vec![community.actor_id()], kind: AddType::Add, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 6165eb2f..007fcbb3 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -12,24 +12,17 @@ use crate::{ deletion::{delete::Delete, undo_delete::UndoDelete}, generate_activity_id, post::create_or_update::CreateOrUpdatePost, + send_lemmy_activity, verify_activity, verify_is_public, voting::{undo_vote::UndoVote, vote::Vote}, }, - context::lemmy_context, fetcher::object_id::ObjectId, http::is_activity_already_known, insert_activity, objects::community::ApubCommunity, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::AnnounceType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::AnnounceType, public, unparsed::Unparsed}; use lemmy_apub_lib::{ data::Data, traits::{ActivityFields, ActivityHandler, ActorType}, @@ -102,8 +95,6 @@ pub struct AnnounceActivity { #[serde(rename = "type")] kind: AnnounceType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -125,7 +116,6 @@ impl AnnounceActivity { &AnnounceType::Announce, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }; let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?; diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index 21493214..0a716228 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -10,17 +10,10 @@ use crate::{ verify_mod_action, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::BlockType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -51,8 +44,6 @@ pub struct BlockUserFromCommunity { #[serde(rename = "type")] kind: BlockType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -75,7 +66,6 @@ impl BlockUserFromCommunity { BlockType::Block, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index 9db9d814..1f51c033 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -1,10 +1,12 @@ use crate::{ - activities::community::announce::{AnnouncableActivities, AnnounceActivity}, + activities::{ + community::announce::{AnnouncableActivities, AnnounceActivity}, + send_lemmy_activity, + }, check_is_apub_id_valid, fetcher::object_id::ObjectId, insert_activity, objects::community::ApubCommunity, - send_lemmy_activity, }; use itertools::Itertools; use lemmy_apub_lib::traits::ActorType; diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index 786740d5..f0c0b90e 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -12,18 +12,11 @@ use crate::{ verify_mod_action, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::RemoveType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::RemoveType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -49,8 +42,6 @@ pub struct RemoveMod { kind: RemoveType, pub(in crate::activities) target: Url, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -72,7 +63,6 @@ impl RemoveMod { object: ObjectId::new(removed_mod.actor_id()), target: generate_moderators_url(&community.actor_id)?.into(), id: id.clone(), - context: lemmy_context(), cc: vec![community.actor_id()], kind: RemoveType::Remove, unparsed: Default::default(), diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index b5e2a69c..ad220c96 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -11,17 +11,10 @@ use crate::{ verify_mod_action, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::UndoType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -46,8 +39,6 @@ pub struct UndoBlockUserFromCommunity { #[serde(rename = "type")] kind: UndoType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -72,7 +63,6 @@ impl UndoBlockUserFromCommunity { cc: vec![community.actor_id()], kind: UndoType::Undo, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index b5ad7f92..78fce324 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -10,20 +10,13 @@ use crate::{ verify_mod_action, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{ community::{ApubCommunity, Group}, person::ApubPerson, }, }; -use activitystreams::{ - activity::kind::UpdateType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -51,8 +44,6 @@ pub struct UpdateCommunity { #[serde(rename = "type")] kind: UpdateType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -74,7 +65,6 @@ impl UpdateCommunity { cc: vec![community.actor_id()], kind: UpdateType::Update, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 2677ea90..0db590b9 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -14,17 +14,10 @@ use crate::{ verify_activity, verify_is_public, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::DeleteType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::DeleteType, public, unparsed::Unparsed}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -79,8 +72,6 @@ pub struct Delete { /// deleting their own content. pub(in crate::activities::deletion) summary: Option, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -159,7 +150,6 @@ impl Delete { DeleteType::Delete, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index d881ab42..5cc4dffc 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -15,17 +15,10 @@ use crate::{ verify_activity, verify_is_public, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, }; -use activitystreams::{ - activity::kind::UndoType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -52,8 +45,6 @@ pub struct UndoDelete { #[serde(rename = "type")] kind: UndoType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -128,7 +119,6 @@ impl UndoDelete { cc: vec![community.actor_id()], kind: UndoType::Undo, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index 92f53184..28f6c108 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -1,16 +1,14 @@ use crate::{ - activities::{following::follow::FollowCommunity, generate_activity_id, verify_activity}, - context::lemmy_context, + activities::{ + following::follow::FollowCommunity, + generate_activity_id, + send_lemmy_activity, + verify_activity, + }, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::AcceptType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -32,8 +30,6 @@ pub struct AcceptFollowCommunity { #[serde(rename = "type")] kind: AcceptType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -59,7 +55,6 @@ impl AcceptFollowCommunity { AcceptType::Accept, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }; let inbox = vec![person.inbox_url()]; diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 4710f70f..57a112e0 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -2,21 +2,15 @@ use crate::{ activities::{ following::accept::AcceptFollowCommunity, generate_activity_id, + send_lemmy_activity, verify_activity, verify_person, verify_person_in_community, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::FollowType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::FollowType, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -41,8 +35,6 @@ pub struct FollowCommunity { #[serde(rename = "type")] kind: FollowType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -62,7 +54,6 @@ impl FollowCommunity { FollowType::Follow, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/activities/following/undo.rs b/crates/apub/src/activities/following/undo.rs index 7abb6117..a9326a26 100644 --- a/crates/apub/src/activities/following/undo.rs +++ b/crates/apub/src/activities/following/undo.rs @@ -2,20 +2,14 @@ use crate::{ activities::{ following::follow::FollowCommunity, generate_activity_id, + send_lemmy_activity, verify_activity, verify_person, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::UndoType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -40,8 +34,6 @@ pub struct UndoFollowCommunity { #[serde(rename = "type")] kind: UndoType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -62,7 +54,6 @@ impl UndoFollowCommunity { UndoType::Undo, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }; let inbox = vec![community.shared_inbox_or_inbox_url()]; diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index 63f79caa..9509babb 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -1,13 +1,19 @@ use crate::{ check_is_apub_id_valid, + context::WithContext, fetcher::object_id::ObjectId, generate_moderators_url, + insert_activity, objects::{community::ApubCommunity, person::ApubPerson}, }; use activitystreams::public; use anyhow::anyhow; use lemmy_api_common::blocking; -use lemmy_apub_lib::{traits::ActivityFields, verify::verify_domains_match}; +use lemmy_apub_lib::{ + activity_queue::send_activity, + traits::{ActivityFields, ActorType}, + verify::verify_domains_match, +}; use lemmy_db_schema::source::community::Community; use lemmy_db_views_actor::{ community_person_ban_view::CommunityPersonBanView, @@ -15,6 +21,7 @@ use lemmy_db_views_actor::{ }; use lemmy_utils::{settings::structs::Settings, LemmyError}; use lemmy_websocket::LemmyContext; +use log::info; use serde::{Deserialize, Serialize}; use strum_macros::ToString; use url::{ParseError, Url}; @@ -146,3 +153,47 @@ where ); Url::parse(&id) } + +async fn send_lemmy_activity( + context: &LemmyContext, + activity: &T, + activity_id: &Url, + actor: &dyn ActorType, + inboxes: Vec, + sensitive: bool, +) -> Result<(), LemmyError> { + if !context.settings().federation.enabled || inboxes.is_empty() { + return Ok(()); + } + let activity = WithContext::new(activity); + + info!("Sending activity {}", activity_id.to_string()); + + // Don't send anything to ourselves + // TODO: this should be a debug assert + let hostname = context.settings().get_hostname_without_port()?; + let inboxes: Vec<&Url> = inboxes + .iter() + .filter(|i| i.domain().expect("valid inbox url") != hostname) + .collect(); + + let serialised_activity = serde_json::to_string(&activity)?; + + insert_activity( + activity_id, + serialised_activity.clone(), + true, + sensitive, + context.pool(), + ) + .await?; + + send_activity( + serialised_activity, + actor, + inboxes, + context.client(), + context.activity_queue(), + ) + .await +} diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index 44498823..b5d9a202 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -12,7 +12,6 @@ use crate::{ verify_person_in_community, CreateOrUpdateType, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{ community::ApubCommunity, @@ -20,7 +19,7 @@ use crate::{ post::{ApubPost, Page}, }, }; -use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed}; +use activitystreams::{public, unparsed::Unparsed}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -44,8 +43,6 @@ pub struct CreateOrUpdatePost { #[serde(rename = "type")] kind: CreateOrUpdateType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -69,7 +66,6 @@ impl CreateOrUpdatePost { cc: vec![community.actor_id()], kind, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/activities/private_message/create_or_update.rs b/crates/apub/src/activities/private_message/create_or_update.rs index 22f8edb8..72a38e5e 100644 --- a/crates/apub/src/activities/private_message/create_or_update.rs +++ b/crates/apub/src/activities/private_message/create_or_update.rs @@ -1,14 +1,18 @@ use crate::{ - activities::{generate_activity_id, verify_activity, verify_person, CreateOrUpdateType}, - context::lemmy_context, + activities::{ + generate_activity_id, + send_lemmy_activity, + verify_activity, + verify_person, + CreateOrUpdateType, + }, fetcher::object_id::ObjectId, objects::{ person::ApubPerson, private_message::{ApubPrivateMessage, ChatMessage}, }, - send_lemmy_activity, }; -use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed}; +use activitystreams::unparsed::Unparsed; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -24,8 +28,6 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)] #[serde(rename_all = "camelCase")] pub struct CreateOrUpdatePrivateMessage { - #[serde(rename = "@context")] - pub context: OneOrMany, id: Url, actor: ObjectId, to: [ObjectId; 1], @@ -54,7 +56,6 @@ impl CreateOrUpdatePrivateMessage { &context.settings().get_protocol_and_hostname(), )?; let create_or_update = CreateOrUpdatePrivateMessage { - context: lemmy_context(), id: id.clone(), actor: ObjectId::new(actor.actor_id()), to: [ObjectId::new(recipient.actor_id())], diff --git a/crates/apub/src/activities/private_message/delete.rs b/crates/apub/src/activities/private_message/delete.rs index bcd9542c..0928cba2 100644 --- a/crates/apub/src/activities/private_message/delete.rs +++ b/crates/apub/src/activities/private_message/delete.rs @@ -1,16 +1,9 @@ use crate::{ - activities::{generate_activity_id, verify_activity, verify_person}, - context::lemmy_context, + activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person}, fetcher::object_id::ObjectId, objects::{person::ApubPerson, private_message::ApubPrivateMessage}, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::DeleteType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -35,8 +28,6 @@ pub struct DeletePrivateMessage { #[serde(rename = "type")] kind: DeleteType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -56,7 +47,6 @@ impl DeletePrivateMessage { DeleteType::Delete, &context.settings().get_protocol_and_hostname(), )?, - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/activities/private_message/undo_delete.rs b/crates/apub/src/activities/private_message/undo_delete.rs index cdabaa9a..4275ea9c 100644 --- a/crates/apub/src/activities/private_message/undo_delete.rs +++ b/crates/apub/src/activities/private_message/undo_delete.rs @@ -2,20 +2,14 @@ use crate::{ activities::{ generate_activity_id, private_message::delete::DeletePrivateMessage, + send_lemmy_activity, verify_activity, verify_person, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{person::ApubPerson, private_message::ApubPrivateMessage}, - send_lemmy_activity, -}; -use activitystreams::{ - activity::kind::UndoType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, }; +use activitystreams::{activity::kind::UndoType, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -40,8 +34,6 @@ pub struct UndoDeletePrivateMessage { #[serde(rename = "type")] kind: UndoType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -69,7 +61,6 @@ impl UndoDeletePrivateMessage { object, kind: UndoType::Undo, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; let inbox = vec![recipient.shared_inbox_or_inbox_url()]; diff --git a/crates/apub/src/activities/report.rs b/crates/apub/src/activities/report.rs index 24041b0f..9256920a 100644 --- a/crates/apub/src/activities/report.rs +++ b/crates/apub/src/activities/report.rs @@ -1,17 +1,15 @@ use crate::{ - activities::{generate_activity_id, verify_activity, verify_person_in_community}, - context::lemmy_context, + activities::{ + generate_activity_id, + send_lemmy_activity, + verify_activity, + verify_person_in_community, + }, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, - send_lemmy_activity, PostOrComment, }; -use activitystreams::{ - activity::kind::FlagType, - base::AnyBase, - primitives::OneOrMany, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::FlagType, unparsed::Unparsed}; use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse}; use lemmy_apub_lib::{ data::Data, @@ -40,8 +38,6 @@ pub struct Report { #[serde(rename = "type")] kind: FlagType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -67,7 +63,6 @@ impl Report { summary: reason, kind, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; send_lemmy_activity( diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index 144cbfc1..cc620661 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -14,18 +14,11 @@ use crate::{ vote::{Vote, VoteType}, }, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, PostOrComment, }; -use activitystreams::{ - activity::kind::UndoType, - base::AnyBase, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -49,8 +42,6 @@ pub struct UndoVote { #[serde(rename = "type")] kind: UndoType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -81,7 +72,6 @@ impl UndoVote { cc: vec![community.actor_id()], kind: UndoType::Undo, id: id.clone(), - context: lemmy_context(), unparsed: Default::default(), }; let activity = AnnouncableActivities::UndoVote(undo_vote); diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 5b08390f..3efef7cf 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -10,12 +10,11 @@ use crate::{ verify_person_in_community, voting::{vote_comment, vote_post}, }, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{community::ApubCommunity, person::ApubPerson}, PostOrComment, }; -use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed}; +use activitystreams::{public, unparsed::Unparsed}; use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -71,8 +70,6 @@ pub struct Vote { #[serde(rename = "type")] pub(in crate::activities::voting) kind: VoteType, id: Url, - #[serde(rename = "@context")] - context: OneOrMany, #[serde(flatten)] unparsed: Unparsed, } @@ -92,7 +89,6 @@ impl Vote { cc: vec![community.actor_id()], kind: kind.clone(), id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?, - context: lemmy_context(), unparsed: Default::default(), }) } diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index dc1d5798..2d190f4e 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -1,17 +1,10 @@ use crate::{ collections::CommunityContext, - context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, objects::person::ApubPerson, }; -use activitystreams::{ - base::AnyBase, - chrono::NaiveDateTime, - collection::kind::OrderedCollectionType, - primitives::OneOrMany, - url::Url, -}; +use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType}; use lemmy_api_common::blocking; use lemmy_apub_lib::{traits::ApubObject, verify::verify_domains_match}; use lemmy_db_schema::{ @@ -22,13 +15,12 @@ use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView; use lemmy_utils::LemmyError; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; +use url::Url; #[skip_serializing_none] #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct GroupModerators { - #[serde(rename = "@context")] - context: OneOrMany, r#type: OrderedCollectionType, id: Url, ordered_items: Vec>, @@ -75,7 +67,6 @@ impl ApubObject for ApubCommunityModerators { .map(|m| ObjectId::::new(m.moderator.actor_id.clone().into_inner())) .collect(); Ok(GroupModerators { - context: lemmy_context(), r#type: OrderedCollectionType::OrderedCollection, id: generate_moderators_url(&data.0.actor_id)?.into(), ordered_items, diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 24465c95..9d870f0e 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -1,17 +1,11 @@ use crate::{ activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType}, collections::CommunityContext, - context::lemmy_context, generate_outbox_url, objects::{person::ApubPerson, post::ApubPost}, }; -use activitystreams::{ - base::AnyBase, - chrono::NaiveDateTime, - collection::kind::OrderedCollectionType, - primitives::OneOrMany, - url::Url, -}; +use activitystreams::collection::kind::OrderedCollectionType; +use chrono::NaiveDateTime; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -25,13 +19,12 @@ use lemmy_db_schema::{ use lemmy_utils::LemmyError; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; +use url::Url; #[skip_serializing_none] #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct GroupOutbox { - #[serde(rename = "@context")] - context: OneOrMany, r#type: OrderedCollectionType, id: Url, ordered_items: Vec, @@ -88,7 +81,6 @@ impl ApubObject for ApubCommunityOutbox { } Ok(GroupOutbox { - context: lemmy_context(), r#type: OrderedCollectionType::OrderedCollection, id: generate_outbox_url(&data.0.actor_id)?.into(), ordered_items, diff --git a/crates/apub/src/context.rs b/crates/apub/src/context.rs index bc58052f..cf4b704f 100644 --- a/crates/apub/src/context.rs +++ b/crates/apub/src/context.rs @@ -1,28 +1,51 @@ use activitystreams::{base::AnyBase, context, primitives::OneOrMany}; +use serde::{Deserialize, Serialize}; use serde_json::json; use url::Url; -pub(crate) fn lemmy_context() -> OneOrMany { - let context_ext = AnyBase::from_arbitrary_json(json!( - { - "sc": "http://schema.org#", - "sensitive": "as:sensitive", - "stickied": "as:stickied", - "pt": "https://join-lemmy.org#", - "comments_enabled": { - "type": "sc:Boolean", - "id": "pt:commentsEnabled" - }, - "moderators": "as:moderators", - "matrixUserId": { - "type": "sc:Text", - "id": "as:alsoKnownAs" - }, - })) - .expect("parse context"); - OneOrMany::from(vec![ - AnyBase::from(context()), - context_ext, - AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")), - ]) +lazy_static! { + static ref CONTEXT: OneOrMany = { + let context_ext = AnyBase::from_arbitrary_json(json!( + { + "sc": "http://schema.org#", + "sensitive": "as:sensitive", + "stickied": "as:stickied", + "pt": "https://join-lemmy.org#", + "comments_enabled": { + "type": "sc:Boolean", + "id": "pt:commentsEnabled" + }, + "moderators": "as:moderators", + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" + }, + })) + .expect("parse context"); + OneOrMany::from(vec![ + AnyBase::from(context()), + context_ext, + AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")), + ]) + }; +} + +#[derive(Serialize, Deserialize)] +pub(crate) struct WithContext { + #[serde(rename = "@context")] + context: OneOrMany, + #[serde(flatten)] + inner: T, +} + +impl WithContext { + pub(crate) fn new(inner: T) -> WithContext { + WithContext { + context: CONTEXT.clone(), + inner, + } + } + pub(crate) fn inner(self) -> T { + self.inner + } } diff --git a/crates/apub/src/fetcher/object_id.rs b/crates/apub/src/fetcher/object_id.rs index 66466362..5c5c518f 100644 --- a/crates/apub/src/fetcher/object_id.rs +++ b/crates/apub/src/fetcher/object_id.rs @@ -22,7 +22,6 @@ use url::Url; /// fetch through the search). This should be configurable. static REQUEST_LIMIT: i32 = 25; -// TODO: after moving this file to library, remove lazy_static dependency from apub crate lazy_static! { static ref CLIENT: Client = Client::builder() .user_agent(build_user_agent(&Settings::get())) diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index ff0562a6..ac391120 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -2,7 +2,7 @@ use crate::objects::{ comment::{ApubComment, Note}, post::{ApubPost, Page}, }; -use activitystreams::chrono::NaiveDateTime; +use chrono::NaiveDateTime; use lemmy_apub_lib::traits::ApubObject; use lemmy_db_schema::source::{comment::CommentForm, post::PostForm}; use lemmy_utils::LemmyError; diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 86cdcbe0..5c2a3e7b 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -7,8 +7,8 @@ use crate::{ post::{ApubPost, Page}, }, }; -use activitystreams::chrono::NaiveDateTime; use anyhow::anyhow; +use chrono::NaiveDateTime; use itertools::Itertools; use lemmy_api_common::blocking; use lemmy_apub_lib::{ diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index f39f7b6f..6c9c632e 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -10,7 +10,7 @@ use crate::{ community_outbox::ApubCommunityOutbox, CommunityContext, }, - context::lemmy_context, + context::WithContext, fetcher::object_id::ObjectId, generate_outbox_url, http::{ @@ -82,9 +82,9 @@ pub async fn community_inbox( ) -> Result { let unparsed = payload_to_string(payload).await?; info!("Received community inbox activity {}", unparsed); - let activity = serde_json::from_str::(&unparsed)?; + let activity = serde_json::from_str::>(&unparsed)?; - receive_group_inbox(activity.clone(), request, &context).await?; + receive_group_inbox(activity.inner(), request, &context).await?; Ok(HttpResponse::Ok().finish()) } @@ -127,9 +127,9 @@ pub(crate) async fn get_apub_community_followers( let mut collection = UnorderedCollection::new(); collection - .set_many_contexts(lemmy_context()) .set_id(community.followers_url.into()) .set_total_items(community_followers.len() as u64); + let collection = WithContext::new(collection); Ok(create_apub_response(&collection)) } diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index fe44d5e3..48956cdf 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -1,5 +1,6 @@ use crate::{ check_is_apub_id_valid, + context::WithContext, fetcher::get_or_fetch_and_upsert_actor, http::{ community::{receive_group_inbox, GroupInboxActivities}, @@ -55,8 +56,8 @@ pub async fn shared_inbox( ) -> Result { let unparsed = payload_to_string(payload).await?; info!("Received shared inbox activity {}", unparsed); - let activity = serde_json::from_str::(&unparsed)?; - match activity { + let activity = serde_json::from_str::>(&unparsed)?; + match activity.inner() { SharedInboxActivities::GroupInboxActivities(g) => { receive_group_inbox(g, request, &context).await } @@ -134,7 +135,7 @@ where { HttpResponse::Ok() .content_type(APUB_JSON_CONTENT_TYPE) - .json(data) + .json(WithContext::new(data)) } fn create_apub_tombstone_response(data: &T) -> HttpResponse @@ -144,7 +145,7 @@ where HttpResponse::Gone() .content_type(APUB_JSON_CONTENT_TYPE) .status(StatusCode::GONE) - .json(data) + .json(WithContext::new(data)) } #[derive(Deserialize)] diff --git a/crates/apub/src/http/person.rs b/crates/apub/src/http/person.rs index 88ffa120..2cc18768 100644 --- a/crates/apub/src/http/person.rs +++ b/crates/apub/src/http/person.rs @@ -8,7 +8,7 @@ use crate::{ undo_delete::UndoDeletePrivateMessage, }, }, - context::lemmy_context, + context::WithContext, generate_outbox_url, http::{ create_apub_response, @@ -80,8 +80,8 @@ pub async fn person_inbox( ) -> Result { let unparsed = payload_to_string(payload).await?; info!("Received person inbox activity {}", unparsed); - let activity = serde_json::from_str::(&unparsed)?; - receive_person_inbox(activity, request, &context).await + let activity = serde_json::from_str::>(&unparsed)?; + receive_person_inbox(activity.inner(), request, &context).await } pub(in crate::http) async fn receive_person_inbox( @@ -104,8 +104,8 @@ pub(crate) async fn get_apub_person_outbox( let mut collection = OrderedCollection::new(); collection .set_many_items(Vec::::new()) - .set_many_contexts(lemmy_context()) .set_id(generate_outbox_url(&person.actor_id)?.into()) .set_total_items(0_u64); + let collection = WithContext::new(collection); Ok(create_apub_response(&collection)) } diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 3bf3ff25..f60e04af 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -12,15 +12,10 @@ extern crate lazy_static; use crate::fetcher::post_or_comment::PostOrComment; use anyhow::{anyhow, Context}; use lemmy_api_common::blocking; -use lemmy_apub_lib::{ - activity_queue::send_activity, - traits::ActorType, - webfinger::{webfinger_resolve_actor, WebfingerType}, -}; +use lemmy_apub_lib::webfinger::{webfinger_resolve_actor, WebfingerType}; use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool}; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError}; use lemmy_websocket::LemmyContext; -use log::info; use serde::Serialize; use std::net::IpAddr; use url::{ParseError, Url}; @@ -195,46 +190,3 @@ where .await??; Ok(()) } - -pub(crate) async fn send_lemmy_activity( - context: &LemmyContext, - activity: &T, - activity_id: &Url, - actor: &dyn ActorType, - inboxes: Vec, - sensitive: bool, -) -> Result<(), LemmyError> { - if !context.settings().federation.enabled || inboxes.is_empty() { - return Ok(()); - } - - info!("Sending activity {}", activity_id.to_string()); - - // Don't send anything to ourselves - // TODO: this should be a debug assert - let hostname = context.settings().get_hostname_without_port()?; - let inboxes: Vec<&Url> = inboxes - .iter() - .filter(|i| i.domain().expect("valid inbox url") != hostname) - .collect(); - - let serialised_activity = serde_json::to_string(&activity)?; - - insert_activity( - activity_id, - serialised_activity.clone(), - true, - sensitive, - context.pool(), - ) - .await?; - - send_activity( - serialised_activity, - actor, - inboxes, - context.client(), - context.activity_queue(), - ) - .await -} diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 335605a6..5698640d 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -1,6 +1,5 @@ use crate::{ activities::{verify_is_public, verify_person_in_community}, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{ community::ApubCommunity, @@ -11,16 +10,9 @@ use crate::{ }, PostOrComment, }; -use activitystreams::{ - base::AnyBase, - chrono::NaiveDateTime, - object::kind::NoteType, - primitives::OneOrMany, - public, - unparsed::Unparsed, -}; +use activitystreams::{object::kind::NoteType, public, unparsed::Unparsed}; use anyhow::anyhow; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use html2md::parse_html; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -52,11 +44,6 @@ 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: Option>, r#type: NoteType, id: Url, pub(crate) attributed_to: ObjectId, @@ -206,7 +193,6 @@ impl ApubObject for ApubComment { }; let note = Note { - context: Some(lemmy_context()), r#type: NoteType::Note, id: self.ap_id.to_owned().into_inner(), attributed_to: ObjectId::new(creator.actor_id), diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index a38e759f..c7d1dd3e 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -5,7 +5,6 @@ use crate::{ community_outbox::ApubCommunityOutbox, CommunityContext, }, - context::lemmy_context, fetcher::object_id::ObjectId, generate_moderators_url, generate_outbox_url, @@ -13,13 +12,10 @@ use crate::{ }; use activitystreams::{ actor::{kind::GroupType, Endpoints}, - base::AnyBase, - chrono::NaiveDateTime, object::kind::ImageType, - primitives::OneOrMany, unparsed::Unparsed, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use itertools::Itertools; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -50,8 +46,6 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Group { - #[serde(rename = "@context")] - context: OneOrMany, #[serde(rename = "type")] kind: GroupType, pub(crate) id: Url, @@ -181,7 +175,6 @@ impl ApubObject for ApubCommunity { }); let group = Group { - context: lemmy_context(), kind: GroupType::Group, id: self.actor_id(), preferred_username: self.name.clone(), diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index f4ba225b..49ba7eb1 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -1,18 +1,10 @@ use crate::{ check_is_apub_id_valid, - context::lemmy_context, generate_outbox_url, objects::{get_summary_from_string_or_source, ImageObject, Source}, }; -use activitystreams::{ - actor::Endpoints, - base::AnyBase, - chrono::NaiveDateTime, - object::{kind::ImageType, Tombstone}, - primitives::OneOrMany, - unparsed::Unparsed, -}; -use chrono::{DateTime, FixedOffset}; +use activitystreams::{actor::Endpoints, object::kind::ImageType, unparsed::Unparsed}; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use lemmy_api_common::blocking; use lemmy_apub_lib::{ signatures::PublicKey, @@ -44,8 +36,6 @@ pub enum UserTypes { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Person { - #[serde(rename = "@context")] - context: OneOrMany, #[serde(rename = "type")] kind: UserTypes, id: Url, @@ -99,7 +89,7 @@ impl From for ApubPerson { impl ApubObject for ApubPerson { type DataType = LemmyContext; type ApubType = Person; - type TombstoneType = Tombstone; + type TombstoneType = (); fn last_refreshed_at(&self) -> Option { Some(self.last_refreshed_at) @@ -146,7 +136,6 @@ impl ApubObject for ApubPerson { }); let person = Person { - context: lemmy_context(), kind, id: self.actor_id.to_owned().into_inner(), preferred_username: self.name.clone(), @@ -170,7 +159,7 @@ impl ApubObject for ApubPerson { Ok(person) } - fn to_tombstone(&self) -> Result { + fn to_tombstone(&self) -> Result<(), LemmyError> { unimplemented!() } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index f15bb5ba..ee9aa7b8 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -1,6 +1,5 @@ use crate::{ activities::{verify_is_public, verify_person_in_community}, - context::lemmy_context, fetcher::object_id::ObjectId, objects::{ community::ApubCommunity, @@ -11,9 +10,7 @@ use crate::{ }, }; use activitystreams::{ - base::AnyBase, object::kind::{ImageType, PageType}, - primitives::OneOrMany, public, unparsed::Unparsed, }; @@ -49,8 +46,6 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Page { - #[serde(rename = "@context")] - context: OneOrMany, r#type: PageType, id: Url, pub(crate) attributed_to: ObjectId, @@ -196,7 +191,6 @@ impl ApubObject for ApubPost { }); let page = Page { - context: lemmy_context(), r#type: PageType::Page, id: self.ap_id.clone().into(), attributed_to: ObjectId::new(creator.actor_id), diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 56200d1b..e971ebe3 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -1,17 +1,10 @@ use crate::{ - context::lemmy_context, fetcher::object_id::ObjectId, objects::{person::ApubPerson, Source}, }; -use activitystreams::{ - base::AnyBase, - chrono::NaiveDateTime, - object::Tombstone, - primitives::OneOrMany, - unparsed::Unparsed, -}; +use activitystreams::unparsed::Unparsed; use anyhow::anyhow; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use html2md::parse_html; use lemmy_api_common::blocking; use lemmy_apub_lib::{ @@ -37,8 +30,6 @@ use url::Url; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ChatMessage { - #[serde(rename = "@context")] - context: OneOrMany, r#type: ChatMessageType, id: Url, pub(crate) attributed_to: ObjectId, @@ -104,7 +95,7 @@ impl From for ApubPrivateMessage { impl ApubObject for ApubPrivateMessage { type DataType = LemmyContext; type ApubType = ChatMessage; - type TombstoneType = Tombstone; + type TombstoneType = (); fn last_refreshed_at(&self) -> Option { None @@ -137,7 +128,6 @@ impl ApubObject for ApubPrivateMessage { blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??; let note = ChatMessage { - context: lemmy_context(), r#type: ChatMessageType::ChatMessage, id: self.ap_id.clone().into(), attributed_to: ObjectId::new(creator.actor_id), @@ -155,7 +145,7 @@ impl ApubObject for ApubPrivateMessage { Ok(note) } - fn to_tombstone(&self) -> Result { + fn to_tombstone(&self) -> Result<(), LemmyError> { unimplemented!() } diff --git a/crates/apub/src/objects/tombstone.rs b/crates/apub/src/objects/tombstone.rs index fc78c968..2746c5ae 100644 --- a/crates/apub/src/objects/tombstone.rs +++ b/crates/apub/src/objects/tombstone.rs @@ -1,10 +1,5 @@ -use crate::context::lemmy_context; -use activitystreams::{ - base::AnyBase, - chrono::{DateTime, FixedOffset, NaiveDateTime}, - object::kind::TombstoneType, - primitives::OneOrMany, -}; +use activitystreams::object::kind::TombstoneType; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use lemmy_utils::utils::convert_datetime; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; @@ -13,8 +8,6 @@ use serde_with::skip_serializing_none; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Tombstone { - #[serde(rename = "@context")] - context: OneOrMany, #[serde(rename = "type")] kind: TombstoneType, former_type: String, @@ -24,7 +17,6 @@ pub struct Tombstone { impl Tombstone { pub fn new(former_type: T, updated_time: NaiveDateTime) -> Tombstone { Tombstone { - context: lemmy_context(), kind: TombstoneType::Tombstone, former_type: former_type.to_string(), deleted: convert_datetime(updated_time), -- 2.44.1