also use actor type for routing, VerifyActivity and SendActivity traits

This commit is contained in:
Felix Ableitner 2021-06-30 04:47:02 +02:00
parent 6d447c81cf
commit fa7778218f
44 changed files with 360 additions and 340 deletions

View file

@ -1,12 +1,11 @@
use crate::ActorType;
use activitystreams::unparsed::UnparsedMutExt; use activitystreams::unparsed::UnparsedMutExt;
use activitystreams_ext::UnparsedExtension; use activitystreams_ext::UnparsedExtension;
use actix_web::HttpRequest; use actix_web::HttpRequest;
use anyhow::{anyhow, Context}; use anyhow::anyhow;
use http::{header::HeaderName, HeaderMap, HeaderValue}; use http::{header::HeaderName, HeaderMap, HeaderValue};
use http_signature_normalization_actix::Config as ConfigActix; use http_signature_normalization_actix::Config as ConfigActix;
use http_signature_normalization_reqwest::prelude::{Config, SignExt}; use http_signature_normalization_reqwest::prelude::{Config, SignExt};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::LemmyError;
use log::debug; use log::debug;
use openssl::{ use openssl::{
hash::MessageDigest, hash::MessageDigest,
@ -65,8 +64,7 @@ pub(crate) async fn sign_and_send(
} }
/// Verifies the HTTP signature on an incoming inbox request. /// Verifies the HTTP signature on an incoming inbox request.
pub fn verify_signature(request: &HttpRequest, actor: &dyn ActorType) -> Result<(), LemmyError> { pub fn verify_signature(request: &HttpRequest, public_key: &str) -> Result<(), LemmyError> {
let public_key = actor.public_key().context(location_info!())?;
let verified = CONFIG2 let verified = CONFIG2
.begin_verify( .begin_verify(
request.method(), request.method(),

View file

@ -14,7 +14,10 @@ use crate::{
}; };
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use http::StatusCode; use http::StatusCode;
use lemmy_db_schema::naive_now; use lemmy_db_schema::{
naive_now,
source::{community::Community, person::Person},
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use serde::Deserialize; use serde::Deserialize;
@ -55,6 +58,27 @@ pub async fn get_or_fetch_and_upsert_actor(
Ok(actor) Ok(actor)
} }
pub enum Actor {
Person(Person),
Community(Community),
}
// TODO: use this and get rid of ActorType
pub async fn get_or_fetch_and_upsert_actor2(
apub_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,
) -> Result<Actor, LemmyError> {
let community = get_or_fetch_and_upsert_community(apub_id, context, recursion_counter).await;
let actor: Actor = match community {
Ok(c) => Actor::Community(c),
Err(_) => {
Actor::Person(get_or_fetch_and_upsert_person(apub_id, context, recursion_counter).await?)
}
};
Ok(actor)
}
/// Determines when a remote actor should be refetched from its instance. In release builds, this is /// Determines when a remote actor should be refetched from its instance. In release builds, this is
/// `ACTOR_REFETCH_INTERVAL_SECONDS` after the last refetch, in debug builds /// `ACTOR_REFETCH_INTERVAL_SECONDS` after the last refetch, in debug builds
/// `ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG`. /// `ACTOR_REFETCH_INTERVAL_SECONDS_DEBUG`.

View file

@ -31,13 +31,17 @@ pub enum PublicUrl {
Public, Public,
} }
// todo: later add a similar trait SendActivity
// todo: maybe add a separate method verify()
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
pub trait ReceiveActivity { pub trait ActivityHandler {
type Actor;
// TODO: also need to check for instance/community blocks in here
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError>;
// todo: later handle request_counter completely inside library // todo: later handle request_counter completely inside library
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError>; ) -> Result<(), LemmyError>;
@ -50,12 +54,6 @@ pub fn verify_domains_match(a: &Url, b: &Url) -> Result<(), LemmyError> {
Ok(()) Ok(())
} }
#[async_trait::async_trait(?Send)]
pub trait VerifyActivity {
// TODO: also need to check for instance/actor blocks in here i think
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError>;
}
// todo: instead of phantomdata, might use option<kind> to cache the fetched object (or just fetch on construction) // 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>); pub struct ObjectId<'a, Kind>(Url, &'a PhantomData<Kind>);

View file

@ -3,9 +3,9 @@ use crate::{
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::{activity::kind::CreateType, base::BaseExt}; use activitystreams::{activity::kind::CreateType, base::BaseExt};
use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, NoteExt}; use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, ActorType, NoteExt};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -21,25 +21,25 @@ pub struct CreateComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<CreateComment> { impl ActivityHandler for Activity<CreateComment> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<CreateComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let comment = Comment::from_apub( let comment = Comment::from_apub(
&self.inner.object, &self.inner.object,
context, context,
self.actor.clone(), actor.actor_id(),
request_counter, request_counter,
false, false,
) )

View file

@ -2,9 +2,9 @@ use crate::{activities::comment::send_websocket_message, inbox::new_inbox_routin
use activitystreams::activity::kind::DeleteType; use activitystreams::activity::kind::DeleteType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::comment::Comment_; use lemmy_db_queries::source::comment::Comment_;
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -20,18 +20,18 @@ pub struct DeleteComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DeleteComment> { impl ActivityHandler for Activity<DeleteComment> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object)?; verify_domains_match(&self.actor, &self.inner.object)?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DeleteComment> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -1,7 +1,8 @@
use crate::{activities::comment::like_or_dislike_comment, inbox::new_inbox_routing::Activity}; use crate::{activities::comment::like_or_dislike_comment, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::DislikeType; use activitystreams::activity::kind::DislikeType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -17,27 +18,20 @@ pub struct DislikeComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DislikeComment> { impl ActivityHandler for Activity<DislikeComment> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DislikeComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
like_or_dislike_comment( like_or_dislike_comment(-1, &actor, &self.inner.object, context, request_counter).await
-1,
&self.actor,
&self.inner.object,
context,
request_counter,
)
.await
} }
} }

View file

@ -1,7 +1,8 @@
use crate::{activities::comment::like_or_dislike_comment, inbox::new_inbox_routing::Activity}; use crate::{activities::comment::like_or_dislike_comment, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::LikeType; use activitystreams::activity::kind::LikeType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -17,27 +18,20 @@ pub struct LikeComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<LikeComment> { impl ActivityHandler for Activity<LikeComment> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<LikeComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
like_or_dislike_comment( like_or_dislike_comment(-1, &actor, &self.inner.object, context, request_counter).await
-1,
&self.actor,
&self.inner.object,
context,
request_counter,
)
.await
} }
} }

View file

@ -7,6 +7,7 @@ use lemmy_db_queries::{Crud, Likeable};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
comment::{Comment, CommentLike, CommentLikeForm}, comment::{Comment, CommentLike, CommentLikeForm},
person::Person,
post::Post, post::Post,
}, },
CommentId, CommentId,
@ -78,22 +79,21 @@ async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::Operation
async fn like_or_dislike_comment( async fn like_or_dislike_comment(
score: i16, score: i16,
actor: &Url, actor: &Person,
object: &Url, object: &Url,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
let comment = get_or_fetch_and_insert_comment(object, context, request_counter).await?; let comment = get_or_fetch_and_insert_comment(object, context, request_counter).await?;
let comment_id = comment.id; let comment_id = comment.id;
let like_form = CommentLikeForm { let like_form = CommentLikeForm {
comment_id, comment_id,
post_id: comment.post_id, post_id: comment.post_id,
person_id: person.id, person_id: actor.id,
score, score,
}; };
let person_id = person.id; let person_id = actor.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
CommentLike::remove(conn, person_id, comment_id)?; CommentLike::remove(conn, person_id, comment_id)?;
CommentLike::like(conn, &like_form) CommentLike::like(conn, &like_form)
@ -110,16 +110,15 @@ async fn like_or_dislike_comment(
} }
async fn undo_like_or_dislike_comment( async fn undo_like_or_dislike_comment(
actor: &Url, actor: &Person,
object: &Url, object: &Url,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
let comment = get_or_fetch_and_insert_comment(object, context, request_counter).await?; let comment = get_or_fetch_and_insert_comment(object, context, request_counter).await?;
let comment_id = comment.id; let comment_id = comment.id;
let person_id = person.id; let person_id = actor.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
CommentLike::remove(conn, person_id, comment_id) CommentLike::remove(conn, person_id, comment_id)
}) })

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::RemoveType; use activitystreams::activity::kind::RemoveType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::comment::Comment_; use lemmy_db_queries::source::comment::Comment_;
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -23,18 +23,18 @@ pub struct RemoveComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<RemoveComment> { impl ActivityHandler for Activity<RemoveComment> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<RemoveComment> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::comment::Comment_; use lemmy_db_queries::source::comment::Comment_;
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -23,19 +23,19 @@ pub struct UndoDeleteComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeleteComment> { impl ActivityHandler for Activity<UndoDeleteComment> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.actor)?; verify_domains_match(&self.actor, &self.inner.object.actor)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDeleteComment> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -4,7 +4,8 @@ use crate::{
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -20,24 +21,24 @@ pub struct UndoDislikeComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDislikeComment> { impl ActivityHandler for Activity<UndoDislikeComment> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.inner.object)?; verify_domains_match(&self.actor, &self.inner.object.inner.object)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDislikeComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
undo_like_or_dislike_comment( undo_like_or_dislike_comment(
&self.actor, &actor,
&self.inner.object.inner.object, &self.inner.object.inner.object,
context, context,
request_counter, request_counter,

View file

@ -4,7 +4,8 @@ use crate::{
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -20,24 +21,24 @@ pub struct UndoLikeComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoLikeComment> { impl ActivityHandler for Activity<UndoLikeComment> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.inner.object)?; verify_domains_match(&self.actor, &self.inner.object.inner.object)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoLikeComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
undo_like_or_dislike_comment( undo_like_or_dislike_comment(
&self.actor, &actor,
&self.inner.object.inner.object, &self.inner.object.inner.object,
context, context,
request_counter, request_counter,

View file

@ -8,9 +8,9 @@ use crate::{
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::comment::Comment_; use lemmy_db_queries::source::comment::Comment_;
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -26,19 +26,19 @@ pub struct UndoRemoveComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoRemoveComment> { impl ActivityHandler for Activity<UndoRemoveComment> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?; verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoRemoveComment> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -3,9 +3,9 @@ use crate::{
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use activitystreams::{activity::kind::UpdateType, base::BaseExt};
use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, NoteExt}; use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, ActorType, NoteExt};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::comment::Comment; use lemmy_db_schema::source::{comment::Comment, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -21,18 +21,18 @@ pub struct UpdateComment {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UpdateComment> { impl ActivityHandler for Activity<UpdateComment> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UpdateComment> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
@ -45,7 +45,8 @@ impl ReceiveActivity for Activity<UpdateComment> {
) )
.await?; .await?;
let recipients = get_notif_recipients(&self.actor, &comment, context, request_counter).await?; let recipients =
get_notif_recipients(&actor.actor_id(), &comment, context, request_counter).await?;
send_websocket_message( send_websocket_message(
comment.id, comment.id,
recipients, recipients,

View file

@ -9,16 +9,19 @@ use lemmy_apub::{
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
CommunityType, CommunityType,
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{source::community::CommunityModerator_, Joinable}; use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm}; use lemmy_db_schema::source::{
community::{CommunityModerator, CommunityModeratorForm},
person::Person,
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct AddModToCommunity { pub struct AddMod {
to: PublicUrl, to: PublicUrl,
object: Url, object: Url,
target: Url, target: Url,
@ -28,7 +31,9 @@ pub struct AddModToCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<AddModToCommunity> { impl ActivityHandler for Activity<AddMod> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.inner.target, &self.inner.cc[0])?; verify_domains_match(&self.inner.target, &self.inner.cc[0])?;
@ -36,12 +41,10 @@ impl VerifyActivity for Activity<AddModToCommunity> {
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?; verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?;
verify_add_remove_moderator_target(&self.inner.target, self.inner.cc[0].clone()) verify_add_remove_moderator_target(&self.inner.target, self.inner.cc[0].clone())
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<AddModToCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -37,8 +37,9 @@ use crate::{
inbox::{is_activity_already_known, new_inbox_routing::Activity}, inbox::{is_activity_already_known, new_inbox_routing::Activity},
}; };
use activitystreams::activity::kind::RemoveType; use activitystreams::activity::kind::RemoveType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::{check_is_apub_id_valid, fetcher::person::get_or_fetch_and_upsert_person};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::{community::Community, person::Person};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -76,20 +77,20 @@ pub enum AnnouncableActivities {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for AnnouncableActivities { impl ActivityHandler for AnnouncableActivities {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
self.verify(context).await self.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for AnnouncableActivities {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
self.receive(context, request_counter).await self.receive(actor, context, request_counter).await
} }
} }
@ -104,30 +105,32 @@ pub struct AnnounceActivity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<AnnounceActivity> { impl ActivityHandler for Activity<AnnounceActivity> {
type Actor = Community;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.cc[0])?; verify_domains_match(&self.actor, &self.inner.cc[0])?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.inner.verify(context).await self.inner.object.inner.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<AnnounceActivity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
if is_activity_already_known(context.pool(), &self.inner.object.id_unchecked()).await? { if is_activity_already_known(context.pool(), &self.inner.object.id_unchecked()).await? {
return Ok(()); return Ok(());
} }
let inner_actor =
get_or_fetch_and_upsert_person(&self.inner.object.actor, context, request_counter).await?;
self self
.inner .inner
.object .object
.inner .inner
.receive(context, request_counter) .receive(inner_actor, context, request_counter)
.await .await
} }
} }

View file

@ -5,13 +5,16 @@ use lemmy_apub::{
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{Bannable, Followable}; use lemmy_db_queries::{Bannable, Followable};
use lemmy_db_schema::source::community::{ use lemmy_db_schema::source::{
CommunityFollower, community::{
CommunityFollowerForm, CommunityFollower,
CommunityPersonBan, CommunityFollowerForm,
CommunityPersonBanForm, CommunityPersonBan,
CommunityPersonBanForm,
},
person::Person,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
@ -28,18 +31,18 @@ pub struct BlockUserFromCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<BlockUserFromCommunity> { impl ActivityHandler for Activity<BlockUserFromCommunity> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<BlockUserFromCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -10,7 +10,7 @@ use lemmy_apub::{
ActorType, ActorType,
CommunityType, CommunityType,
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_queries::{source::community::Community_, ApubObject};
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
@ -31,7 +31,9 @@ pub struct DeleteCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DeleteCommunity> { impl ActivityHandler for Activity<DeleteCommunity> {
type Actor = lemmy_apub::fetcher::Actor;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
let object = self.inner.object.clone(); let object = self.inner.object.clone();
@ -51,15 +53,14 @@ impl VerifyActivity for Activity<DeleteCommunity> {
verify_domains_match(&self.actor, &self.inner.cc[0]) verify_domains_match(&self.actor, &self.inner.cc[0])
} }
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DeleteCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// TODO: match on actor to decide what to do
let actor = self.inner.object.clone(); let actor = self.inner.object.clone();
let community = blocking(context.pool(), move |conn| { let community = blocking(context.pool(), move |conn| {
Community::read_from_apub_id(conn, &actor.into()) Community::read_from_apub_id(conn, &actor.into())

View file

@ -2,7 +2,7 @@ use crate::{activities::community::send_websocket_message, inbox::new_inbox_rout
use activitystreams::activity::kind::RemoveType; use activitystreams::activity::kind::RemoveType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_queries::{source::community::Community_, ApubObject};
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
@ -20,19 +20,19 @@ pub struct RemoveCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<RemoveCommunity> { impl ActivityHandler for Activity<RemoveCommunity> {
type Actor = lemmy_apub::fetcher::Actor;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_domains_match(&self.actor, &self.inner.object)?; verify_domains_match(&self.actor, &self.inner.object)?;
verify_domains_match(&self.actor, &self.inner.cc[0]) verify_domains_match(&self.actor, &self.inner.cc[0])
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<RemoveCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
_request_counter: &mut i32, _request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -9,16 +9,19 @@ use lemmy_apub::{
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
CommunityType, CommunityType,
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::Joinable; use lemmy_db_queries::Joinable;
use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm}; use lemmy_db_schema::source::{
community::{CommunityModerator, CommunityModeratorForm},
person::Person,
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct RemoveModToCommunity { pub struct RemoveMod {
to: PublicUrl, to: PublicUrl,
object: Url, object: Url,
target: Url, target: Url,
@ -28,7 +31,9 @@ pub struct RemoveModToCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<RemoveModToCommunity> { impl ActivityHandler for Activity<RemoveMod> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.inner.target, &self.inner.cc[0])?; verify_domains_match(&self.inner.target, &self.inner.cc[0])?;
@ -36,12 +41,10 @@ impl VerifyActivity for Activity<RemoveModToCommunity> {
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?; verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?;
verify_add_remove_moderator_target(&self.inner.target, self.inner.cc[0].clone()) verify_add_remove_moderator_target(&self.inner.target, self.inner.cc[0].clone())
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<RemoveModToCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -8,9 +8,12 @@ use lemmy_apub::{
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::Bannable; use lemmy_db_queries::Bannable;
use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm}; use lemmy_db_schema::source::{
community::{CommunityPersonBan, CommunityPersonBanForm},
person::Person,
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -26,19 +29,19 @@ pub struct UndoBlockUserFromCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoBlockUserFromCommunity> { impl ActivityHandler for Activity<UndoBlockUserFromCommunity> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?; verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoBlockUserFromCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -14,7 +14,7 @@ use lemmy_apub::{
ActorType, ActorType,
CommunityType, CommunityType,
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{source::community::Community_, ApubObject}; use lemmy_db_queries::{source::community::Community_, ApubObject};
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
@ -35,7 +35,9 @@ pub struct UndoDeleteCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeleteCommunity> { impl ActivityHandler for Activity<UndoDeleteCommunity> {
type Actor = lemmy_apub::fetcher::Actor;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
let object = self.inner.object.inner.object.clone(); let object = self.inner.object.inner.object.clone();
@ -56,18 +58,16 @@ impl VerifyActivity for Activity<UndoDeleteCommunity> {
} }
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDeleteCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let actor = self.inner.object.inner.object.clone(); let object = self.inner.object.inner.object.clone();
let community = blocking(context.pool(), move |conn| { let community = blocking(context.pool(), move |conn| {
Community::read_from_apub_id(conn, &actor.into()) Community::read_from_apub_id(conn, &object.into())
}) })
.await?; .await?;
let community_id = match community { let community_id = match community {

View file

@ -5,7 +5,7 @@ use crate::{
use activitystreams::activity::kind::RemoveType; use activitystreams::activity::kind::RemoveType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::community::get_or_fetch_and_upsert_community}; use lemmy_apub::{check_is_apub_id_valid, fetcher::community::get_or_fetch_and_upsert_community};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::community::Community_; use lemmy_db_queries::source::community::Community_;
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
@ -23,7 +23,9 @@ pub struct UndoRemoveCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoRemoveCommunity> { impl ActivityHandler for Activity<UndoRemoveCommunity> {
type Actor = lemmy_apub::fetcher::Actor;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
@ -31,12 +33,10 @@ impl VerifyActivity for Activity<UndoRemoveCommunity> {
verify_domains_match(&self.actor, &self.inner.cc[0])?; verify_domains_match(&self.actor, &self.inner.cc[0])?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoRemoveCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -5,9 +5,12 @@ use crate::{
use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use activitystreams::{activity::kind::UpdateType, base::BaseExt};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, objects::FromApubToForm, GroupExt}; use lemmy_apub::{check_is_apub_id_valid, objects::FromApubToForm, GroupExt};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{ApubObject, Crud}; use lemmy_db_queries::{ApubObject, Crud};
use lemmy_db_schema::source::community::{Community, CommunityForm}; use lemmy_db_schema::source::{
community::{Community, CommunityForm},
person::Person,
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -25,19 +28,19 @@ pub struct UpdateCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UpdateCommunity> { impl ActivityHandler for Activity<UpdateCommunity> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
self.inner.object.id(self.inner.cc[0].as_str())?; self.inner.object.id(self.inner.cc[0].as_str())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_is_community_mod(self.actor.clone(), self.inner.cc[0].clone(), context).await verify_is_community_mod(self.actor.clone(), self.inner.cc[0].clone(), context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UpdateCommunity> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -1,13 +1,10 @@
use crate::{activities::follow::follow::FollowCommunity, inbox::new_inbox_routing::Activity}; use crate::{activities::follow::follow::FollowCommunity, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::AcceptType; use activitystreams::activity::kind::AcceptType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{ use lemmy_apub::{check_is_apub_id_valid, fetcher::person::get_or_fetch_and_upsert_person};
check_is_apub_id_valid, use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
};
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity};
use lemmy_db_queries::Followable; use lemmy_db_queries::Followable;
use lemmy_db_schema::source::community::CommunityFollower; use lemmy_db_schema::source::community::{Community, CommunityFollower};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -21,29 +18,27 @@ pub struct AcceptFollowCommunity {
kind: AcceptType, kind: AcceptType,
} }
/// Handle accepted follows
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<AcceptFollowCommunity> { impl ActivityHandler for Activity<AcceptFollowCommunity> {
type Actor = Community;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
/// Handle accepted follows
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<AcceptFollowCommunity> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community =
get_or_fetch_and_upsert_community(&self.actor, context, request_counter).await?;
let person = get_or_fetch_and_upsert_person(&self.inner.to, context, request_counter).await?; let person = get_or_fetch_and_upsert_person(&self.inner.to, context, request_counter).await?;
// This will throw an error if no follow was requested // This will throw an error if no follow was requested
blocking(&context.pool(), move |conn| { blocking(&context.pool(), move |conn| {
CommunityFollower::follow_accepted(conn, community.id, person.id) CommunityFollower::follow_accepted(conn, actor.id, person.id)
}) })
.await??; .await??;

View file

@ -7,12 +7,15 @@ use anyhow::Context;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{ use lemmy_apub::{
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person}, fetcher::community::get_or_fetch_and_upsert_community,
CommunityType, CommunityType,
}; };
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
use lemmy_db_queries::Followable; use lemmy_db_queries::Followable;
use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm}; use lemmy_db_schema::source::{
community::{CommunityFollower, CommunityFollowerForm},
person::Person,
};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -27,27 +30,26 @@ pub struct FollowCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<FollowCommunity> { impl ActivityHandler for Activity<FollowCommunity> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.inner.to, &self.inner.object)?; verify_domains_match(&self.inner.to, &self.inner.object)?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<FollowCommunity> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community = let community =
get_or_fetch_and_upsert_community(&self.inner.object, context, request_counter).await?; get_or_fetch_and_upsert_community(&self.inner.object, context, request_counter).await?;
let person = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
let community_follower_form = CommunityFollowerForm { let community_follower_form = CommunityFollowerForm {
community_id: community.id, community_id: community.id,
person_id: person.id, person_id: actor.id,
pending: false, pending: false,
}; };

View file

@ -1,13 +1,13 @@
use crate::{activities::follow::follow::FollowCommunity, inbox::new_inbox_routing::Activity}; use crate::{activities::follow::follow::FollowCommunity, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{ use lemmy_apub::{check_is_apub_id_valid, fetcher::community::get_or_fetch_and_upsert_community};
check_is_apub_id_valid, use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
};
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity};
use lemmy_db_queries::Followable; use lemmy_db_queries::Followable;
use lemmy_db_schema::source::community::{CommunityFollower, CommunityFollowerForm}; use lemmy_db_schema::source::{
community::{CommunityFollower, CommunityFollowerForm},
person::Person,
};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -22,29 +22,28 @@ pub struct UndoFollowCommunity {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoFollowCommunity> { impl ActivityHandler for Activity<UndoFollowCommunity> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.inner.to, &self.inner.object.inner.object)?; verify_domains_match(&self.inner.to, &self.inner.object.inner.object)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoFollowCommunity> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community = let community =
get_or_fetch_and_upsert_community(&self.inner.to, context, request_counter).await?; get_or_fetch_and_upsert_community(&self.inner.to, context, request_counter).await?;
let person = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
let community_follower_form = CommunityFollowerForm { let community_follower_form = CommunityFollowerForm {
community_id: community.id, community_id: community.id,
person_id: person.id, person_id: actor.id,
pending: false, pending: false,
}; };

View file

@ -1,14 +1,8 @@
use crate::{activities::post::send_websocket_message, inbox::new_inbox_routing::Activity}; use crate::{activities::post::send_websocket_message, inbox::new_inbox_routing::Activity};
use activitystreams::{activity::kind::CreateType, base::BaseExt}; use activitystreams::{activity::kind::CreateType, base::BaseExt};
use lemmy_apub::{ use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, ActorType, PageExt};
check_is_apub_id_valid, use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
fetcher::person::get_or_fetch_and_upsert_person, use lemmy_db_schema::source::{person::Person, post::Post};
objects::FromApub,
ActorType,
PageExt,
};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity};
use lemmy_db_schema::source::post::Post;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -24,27 +18,25 @@ pub struct CreatePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<CreatePost> { impl ActivityHandler for Activity<CreatePost> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(self.id_unchecked(), &self.actor)?; verify_domains_match(self.id_unchecked(), &self.actor)?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<CreatePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
let post = Post::from_apub( let post = Post::from_apub(
&self.inner.object, &self.inner.object,
context, context,
person.actor_id(), actor.actor_id(),
request_counter, request_counter,
false, false,
) )

View file

@ -2,9 +2,9 @@ use crate::{activities::post::send_websocket_message, inbox::new_inbox_routing::
use activitystreams::activity::kind::DeleteType; use activitystreams::activity::kind::DeleteType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::post::Post_; use lemmy_db_queries::source::post::Post_;
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::{person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -20,18 +20,18 @@ pub struct DeletePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DeletePost> { impl ActivityHandler for Activity<DeletePost> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object)?; verify_domains_match(&self.actor, &self.inner.object)?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DeletePost> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -1,7 +1,8 @@
use crate::{activities::post::like_or_dislike_post, inbox::new_inbox_routing::Activity}; use crate::{activities::post::like_or_dislike_post, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::DislikeType; use activitystreams::activity::kind::DislikeType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -17,27 +18,20 @@ pub struct DislikePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DislikePost> { impl ActivityHandler for Activity<DislikePost> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DislikePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
like_or_dislike_post( like_or_dislike_post(-1, &actor, &self.inner.object, context, request_counter).await
-1,
&self.actor,
&self.inner.object,
context,
request_counter,
)
.await
} }
} }

View file

@ -1,7 +1,8 @@
use crate::{activities::post::like_or_dislike_post, inbox::new_inbox_routing::Activity}; use crate::{activities::post::like_or_dislike_post, inbox::new_inbox_routing::Activity};
use activitystreams::activity::kind::LikeType; use activitystreams::activity::kind::LikeType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -17,20 +18,20 @@ pub struct LikePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<LikePost> { impl ActivityHandler for Activity<LikePost> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<LikePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
like_or_dislike_post(1, &self.actor, &self.inner.object, context, request_counter).await like_or_dislike_post(1, &actor, &self.inner.object, context, request_counter).await
} }
} }

View file

@ -1,11 +1,11 @@
use lemmy_api_common::{blocking, post::PostResponse}; use lemmy_api_common::{blocking, post::PostResponse};
use lemmy_apub::fetcher::{ use lemmy_apub::fetcher::objects::get_or_fetch_and_insert_post;
objects::get_or_fetch_and_insert_post,
person::get_or_fetch_and_upsert_person,
};
use lemmy_db_queries::Likeable; use lemmy_db_queries::Likeable;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::post::{PostLike, PostLikeForm}, source::{
person::Person,
post::{PostLike, PostLikeForm},
},
PostId, PostId,
}; };
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
@ -47,21 +47,20 @@ async fn send_websocket_message<OP: ToString + Send + lemmy_websocket::Operation
async fn like_or_dislike_post( async fn like_or_dislike_post(
score: i16, score: i16,
actor: &Url, actor: &Person,
object: &Url, object: &Url,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
let post = get_or_fetch_and_insert_post(object, context, request_counter).await?; let post = get_or_fetch_and_insert_post(object, context, request_counter).await?;
let post_id = post.id; let post_id = post.id;
let like_form = PostLikeForm { let like_form = PostLikeForm {
post_id: post.id, post_id: post.id,
person_id: person.id, person_id: actor.id,
score, score,
}; };
let person_id = person.id; let person_id = actor.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
PostLike::remove(conn, person_id, post_id)?; PostLike::remove(conn, person_id, post_id)?;
PostLike::like(conn, &like_form) PostLike::like(conn, &like_form)
@ -72,16 +71,15 @@ async fn like_or_dislike_post(
} }
async fn undo_like_or_dislike_post( async fn undo_like_or_dislike_post(
actor: &Url, actor: &Person,
object: &Url, object: &Url,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
let post = get_or_fetch_and_insert_post(object, context, request_counter).await?; let post = get_or_fetch_and_insert_post(object, context, request_counter).await?;
let post_id = post.id; let post_id = post.id;
let person_id = person.id; let person_id = actor.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
PostLike::remove(conn, person_id, post_id) PostLike::remove(conn, person_id, post_id)
}) })

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::RemoveType; use activitystreams::activity::kind::RemoveType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::post::Post_; use lemmy_db_queries::source::post::Post_;
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::{person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -23,18 +23,18 @@ pub struct RemovePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<RemovePost> { impl ActivityHandler for Activity<RemovePost> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<RemovePost> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::post::Post_; use lemmy_db_queries::source::post::Post_;
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::{person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -23,19 +23,19 @@ pub struct UndoDeletePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeletePost> { impl ActivityHandler for Activity<UndoDeletePost> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.actor)?; verify_domains_match(&self.actor, &self.inner.object.actor)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDeletePost> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -4,7 +4,8 @@ use crate::{
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -20,24 +21,24 @@ pub struct UndoDislikePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDislikePost> { impl ActivityHandler for Activity<UndoDislikePost> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.inner.object)?; verify_domains_match(&self.actor, &self.inner.object.inner.object)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDislikePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
undo_like_or_dislike_post( undo_like_or_dislike_post(
&self.actor, &actor,
&self.inner.object.inner.object, &self.inner.object.inner.object,
context, context,
request_counter, request_counter,

View file

@ -4,7 +4,8 @@ use crate::{
}; };
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_schema::source::person::Person;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -18,26 +19,25 @@ pub struct UndoLikePost {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoLikePost> { impl ActivityHandler for Activity<UndoLikePost> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.inner.object)?; verify_domains_match(&self.actor, &self.inner.object.inner.object)?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoLikePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
undo_like_or_dislike_post( undo_like_or_dislike_post(
&self.actor, &actor,
&self.inner.object.inner.object, &self.inner.object.inner.object,
context, context,
request_counter, request_counter,

View file

@ -8,9 +8,9 @@ use crate::{
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post}; use lemmy_apub::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_post};
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::source::post::Post_; use lemmy_db_queries::source::post::Post_;
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::{person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -26,19 +26,19 @@ pub struct UndoRemovePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoRemovePost> { impl ActivityHandler for Activity<UndoRemovePost> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?; verify_mod_action(self.actor.clone(), self.inner.cc[0].clone(), context).await?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoRemovePost> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -4,16 +4,16 @@ use anyhow::Context;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::{ use lemmy_apub::{
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::person::get_or_fetch_and_upsert_person,
objects::{FromApub, FromApubToForm}, objects::{FromApub, FromApubToForm},
ActorType, ActorType,
PageExt, PageExt,
}; };
use lemmy_apub_lib::{verify_domains_match, PublicUrl, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler, PublicUrl};
use lemmy_db_queries::{ApubObject, Crud}; use lemmy_db_queries::{ApubObject, Crud};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
community::Community, community::Community,
person::Person,
post::{Post, PostForm}, post::{Post, PostForm},
}, },
DbUrl, DbUrl,
@ -33,26 +33,25 @@ pub struct UpdatePost {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UpdatePost> { impl ActivityHandler for Activity<UpdatePost> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UpdatePost> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let person = get_or_fetch_and_upsert_person(&self.actor, context, request_counter).await?;
let temp_post = PostForm::from_apub( let temp_post = PostForm::from_apub(
&self.inner.object, &self.inner.object,
context, context,
person.actor_id(), actor.actor_id(),
request_counter, request_counter,
false, false,
) )
@ -84,7 +83,7 @@ impl ReceiveActivity for Activity<UpdatePost> {
let post = Post::from_apub( let post = Post::from_apub(
&self.inner.object, &self.inner.object,
context, context,
person.actor_id(), actor.actor_id(),
request_counter, request_counter,
mod_action_allowed, mod_action_allowed,
) )

View file

@ -3,9 +3,9 @@ use crate::{
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::{activity::kind::CreateType, base::BaseExt}; use activitystreams::{activity::kind::CreateType, base::BaseExt};
use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, NoteExt}; use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, ActorType, NoteExt};
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -20,25 +20,25 @@ pub struct CreatePrivateMessage {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<CreatePrivateMessage> { impl ActivityHandler for Activity<CreatePrivateMessage> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(self.id_unchecked(), &self.actor)?; verify_domains_match(self.id_unchecked(), &self.actor)?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<CreatePrivateMessage> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let private_message = PrivateMessage::from_apub( let private_message = PrivateMessage::from_apub(
&self.inner.object, &self.inner.object,
context, context,
self.actor.clone(), actor.actor_id(),
request_counter, request_counter,
false, false,
) )

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::DeleteType; use activitystreams::activity::kind::DeleteType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject}; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -22,18 +22,18 @@ pub struct DeletePrivateMessage {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<DeletePrivateMessage> { impl ActivityHandler for Activity<DeletePrivateMessage> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object)?; verify_domains_match(&self.actor, &self.inner.object)?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<DeletePrivateMessage> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
_request_counter: &mut i32, _request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -5,9 +5,9 @@ use crate::{
use activitystreams::activity::kind::UndoType; use activitystreams::activity::kind::UndoType;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub::check_is_apub_id_valid; use lemmy_apub::check_is_apub_id_valid;
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject}; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -22,19 +22,19 @@ pub struct UndoDeletePrivateMessage {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UndoDeletePrivateMessage> { impl ActivityHandler for Activity<UndoDeletePrivateMessage> {
type Actor = Person;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(&self.actor, self.id_unchecked())?; verify_domains_match(&self.actor, self.id_unchecked())?;
verify_domains_match(&self.actor, &self.inner.object.id_unchecked())?; verify_domains_match(&self.actor, &self.inner.object.id_unchecked())?;
check_is_apub_id_valid(&self.actor, false)?; check_is_apub_id_valid(&self.actor, false)?;
self.inner.object.verify(context).await self.inner.object.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UndoDeletePrivateMessage> {
async fn receive( async fn receive(
&self, &self,
_actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
_request_counter: &mut i32, _request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {

View file

@ -3,9 +3,9 @@ use crate::{
inbox::new_inbox_routing::Activity, inbox::new_inbox_routing::Activity,
}; };
use activitystreams::{activity::kind::UpdateType, base::BaseExt}; use activitystreams::{activity::kind::UpdateType, base::BaseExt};
use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, NoteExt}; use lemmy_apub::{check_is_apub_id_valid, objects::FromApub, ActorType, NoteExt};
use lemmy_apub_lib::{verify_domains_match, ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::{verify_domains_match, ActivityHandler};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
@ -20,25 +20,25 @@ pub struct UpdatePrivateMessage {
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for Activity<UpdatePrivateMessage> { impl ActivityHandler for Activity<UpdatePrivateMessage> {
type Actor = Person;
async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, _context: &LemmyContext) -> Result<(), LemmyError> {
verify_domains_match(self.id_unchecked(), &self.actor)?; verify_domains_match(self.id_unchecked(), &self.actor)?;
self.inner.object.id(self.actor.as_str())?; self.inner.object.id(self.actor.as_str())?;
check_is_apub_id_valid(&self.actor, false) check_is_apub_id_valid(&self.actor, false)
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for Activity<UpdatePrivateMessage> {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let private_message = PrivateMessage::from_apub( let private_message = PrivateMessage::from_apub(
&self.inner.object, &self.inner.object,
context, context,
self.actor.clone(), actor.actor_id(),
request_counter, request_counter,
false, false,
) )

View file

@ -12,10 +12,12 @@ use crate::activities::{
update::UpdateComment, update::UpdateComment,
}, },
community::{ community::{
add_mod::AddMod,
announce::AnnounceActivity, announce::AnnounceActivity,
block_user::BlockUserFromCommunity, block_user::BlockUserFromCommunity,
delete::DeleteCommunity, delete::DeleteCommunity,
remove::RemoveCommunity, remove::RemoveCommunity,
remove_mod::RemoveMod,
undo_block_user::UndoBlockUserFromCommunity, undo_block_user::UndoBlockUserFromCommunity,
undo_delete::UndoDeleteCommunity, undo_delete::UndoDeleteCommunity,
undo_remove::UndoRemoveCommunity, undo_remove::UndoRemoveCommunity,
@ -42,7 +44,7 @@ use crate::activities::{
}, },
}; };
use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed}; use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed};
use lemmy_apub_lib::{ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::ActivityHandler;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
@ -105,27 +107,28 @@ pub enum SharedInboxActivities {
UpdateCommunity(UpdateCommunity), UpdateCommunity(UpdateCommunity),
DeleteCommunity(DeleteCommunity), DeleteCommunity(DeleteCommunity),
RemoveCommunity(RemoveCommunity), RemoveCommunity(RemoveCommunity),
AddMod(AddMod),
RemoveMod(RemoveMod),
UndoDeleteCommunity(UndoDeleteCommunity), UndoDeleteCommunity(UndoDeleteCommunity),
UndoRemoveCommunity(UndoRemoveCommunity), UndoRemoveCommunity(UndoRemoveCommunity),
BlockUserFromCommunity(BlockUserFromCommunity), BlockUserFromCommunity(BlockUserFromCommunity),
UndoBlockUserFromCommunity(UndoBlockUserFromCommunity), UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
} }
// todo: can probably get rid of these?
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl VerifyActivity for SharedInboxActivities { impl ActivityHandler for SharedInboxActivities {
type Actor = lemmy_apub::fetcher::Actor;
async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> { async fn verify(&self, context: &LemmyContext) -> Result<(), LemmyError> {
self.verify(context).await self.verify(context).await
} }
}
#[async_trait::async_trait(?Send)]
impl ReceiveActivity for SharedInboxActivities {
async fn receive( async fn receive(
&self, &self,
actor: Self::Actor,
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
self.receive(context, request_counter).await self.receive(actor, context, request_counter).await
} }
} }

View file

@ -4,14 +4,15 @@ use crate::inbox::{
new_inbox_routing::{Activity, SharedInboxActivities}, new_inbox_routing::{Activity, SharedInboxActivities},
}; };
use actix_web::{web, HttpRequest, HttpResponse}; use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::Context;
use lemmy_apub::{ use lemmy_apub::{
check_is_apub_id_valid, check_is_apub_id_valid,
extensions::signatures::verify_signature, extensions::signatures::verify_signature,
fetcher::get_or_fetch_and_upsert_actor, fetcher::{get_or_fetch_and_upsert_actor2, Actor},
insert_activity, insert_activity,
}; };
use lemmy_apub_lib::{ReceiveActivity, VerifyActivity}; use lemmy_apub_lib::ActivityHandler;
use lemmy_utils::LemmyError; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
pub async fn shared_inbox( pub async fn shared_inbox(
@ -30,8 +31,12 @@ pub async fn shared_inbox(
activity.inner.verify(&context).await?; activity.inner.verify(&context).await?;
let request_counter = &mut 0; let request_counter = &mut 0;
let actor = get_or_fetch_and_upsert_actor(&activity.actor, &context, request_counter).await?; let actor = get_or_fetch_and_upsert_actor2(&activity.actor, &context, request_counter).await?;
verify_signature(&request, actor.as_ref())?; let public_key = match &actor {
Actor::Person(p) => p.public_key.as_ref().context(location_info!())?,
Actor::Community(c) => c.public_key.as_ref().context(location_info!())?,
};
verify_signature(&request, &public_key)?;
// Log the activity, so we avoid receiving and parsing it twice. Note that this could still happen // Log the activity, so we avoid receiving and parsing it twice. Note that this could still happen
// if we receive the same activity twice in very quick succession. // if we receive the same activity twice in very quick succession.
@ -44,7 +49,9 @@ pub async fn shared_inbox(
) )
.await?; .await?;
// TODO: pass the actor in somehow activity
activity.inner.receive(&context, request_counter).await?; .inner
.receive(actor, &context, request_counter)
.await?;
return Ok(HttpResponse::Ok().finish()); return Ok(HttpResponse::Ok().finish());
} }