mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 15:51:20 +00:00
some code cleanup
This commit is contained in:
parent
e88ab170ef
commit
28e960bd9c
37 changed files with 86 additions and 174 deletions
|
@ -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::<RequestType>()
|
||||
// .fetchObject() - for custom http client
|
||||
// .checkActivity() - for common validity checks
|
||||
pub struct InboxConfig {
|
||||
//actors: Vec<ActorConfig>,
|
||||
}
|
||||
|
||||
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<kind> to cache the fetched object (or just fetch on construction)
|
||||
pub struct ObjectId<'a, Kind>(Url, &'a PhantomData<Kind>);
|
||||
|
||||
impl<Kind> ObjectId<'_, Kind> {
|
||||
pub fn url(self) -> Url {
|
||||
self.0
|
||||
}
|
||||
pub fn dereference(self) -> Result<Kind, LemmyError> {
|
||||
// todo: fetch object from http or database
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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])?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<OP: ToString + Send + lemmy_websocket::Operation
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: why do we have this and verify_mod_action() ?
|
||||
async fn verify_is_community_mod(
|
||||
actor: Url,
|
||||
community: Url,
|
||||
context: &LemmyContext,
|
||||
) -> 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> {
|
||||
|
|
|
@ -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)?;
|
||||
|
|
|
@ -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])?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<AnnounceActivity>),
|
||||
}
|
||||
|
||||
#[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
|
||||
|
|
|
@ -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<LemmyContext>,
|
||||
) -> Result<HttpResponse, LemmyError>
|
||||
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::<T>(activity)?;
|
||||
let activity_data = activity.common();
|
||||
|
@ -167,9 +168,7 @@ pub(crate) async fn is_activity_already_known(
|
|||
}
|
||||
}
|
||||
|
||||
fn assert_activity_not_local<T: Debug + ActivityHandlerNew>(
|
||||
activity: &T,
|
||||
) -> Result<(), LemmyError> {
|
||||
fn assert_activity_not_local<T: Debug + ActivityHandler>(activity: &T) -> Result<(), LemmyError> {
|
||||
let activity_domain = activity
|
||||
.common()
|
||||
.id_unchecked()
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
mod activities;
|
||||
mod http;
|
||||
pub mod routes;
|
||||
pub mod http;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue