X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapub%2Fsrc%2Fhttp%2Fperson.rs;h=2543136348dd185e858be07cbf53932676f3ab48;hb=21a87ebaf2e5c038594eb70ef58bd51826259529;hp=6a5a9a27b8fcf6d4b6c7cb0d90f626ae13b0f5d2;hpb=4c8f2e976effe381d4ea1914462c43242a8c64fd;p=lemmy.git diff --git a/crates/apub/src/http/person.rs b/crates/apub/src/http/person.rs index 6a5a9a27..25431363 100644 --- a/crates/apub/src/http/person.rs +++ b/crates/apub/src/http/person.rs @@ -1,21 +1,21 @@ use crate::{ - extensions::context::lemmy_context, + activity_lists::PersonInboxActivities, + fetcher::user_or_community::UserOrCommunity, http::{create_apub_response, create_apub_tombstone_response}, - objects::ToApub, - ActorType, + objects::person::ApubPerson, + protocol::collections::empty_outbox::EmptyOutbox, }; -use activitystreams::{ - base::BaseExt, - collection::{CollectionExt, OrderedCollection}, +use activitypub_federation::{ + actix_web::inbox::receive_activity, + config::Data, + protocol::context::WithContext, + traits::Object, }; -use actix_web::{body::Body, web, HttpResponse}; -use lemmy_api_common::blocking; -use lemmy_db_queries::source::person::Person_; -use lemmy_db_schema::source::person::Person; -use lemmy_utils::LemmyError; -use lemmy_websocket::LemmyContext; +use actix_web::{web, web::Bytes, HttpRequest, HttpResponse}; +use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url}; +use lemmy_db_schema::{source::person::Person, traits::ApubActor}; +use lemmy_utils::error::LemmyError; use serde::Deserialize; -use url::Url; #[derive(Deserialize)] pub struct PersonQuery { @@ -23,56 +23,45 @@ pub struct PersonQuery { } /// Return the ActivityPub json representation of a local person over HTTP. +#[tracing::instrument(skip_all)] pub(crate) async fn get_apub_person_http( info: web::Path, - context: web::Data, -) -> Result, LemmyError> { + context: Data, +) -> Result { let user_name = info.into_inner().user_name; // TODO: this needs to be able to read deleted persons, so that it can send tombstones - let person = blocking(context.pool(), move |conn| { - Person::find_by_name(conn, &user_name) - }) - .await??; + let person: ApubPerson = Person::read_from_name(&mut context.pool(), &user_name, true) + .await? + .into(); if !person.deleted { - let apub = person.to_apub(context.pool()).await?; + let apub = person.into_json(&context).await?; - Ok(create_apub_response(&apub)) + create_apub_response(&apub) } else { - Ok(create_apub_tombstone_response(&person.to_tombstone()?)) + create_apub_tombstone_response(person.actor_id.clone()) } } -pub(crate) async fn get_apub_person_outbox( - info: web::Path, - context: web::Data, -) -> Result, LemmyError> { - let person = blocking(context.pool(), move |conn| { - Person::find_by_name(&conn, &info.user_name) - }) - .await??; - // TODO: populate the person outbox - let mut collection = OrderedCollection::new(); - collection - .set_many_items(Vec::::new()) - .set_many_contexts(lemmy_context()?) - .set_id(person.get_outbox_url()?) - .set_total_items(0_u64); - Ok(create_apub_response(&collection)) +#[tracing::instrument(skip_all)] +pub async fn person_inbox( + request: HttpRequest, + body: Bytes, + data: Data, +) -> Result { + receive_activity::, UserOrCommunity, LemmyContext>( + request, body, &data, + ) + .await } -pub(crate) async fn get_apub_person_inbox( +#[tracing::instrument(skip_all)] +pub(crate) async fn get_apub_person_outbox( info: web::Path, - context: web::Data, -) -> Result, LemmyError> { - let person = blocking(context.pool(), move |conn| { - Person::find_by_name(&conn, &info.user_name) - }) - .await??; - - let mut collection = OrderedCollection::new(); - collection - .set_id(person.inbox_url.into()) - .set_many_contexts(lemmy_context()?); - Ok(create_apub_response(&collection)) + context: Data, +) -> Result { + let person = Person::read_from_name(&mut context.pool(), &info.user_name, false).await?; + let outbox_id = generate_outbox_url(&person.actor_id)?.into(); + let outbox = EmptyOutbox::new(outbox_id)?; + create_apub_response(&outbox) }