diff --git a/crates/apub_lib/src/lib.rs b/crates/apub_lib/src/lib.rs index 349775cd7..66bba9f43 100644 --- a/crates/apub_lib/src/lib.rs +++ b/crates/apub_lib/src/lib.rs @@ -7,30 +7,8 @@ use activitystreams::{ pub use lemmy_apub_lib_derive::*; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; -use std::marker::PhantomData; use url::Url; -// for now, limit it to activity routing only, no http sigs, parsing or any of that -// need to route in this order: -// 1. recipient actor -// 2. activity type -// 3. inner object (recursively until object is empty or an url) - -// TODO: turn this into a trait in which app has to implement the following functions: -// .checkIdValid() - for unique, instance block etc -// .checkHttpSig::() -// .fetchObject() - for custom http client -// .checkActivity() - for common validity checks -pub struct InboxConfig { - //actors: Vec, -} - -impl InboxConfig { - pub fn shared_inbox_handler() { - todo!() - } -} - #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub enum PublicUrl { #[serde(rename = "https://www.w3.org/ns/activitystreams#Public")] @@ -57,15 +35,13 @@ impl ActivityCommonFields { } #[async_trait::async_trait(?Send)] -pub trait ActivityHandlerNew { - // TODO: also need to check for instance/community blocks in here +pub trait ActivityHandler { async fn verify( &self, context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError>; - // todo: later handle request_counter completely inside library async fn receive( &self, context: &LemmyContext, @@ -94,16 +70,3 @@ pub fn verify_urls_match(a: &Url, b: &Url) -> Result<(), LemmyError> { } Ok(()) } - -// todo: instead of phantomdata, might use option to cache the fetched object (or just fetch on construction) -pub struct ObjectId<'a, Kind>(Url, &'a PhantomData); - -impl ObjectId<'_, Kind> { - pub fn url(self) -> Url { - self.0 - } - pub fn dereference(self) -> Result { - // todo: fetch object from http or database - todo!() - } -} diff --git a/crates/apub_lib_derive/src/lib.rs b/crates/apub_lib_derive/src/lib.rs index 6e809813d..71c594348 100644 --- a/crates/apub_lib_derive/src/lib.rs +++ b/crates/apub_lib_derive/src/lib.rs @@ -2,7 +2,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{parse_macro_input, Data, DeriveInput}; -#[proc_macro_derive(ActivityHandlerNew)] +#[proc_macro_derive(ActivityHandler)] pub fn derive_activity_handler(input: proc_macro::TokenStream) -> proc_macro::TokenStream { // Parse the input tokens into a syntax tree. let input = parse_macro_input!(input as DeriveInput); @@ -34,7 +34,7 @@ pub fn derive_activity_handler(input: proc_macro::TokenStream) -> proc_macro::To // The generated impl. let expanded = quote! { #[async_trait::async_trait(?Send)] - impl #impl_generics lemmy_apub_lib::ActivityHandlerNew for #name #ty_generics #where_clause { + impl #impl_generics lemmy_apub_lib::ActivityHandler for #name #ty_generics #where_clause { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/comment/create.rs b/crates/apub_receive/src/activities/comment/create.rs index 11afddcbc..7ce5d09af 100644 --- a/crates/apub_receive/src/activities/comment/create.rs +++ b/crates/apub_receive/src/activities/comment/create.rs @@ -5,12 +5,7 @@ use crate::activities::{ }; use activitystreams::{activity::kind::CreateType, base::BaseExt}; use lemmy_apub::{objects::FromApub, NoteExt}; -use lemmy_apub_lib::{ - verify_domains_match_opt, - ActivityCommonFields, - ActivityHandlerNew, - PublicUrl, -}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_schema::source::comment::Comment; use lemmy_utils::LemmyError; use lemmy_websocket::{LemmyContext, UserOperationCrud}; @@ -29,7 +24,7 @@ pub struct CreateComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for CreateComment { +impl ActivityHandler for CreateComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/comment/update.rs b/crates/apub_receive/src/activities/comment/update.rs index 69a1d936e..c07837e39 100644 --- a/crates/apub_receive/src/activities/comment/update.rs +++ b/crates/apub_receive/src/activities/comment/update.rs @@ -5,12 +5,7 @@ use crate::activities::{ }; use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use lemmy_apub::{objects::FromApub, NoteExt}; -use lemmy_apub_lib::{ - verify_domains_match_opt, - ActivityCommonFields, - ActivityHandlerNew, - PublicUrl, -}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_schema::source::comment::Comment; use lemmy_utils::LemmyError; use lemmy_websocket::{LemmyContext, UserOperationCrud}; @@ -29,7 +24,7 @@ pub struct UpdateComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UpdateComment { +impl ActivityHandler for UpdateComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/community/add_mod.rs b/crates/apub_receive/src/activities/community/add_mod.rs index eb79b197f..3f4a33e7c 100644 --- a/crates/apub_receive/src/activities/community/add_mod.rs +++ b/crates/apub_receive/src/activities/community/add_mod.rs @@ -6,7 +6,7 @@ use lemmy_apub::{ fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, CommunityType, }; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{source::community::CommunityModerator_, Joinable}; use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm}; use lemmy_utils::LemmyError; @@ -27,7 +27,7 @@ pub struct AddMod { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for AddMod { +impl ActivityHandler for AddMod { async fn verify(&self, context: &LemmyContext, _: &mut i32) -> Result<(), LemmyError> { verify_domains_match(&self.common.actor, self.common.id_unchecked())?; verify_domains_match(&self.target, &self.cc[0])?; diff --git a/crates/apub_receive/src/activities/community/announce.rs b/crates/apub_receive/src/activities/community/announce.rs index 7f4eaa5b1..1bdaacbc3 100644 --- a/crates/apub_receive/src/activities/community/announce.rs +++ b/crates/apub_receive/src/activities/community/announce.rs @@ -20,13 +20,13 @@ use crate::{ }; use activitystreams::activity::kind::AnnounceType; use lemmy_apub::insert_activity; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; use url::Url; -#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandlerNew)] +#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)] #[serde(untagged)] pub enum AnnouncableActivities { CreateComment(CreateComment), @@ -58,7 +58,7 @@ pub struct AnnounceActivity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for AnnounceActivity { +impl ActivityHandler for AnnounceActivity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/community/block_user.rs b/crates/apub_receive/src/activities/community/block_user.rs index a67296a24..03a19e9c7 100644 --- a/crates/apub_receive/src/activities/community/block_user.rs +++ b/crates/apub_receive/src/activities/community/block_user.rs @@ -5,7 +5,7 @@ use lemmy_apub::fetcher::{ community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person, }; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{Bannable, Followable}; use lemmy_db_schema::source::community::{ CommunityFollower, @@ -30,7 +30,7 @@ pub struct BlockUserFromCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for BlockUserFromCommunity { +impl ActivityHandler for BlockUserFromCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/community/delete.rs b/crates/apub_receive/src/activities/community/delete.rs index 6242f68f2..ad5ccfd94 100644 --- a/crates/apub_receive/src/activities/community/delete.rs +++ b/crates/apub_receive/src/activities/community/delete.rs @@ -1,4 +1,4 @@ -use crate::activities::community::{send_websocket_message, verify_is_community_mod}; +use crate::activities::{community::send_websocket_message, verify_mod_action}; use activitystreams::activity::kind::DeleteType; use lemmy_api_common::blocking; use lemmy_apub::{ @@ -7,7 +7,7 @@ use lemmy_apub::{ ActorType, CommunityType, }; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_schema::source::community::Community; use lemmy_utils::LemmyError; @@ -30,7 +30,7 @@ pub struct DeleteCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for DeleteCommunity { +impl ActivityHandler for DeleteCommunity { async fn verify(&self, context: &LemmyContext, _: &mut i32) -> Result<(), LemmyError> { verify_domains_match(&self.common.actor, self.common.id_unchecked())?; let object = self.object.clone(); @@ -42,7 +42,7 @@ impl ActivityHandlerNew for DeleteCommunity { if let Ok(c) = community { verify_domains_match(&self.object, &self.cc[0])?; check_is_apub_id_valid(&self.common.actor, false)?; - verify_is_community_mod(self.common.actor.clone(), c.actor_id(), context).await + verify_mod_action(&self.common.actor, c.actor_id(), context).await } // community action sent to followers else { diff --git a/crates/apub_receive/src/activities/community/mod.rs b/crates/apub_receive/src/activities/community/mod.rs index b87077260..c69a16c82 100644 --- a/crates/apub_receive/src/activities/community/mod.rs +++ b/crates/apub_receive/src/activities/community/mod.rs @@ -1,11 +1,7 @@ use anyhow::anyhow; use lemmy_api_common::{blocking, community::CommunityResponse}; use lemmy_apub::generate_moderators_url; -use lemmy_db_queries::ApubObject; -use lemmy_db_schema::{ - source::{community::Community, person::Person}, - CommunityId, -}; +use lemmy_db_schema::CommunityId; use lemmy_db_views_actor::community_view::CommunityView; use lemmy_utils::LemmyError; use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext}; @@ -44,30 +40,6 @@ async fn send_websocket_message Result<(), LemmyError> { - let actor = blocking(context.pool(), move |conn| { - Person::read_from_apub_id(conn, &actor.into()) - }) - .await??; - let community = blocking(context.pool(), move |conn| { - Community::read_from_apub_id(conn, &community.into()) - }) - .await??; - let is_mod_or_admin = blocking(context.pool(), move |conn| { - CommunityView::is_mod_or_admin(conn, actor.id, community.id) - }) - .await?; - if !is_mod_or_admin { - return Err(anyhow!("Not a mod").into()); - } - Ok(()) -} - /// For Add/Remove community moderator activities, check that the target field actually contains /// /c/community/moderators. Any different values are unsupported. fn verify_add_remove_moderator_target(target: &Url, community: Url) -> Result<(), LemmyError> { diff --git a/crates/apub_receive/src/activities/community/remove.rs b/crates/apub_receive/src/activities/community/remove.rs index 41b86ef67..a0e8880c9 100644 --- a/crates/apub_receive/src/activities/community/remove.rs +++ b/crates/apub_receive/src/activities/community/remove.rs @@ -2,7 +2,7 @@ use crate::activities::community::send_websocket_message; use activitystreams::activity::kind::RemoveType; use lemmy_api_common::blocking; use lemmy_apub::check_is_apub_id_valid; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_schema::source::community::Community; use lemmy_utils::LemmyError; @@ -22,7 +22,7 @@ pub struct RemoveCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for RemoveCommunity { +impl ActivityHandler for RemoveCommunity { async fn verify(&self, _context: &LemmyContext, _: &mut i32) -> Result<(), LemmyError> { verify_domains_match(&self.common.actor, self.common.id_unchecked())?; check_is_apub_id_valid(&self.common.actor, false)?; diff --git a/crates/apub_receive/src/activities/community/remove_mod.rs b/crates/apub_receive/src/activities/community/remove_mod.rs index f06c51d2a..0d25dfa16 100644 --- a/crates/apub_receive/src/activities/community/remove_mod.rs +++ b/crates/apub_receive/src/activities/community/remove_mod.rs @@ -6,7 +6,7 @@ use lemmy_apub::{ fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, CommunityType, }; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::Joinable; use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm}; use lemmy_utils::LemmyError; @@ -27,7 +27,7 @@ pub struct RemoveMod { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for RemoveMod { +impl ActivityHandler for RemoveMod { async fn verify(&self, context: &LemmyContext, _: &mut i32) -> Result<(), LemmyError> { verify_domains_match(&self.common.actor, self.common.id_unchecked())?; verify_domains_match(&self.target, &self.cc[0])?; diff --git a/crates/apub_receive/src/activities/community/undo_block_user.rs b/crates/apub_receive/src/activities/community/undo_block_user.rs index b9257badf..88518385b 100644 --- a/crates/apub_receive/src/activities/community/undo_block_user.rs +++ b/crates/apub_receive/src/activities/community/undo_block_user.rs @@ -10,7 +10,7 @@ use lemmy_apub::fetcher::{ community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person, }; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::Bannable; use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm}; use lemmy_utils::LemmyError; @@ -30,7 +30,7 @@ pub struct UndoBlockUserFromCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoBlockUserFromCommunity { +impl ActivityHandler for UndoBlockUserFromCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/community/undo_delete.rs b/crates/apub_receive/src/activities/community/undo_delete.rs index 79c61e962..ba3b2f137 100644 --- a/crates/apub_receive/src/activities/community/undo_delete.rs +++ b/crates/apub_receive/src/activities/community/undo_delete.rs @@ -1,7 +1,6 @@ -use crate::activities::community::{ - delete::DeleteCommunity, - send_websocket_message, - verify_is_community_mod, +use crate::activities::{ + community::{delete::DeleteCommunity, send_websocket_message}, + verify_mod_action, }; use activitystreams::activity::kind::DeleteType; use lemmy_api_common::blocking; @@ -11,7 +10,7 @@ use lemmy_apub::{ ActorType, CommunityType, }; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_schema::source::community::Community; use lemmy_utils::LemmyError; @@ -34,7 +33,7 @@ pub struct UndoDeleteCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoDeleteCommunity { +impl ActivityHandler for UndoDeleteCommunity { async fn verify( &self, context: &LemmyContext, @@ -50,7 +49,7 @@ impl ActivityHandlerNew for UndoDeleteCommunity { if let Ok(c) = community { verify_domains_match(&self.object.object, &self.cc[0])?; check_is_apub_id_valid(&self.common.actor, false)?; - verify_is_community_mod(self.common.actor.clone(), c.actor_id(), context).await?; + verify_mod_action(&self.common.actor, c.actor_id(), context).await?; } // community action sent to followers else { diff --git a/crates/apub_receive/src/activities/community/undo_remove.rs b/crates/apub_receive/src/activities/community/undo_remove.rs index 67ed85825..71421403e 100644 --- a/crates/apub_receive/src/activities/community/undo_remove.rs +++ b/crates/apub_receive/src/activities/community/undo_remove.rs @@ -2,7 +2,7 @@ use crate::activities::community::{remove::RemoveCommunity, send_websocket_messa use activitystreams::activity::kind::RemoveType; use lemmy_api_common::blocking; use lemmy_apub::{check_is_apub_id_valid, fetcher::community::get_or_fetch_and_upsert_community}; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::source::community::Community_; use lemmy_db_schema::source::community::Community; use lemmy_utils::LemmyError; @@ -22,7 +22,7 @@ pub struct UndoRemoveCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoRemoveCommunity { +impl ActivityHandler for UndoRemoveCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/community/update.rs b/crates/apub_receive/src/activities/community/update.rs index 3cadc8dec..a8e0feb09 100644 --- a/crates/apub_receive/src/activities/community/update.rs +++ b/crates/apub_receive/src/activities/community/update.rs @@ -1,8 +1,8 @@ -use crate::activities::community::{send_websocket_message, verify_is_community_mod}; +use crate::activities::{community::send_websocket_message, verify_mod_action}; use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use lemmy_api_common::blocking; use lemmy_apub::{check_is_apub_id_valid, objects::FromApubToForm, GroupExt}; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{ApubObject, Crud}; use lemmy_db_schema::source::community::{Community, CommunityForm}; use lemmy_utils::LemmyError; @@ -24,12 +24,12 @@ pub struct UpdateCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UpdateCommunity { +impl ActivityHandler for UpdateCommunity { async fn verify(&self, context: &LemmyContext, _: &mut i32) -> Result<(), LemmyError> { verify_domains_match(&self.common.actor, self.common.id_unchecked())?; self.object.id(self.cc[0].as_str())?; check_is_apub_id_valid(&self.common.actor, false)?; - verify_is_community_mod(self.common.actor.clone(), self.cc[0].clone(), context).await + verify_mod_action(&self.common.actor, self.cc[0].clone(), context).await } async fn receive( diff --git a/crates/apub_receive/src/activities/following/accept.rs b/crates/apub_receive/src/activities/following/accept.rs index bd0aa9cb8..d5cf474d4 100644 --- a/crates/apub_receive/src/activities/following/accept.rs +++ b/crates/apub_receive/src/activities/following/accept.rs @@ -5,7 +5,7 @@ use lemmy_apub::fetcher::{ community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person, }; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler}; use lemmy_db_queries::Followable; use lemmy_db_schema::source::community::CommunityFollower; use lemmy_utils::LemmyError; @@ -25,7 +25,7 @@ pub struct AcceptFollowCommunity { /// Handle accepted follows #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for AcceptFollowCommunity { +impl ActivityHandler for AcceptFollowCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/following/follow.rs b/crates/apub_receive/src/activities/following/follow.rs index f9ca8d429..fd0649f19 100644 --- a/crates/apub_receive/src/activities/following/follow.rs +++ b/crates/apub_receive/src/activities/following/follow.rs @@ -9,7 +9,7 @@ use lemmy_apub::{ fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, CommunityType, }; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler}; use lemmy_db_queries::Followable; use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm}; use lemmy_utils::{location_info, LemmyError}; @@ -28,7 +28,7 @@ pub struct FollowCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for FollowCommunity { +impl ActivityHandler for FollowCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/following/undo.rs b/crates/apub_receive/src/activities/following/undo.rs index 1e25669e3..1f3d12e61 100644 --- a/crates/apub_receive/src/activities/following/undo.rs +++ b/crates/apub_receive/src/activities/following/undo.rs @@ -5,7 +5,7 @@ use lemmy_apub::fetcher::{ community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person, }; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler}; use lemmy_db_queries::Followable; use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm}; use lemmy_utils::LemmyError; @@ -24,7 +24,7 @@ pub struct UndoFollowCommunity { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoFollowCommunity { +impl ActivityHandler for UndoFollowCommunity { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post/create.rs b/crates/apub_receive/src/activities/post/create.rs index ef7069aa7..2d31fa0d1 100644 --- a/crates/apub_receive/src/activities/post/create.rs +++ b/crates/apub_receive/src/activities/post/create.rs @@ -10,12 +10,7 @@ use lemmy_apub::{ ActorType, PageExt, }; -use lemmy_apub_lib::{ - verify_domains_match_opt, - ActivityCommonFields, - ActivityHandlerNew, - PublicUrl, -}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_schema::source::post::Post; use lemmy_utils::LemmyError; use lemmy_websocket::{LemmyContext, UserOperationCrud}; @@ -34,7 +29,7 @@ pub struct CreatePost { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for CreatePost { +impl ActivityHandler for CreatePost { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post/update.rs b/crates/apub_receive/src/activities/post/update.rs index ac1f02dc2..1f5924929 100644 --- a/crates/apub_receive/src/activities/post/update.rs +++ b/crates/apub_receive/src/activities/post/update.rs @@ -12,12 +12,7 @@ use lemmy_apub::{ ActorType, PageExt, }; -use lemmy_apub_lib::{ - verify_domains_match_opt, - ActivityCommonFields, - ActivityHandlerNew, - PublicUrl, -}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::ApubObject; use lemmy_db_schema::{ source::post::{Post, PostForm}, @@ -40,7 +35,7 @@ pub struct UpdatePost { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UpdatePost { +impl ActivityHandler for UpdatePost { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/delete.rs b/crates/apub_receive/src/activities/post_or_comment/delete.rs index 591facf5c..8856e726a 100644 --- a/crates/apub_receive/src/activities/post_or_comment/delete.rs +++ b/crates/apub_receive/src/activities/post_or_comment/delete.rs @@ -11,7 +11,7 @@ use lemmy_apub::{ ActorType, PostOrComment, }; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::{ source::{comment::Comment_, post::Post_}, Crud, @@ -34,7 +34,7 @@ pub struct DeletePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for DeletePostOrComment { +impl ActivityHandler for DeletePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/dislike.rs b/crates/apub_receive/src/activities/post_or_comment/dislike.rs index 98bbbd4cb..161a7d28a 100644 --- a/crates/apub_receive/src/activities/post_or_comment/dislike.rs +++ b/crates/apub_receive/src/activities/post_or_comment/dislike.rs @@ -4,7 +4,7 @@ use crate::activities::{ verify_person_in_community, }; use activitystreams::activity::kind::DislikeType; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -22,7 +22,7 @@ pub struct DislikePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for DislikePostOrComment { +impl ActivityHandler for DislikePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/like.rs b/crates/apub_receive/src/activities/post_or_comment/like.rs index 8b6046d3f..03897ccd6 100644 --- a/crates/apub_receive/src/activities/post_or_comment/like.rs +++ b/crates/apub_receive/src/activities/post_or_comment/like.rs @@ -4,7 +4,7 @@ use crate::activities::{ verify_person_in_community, }; use activitystreams::activity::kind::LikeType; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -22,7 +22,7 @@ pub struct LikePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for LikePostOrComment { +impl ActivityHandler for LikePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/remove.rs b/crates/apub_receive/src/activities/post_or_comment/remove.rs index 15c64aa7e..8a8aef6e3 100644 --- a/crates/apub_receive/src/activities/post_or_comment/remove.rs +++ b/crates/apub_receive/src/activities/post_or_comment/remove.rs @@ -8,7 +8,7 @@ use crate::activities::{ use activitystreams::activity::kind::RemoveType; use lemmy_api_common::blocking; use lemmy_apub::{fetcher::objects::get_or_fetch_and_insert_post_or_comment, PostOrComment}; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::source::{comment::Comment_, post::Post_}; use lemmy_db_schema::source::{comment::Comment, post::Post}; use lemmy_utils::LemmyError; @@ -28,7 +28,7 @@ pub struct RemovePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for RemovePostOrComment { +impl ActivityHandler for RemovePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/undo_delete.rs b/crates/apub_receive/src/activities/post_or_comment/undo_delete.rs index eb234ecf9..b121ac03f 100644 --- a/crates/apub_receive/src/activities/post_or_comment/undo_delete.rs +++ b/crates/apub_receive/src/activities/post_or_comment/undo_delete.rs @@ -8,7 +8,7 @@ use crate::activities::{ use activitystreams::activity::kind::UndoType; use lemmy_api_common::blocking; use lemmy_apub::{fetcher::objects::get_or_fetch_and_insert_post_or_comment, PostOrComment}; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::source::{comment::Comment_, post::Post_}; use lemmy_db_schema::source::{comment::Comment, post::Post}; use lemmy_utils::LemmyError; @@ -28,7 +28,7 @@ pub struct UndoDeletePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoDeletePostOrComment { +impl ActivityHandler for UndoDeletePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/undo_dislike.rs b/crates/apub_receive/src/activities/post_or_comment/undo_dislike.rs index 72eb23749..082fba9b0 100644 --- a/crates/apub_receive/src/activities/post_or_comment/undo_dislike.rs +++ b/crates/apub_receive/src/activities/post_or_comment/undo_dislike.rs @@ -4,7 +4,7 @@ use crate::activities::{ verify_person_in_community, }; use activitystreams::activity::kind::UndoType; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -22,7 +22,7 @@ pub struct UndoDislikePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoDislikePostOrComment { +impl ActivityHandler for UndoDislikePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/undo_like.rs b/crates/apub_receive/src/activities/post_or_comment/undo_like.rs index 62a2ab8f2..bab2d5dfa 100644 --- a/crates/apub_receive/src/activities/post_or_comment/undo_like.rs +++ b/crates/apub_receive/src/activities/post_or_comment/undo_like.rs @@ -4,7 +4,7 @@ use crate::activities::{ verify_person_in_community, }; use activitystreams::activity::kind::UndoType; -use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -22,7 +22,7 @@ pub struct UndoLikePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoLikePostOrComment { +impl ActivityHandler for UndoLikePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/post_or_comment/undo_remove.rs b/crates/apub_receive/src/activities/post_or_comment/undo_remove.rs index 7bd5437ed..09f52096c 100644 --- a/crates/apub_receive/src/activities/post_or_comment/undo_remove.rs +++ b/crates/apub_receive/src/activities/post_or_comment/undo_remove.rs @@ -9,7 +9,7 @@ use crate::activities::{ use activitystreams::activity::kind::UndoType; use lemmy_api_common::blocking; use lemmy_apub::{fetcher::objects::get_or_fetch_and_insert_post_or_comment, PostOrComment}; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew, PublicUrl}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl}; use lemmy_db_queries::source::{comment::Comment_, post::Post_}; use lemmy_db_schema::source::{comment::Comment, post::Post}; use lemmy_utils::LemmyError; @@ -29,7 +29,7 @@ pub struct UndoRemovePostOrComment { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoRemovePostOrComment { +impl ActivityHandler for UndoRemovePostOrComment { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/private_message/create.rs b/crates/apub_receive/src/activities/private_message/create.rs index 2829a1cd5..2d766565e 100644 --- a/crates/apub_receive/src/activities/private_message/create.rs +++ b/crates/apub_receive/src/activities/private_message/create.rs @@ -1,7 +1,7 @@ use crate::activities::{private_message::send_websocket_message, verify_activity, verify_person}; use activitystreams::{activity::kind::CreateType, base::BaseExt}; use lemmy_apub::{objects::FromApub, NoteExt}; -use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler}; use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_utils::LemmyError; use lemmy_websocket::{LemmyContext, UserOperationCrud}; @@ -19,7 +19,7 @@ pub struct CreatePrivateMessage { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for CreatePrivateMessage { +impl ActivityHandler for CreatePrivateMessage { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/private_message/delete.rs b/crates/apub_receive/src/activities/private_message/delete.rs index 75fc146c4..b7f1a3cd9 100644 --- a/crates/apub_receive/src/activities/private_message/delete.rs +++ b/crates/apub_receive/src/activities/private_message/delete.rs @@ -1,7 +1,7 @@ use crate::activities::{private_message::send_websocket_message, verify_activity, verify_person}; use activitystreams::activity::kind::DeleteType; use lemmy_api_common::blocking; -use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler}; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject}; use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_utils::LemmyError; @@ -20,7 +20,7 @@ pub struct DeletePrivateMessage { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for DeletePrivateMessage { +impl ActivityHandler for DeletePrivateMessage { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/private_message/undo_delete.rs b/crates/apub_receive/src/activities/private_message/undo_delete.rs index 3c9298d73..dc297b5af 100644 --- a/crates/apub_receive/src/activities/private_message/undo_delete.rs +++ b/crates/apub_receive/src/activities/private_message/undo_delete.rs @@ -9,7 +9,7 @@ use lemmy_apub_lib::{ verify_domains_match, verify_urls_match, ActivityCommonFields, - ActivityHandlerNew, + ActivityHandler, }; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject}; use lemmy_db_schema::source::private_message::PrivateMessage; @@ -29,7 +29,7 @@ pub struct UndoDeletePrivateMessage { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UndoDeletePrivateMessage { +impl ActivityHandler for UndoDeletePrivateMessage { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/activities/private_message/update.rs b/crates/apub_receive/src/activities/private_message/update.rs index ea716dfa8..56a79f8e8 100644 --- a/crates/apub_receive/src/activities/private_message/update.rs +++ b/crates/apub_receive/src/activities/private_message/update.rs @@ -1,7 +1,7 @@ use crate::activities::{private_message::send_websocket_message, verify_activity, verify_person}; use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use lemmy_apub::{objects::FromApub, NoteExt}; -use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler}; use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_utils::LemmyError; use lemmy_websocket::{LemmyContext, UserOperationCrud}; @@ -19,7 +19,7 @@ pub struct UpdatePrivateMessage { } #[async_trait::async_trait(?Send)] -impl ActivityHandlerNew for UpdatePrivateMessage { +impl ActivityHandler for UpdatePrivateMessage { async fn verify( &self, context: &LemmyContext, diff --git a/crates/apub_receive/src/http/inbox_enums.rs b/crates/apub_receive/src/http/inbox_enums.rs index 7250b6b62..907e13e8a 100644 --- a/crates/apub_receive/src/http/inbox_enums.rs +++ b/crates/apub_receive/src/http/inbox_enums.rs @@ -31,12 +31,12 @@ use crate::activities::{ update::UpdatePrivateMessage, }, }; -use lemmy_apub_lib::{ActivityCommonFields, ActivityHandlerNew}; +use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandlerNew)] +#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)] #[serde(untagged)] pub enum PersonInboxActivities { AcceptFollowCommunity(AcceptFollowCommunity), @@ -47,7 +47,7 @@ pub enum PersonInboxActivities { AnnounceActivity(Box), } -#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandlerNew)] +#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)] #[serde(untagged)] pub enum GroupInboxActivities { FollowCommunity(FollowCommunity), @@ -75,7 +75,7 @@ pub enum GroupInboxActivities { RemoveMod(RemoveMod), } -#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandlerNew)] +#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler)] #[serde(untagged)] pub enum SharedInboxActivities { // received by group diff --git a/crates/apub_receive/src/http/mod.rs b/crates/apub_receive/src/http/mod.rs index d15c958ec..44302d8d9 100644 --- a/crates/apub_receive/src/http/mod.rs +++ b/crates/apub_receive/src/http/mod.rs @@ -17,7 +17,7 @@ use lemmy_apub::{ insert_activity, APUB_JSON_CONTENT_TYPE, }; -use lemmy_apub_lib::ActivityHandlerNew; +use lemmy_apub_lib::ActivityHandler; use lemmy_db_queries::{source::activity::Activity_, DbPool}; use lemmy_db_schema::source::activity::Activity; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError}; @@ -26,11 +26,12 @@ use serde::{Deserialize, Serialize}; use std::{fmt::Debug, io::Read}; use url::Url; -pub mod comment; -pub mod community; -pub mod inbox_enums; -pub mod person; -pub mod post; +mod comment; +mod community; +mod inbox_enums; +mod person; +mod post; +pub mod routes; pub async fn shared_inbox( request: HttpRequest, @@ -58,7 +59,7 @@ async fn receive_activity<'a, T>( context: web::Data, ) -> Result where - T: ActivityHandlerNew + Clone + Deserialize<'a> + Serialize + std::fmt::Debug + Send + 'static, + T: ActivityHandler + Clone + Deserialize<'a> + Serialize + std::fmt::Debug + Send + 'static, { let activity = serde_json::from_str::(activity)?; let activity_data = activity.common(); @@ -167,9 +168,7 @@ pub(crate) async fn is_activity_already_known( } } -fn assert_activity_not_local( - activity: &T, -) -> Result<(), LemmyError> { +fn assert_activity_not_local(activity: &T) -> Result<(), LemmyError> { let activity_domain = activity .common() .id_unchecked() diff --git a/crates/apub_receive/src/routes.rs b/crates/apub_receive/src/http/routes.rs similarity index 100% rename from crates/apub_receive/src/routes.rs rename to crates/apub_receive/src/http/routes.rs diff --git a/crates/apub_receive/src/lib.rs b/crates/apub_receive/src/lib.rs index d6b772a05..dadc76b6a 100644 --- a/crates/apub_receive/src/lib.rs +++ b/crates/apub_receive/src/lib.rs @@ -1,3 +1,2 @@ mod activities; -mod http; -pub mod routes; +pub mod http; diff --git a/src/main.rs b/src/main.rs index efccece14..fd5394fca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,7 +91,7 @@ async fn main() -> Result<(), LemmyError> { .app_data(Data::new(context)) // The routes .configure(|cfg| api_routes::config(cfg, &rate_limiter)) - .configure(lemmy_apub_receive::routes::config) + .configure(lemmy_apub_receive::http::routes::config) .configure(feeds::config) .configure(|cfg| images::config(cfg, &rate_limiter)) .configure(nodeinfo::config)