2 activity::{ActorAndObjectRef, ActorAndObjectRefExt},
3 base::{AsBase, BaseExt},
6 use anyhow::{anyhow, Context};
7 use lemmy_apub::fetcher::person::get_or_fetch_and_upsert_person;
8 use lemmy_db_schema::source::person::Person;
9 use lemmy_utils::{location_info, LemmyError};
10 use lemmy_websocket::LemmyContext;
15 pub(crate) mod comment;
16 pub(crate) mod comment_undo;
17 pub(crate) mod community;
19 pub(crate) mod post_undo;
20 pub(crate) mod private_message;
22 /// Return HTTP 501 for unsupported activities in inbox.
23 pub(crate) fn receive_unhandled_activity<A>(activity: A) -> Result<(), LemmyError>
27 debug!("received unhandled activity type: {:?}", activity);
28 Err(anyhow!("Activity not supported").into())
31 /// Reads the actor field of an activity and returns the corresponding `Person`.
32 pub(crate) async fn get_actor_as_person<T, A>(
34 context: &LemmyContext,
35 request_counter: &mut i32,
36 ) -> Result<Person, LemmyError>
38 T: AsBase<A> + ActorAndObjectRef,
40 let actor = activity.actor()?;
41 let person_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
42 get_or_fetch_and_upsert_person(person_uri, context, request_counter).await
45 /// Ensure that the ID of an incoming activity comes from the same domain as the actor. Optionally
46 /// also checks the ID of the inner object.
48 /// The reason that this starts with the actor ID is that it was already confirmed as correct by the
50 pub(crate) fn verify_activity_domains_valid<T, Kind>(
53 object_domain_must_match: bool,
54 ) -> Result<(), LemmyError>
56 T: AsBase<Kind> + ActorAndObjectRef,
58 let expected_domain = actor_id.domain().context(location_info!())?;
60 activity.id(expected_domain)?;
62 let object_id = match activity.object().to_owned().single_xsd_any_uri() {
63 // object is just an ID
65 // object is something like an activity, a comment or a post
70 .context(location_info!())?
72 .context(location_info!())?
76 if object_domain_must_match && object_id.domain() != Some(expected_domain) {
77 return Err(DomainError.into());