2021-07-17 16:20:44 +00:00
|
|
|
use crate::{
|
2022-11-12 13:52:57 +00:00
|
|
|
activity_lists::PersonInboxActivitiesWithAnnouncable,
|
2022-06-02 14:33:41 +00:00
|
|
|
fetcher::user_or_community::UserOrCommunity,
|
2022-02-07 19:23:12 +00:00
|
|
|
generate_outbox_url,
|
2022-06-02 14:33:41 +00:00
|
|
|
http::{create_apub_response, create_apub_tombstone_response, receive_lemmy_activity},
|
2021-10-18 21:36:44 +00:00
|
|
|
objects::person::ApubPerson,
|
2022-02-07 19:23:12 +00:00
|
|
|
protocol::collections::empty_outbox::EmptyOutbox,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
|
|
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
2022-01-27 16:39:22 +00:00
|
|
|
use lemmy_db_schema::{source::person::Person, traits::ApubActor};
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2021-10-29 10:32:42 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use serde::Deserialize;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2021-03-10 22:33:55 +00:00
|
|
|
pub struct PersonQuery {
|
2020-10-12 14:10:09 +00:00
|
|
|
user_name: String,
|
|
|
|
}
|
|
|
|
|
2021-03-10 22:33:55 +00:00
|
|
|
/// Return the ActivityPub json representation of a local person over HTTP.
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_http(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-10-12 14:10:09 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
2021-12-14 13:30:37 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2020-10-12 14:10:09 +00:00
|
|
|
let user_name = info.into_inner().user_name;
|
2021-03-10 22:33:55 +00:00
|
|
|
// TODO: this needs to be able to read deleted persons, so that it can send tombstones
|
2022-11-09 10:05:00 +00:00
|
|
|
let person: ApubPerson = Person::read_from_name(context.pool(), &user_name, true)
|
|
|
|
.await?
|
|
|
|
.into();
|
2021-01-12 16:12:41 +00:00
|
|
|
|
2021-03-10 22:33:55 +00:00
|
|
|
if !person.deleted {
|
2021-11-06 12:37:55 +00:00
|
|
|
let apub = person.into_apub(&context).await?;
|
2021-01-12 16:12:41 +00:00
|
|
|
|
|
|
|
Ok(create_apub_response(&apub))
|
|
|
|
} else {
|
2022-06-02 14:33:41 +00:00
|
|
|
Ok(create_apub_tombstone_response(person.actor_id.clone()))
|
2021-01-12 16:12:41 +00:00
|
|
|
}
|
2020-10-12 14:10:09 +00:00
|
|
|
}
|
2020-11-18 16:04:35 +00:00
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
pub async fn person_inbox(
|
|
|
|
request: HttpRequest,
|
2022-06-02 14:33:41 +00:00
|
|
|
payload: String,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-11-12 13:52:57 +00:00
|
|
|
receive_lemmy_activity::<WithContext<PersonInboxActivitiesWithAnnouncable>, UserOrCommunity>(
|
2022-06-02 14:33:41 +00:00
|
|
|
request, payload, context,
|
|
|
|
)
|
|
|
|
.await
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_outbox(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-11-18 16:04:35 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
2021-12-14 13:30:37 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let person = Person::read_from_name(context.pool(), &info.user_name, false).await?;
|
2022-02-07 19:23:12 +00:00
|
|
|
let outbox_id = generate_outbox_url(&person.actor_id)?.into();
|
|
|
|
let outbox = EmptyOutbox::new(outbox_id).await?;
|
2021-10-28 15:52:11 +00:00
|
|
|
Ok(create_apub_response(&outbox))
|
2020-11-18 16:04:35 +00:00
|
|
|
}
|