2021-07-17 16:20:44 +00:00
|
|
|
use crate::{
|
2021-08-19 21:24:33 +00:00
|
|
|
activities::{
|
|
|
|
community::announce::{AnnouncableActivities, AnnounceActivity},
|
|
|
|
following::accept::AcceptFollowCommunity,
|
|
|
|
private_message::{
|
|
|
|
create_or_update::CreateOrUpdatePrivateMessage,
|
|
|
|
delete::DeletePrivateMessage,
|
|
|
|
undo_delete::UndoDeletePrivateMessage,
|
|
|
|
},
|
|
|
|
},
|
2021-07-17 16:20:44 +00:00
|
|
|
extensions::context::lemmy_context,
|
|
|
|
http::{
|
|
|
|
create_apub_response,
|
|
|
|
create_apub_tombstone_response,
|
|
|
|
payload_to_string,
|
|
|
|
receive_activity,
|
|
|
|
},
|
|
|
|
objects::ToApub,
|
|
|
|
ActorType,
|
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
|
|
|
};
|
2020-11-18 16:04:35 +00:00
|
|
|
use activitystreams::{
|
|
|
|
base::BaseExt,
|
|
|
|
collection::{CollectionExt, OrderedCollection},
|
|
|
|
};
|
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
|
|
|
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
|
2021-03-25 19:19:40 +00:00
|
|
|
use lemmy_api_common::blocking;
|
2021-08-19 21:24:33 +00:00
|
|
|
use lemmy_apub_lib::{ActivityFields, ActivityHandler};
|
2021-03-10 22:33:55 +00:00
|
|
|
use lemmy_db_queries::source::person::Person_;
|
|
|
|
use lemmy_db_schema::source::person::Person;
|
2020-10-12 14:10:09 +00:00
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
2021-08-19 21:24:33 +00:00
|
|
|
use log::trace;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2020-11-18 16:04:35 +00:00
|
|
|
use url::Url;
|
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-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>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
|
|
|
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
|
|
|
|
let person = blocking(context.pool(), move |conn| {
|
|
|
|
Person::find_by_name(conn, &user_name)
|
2020-10-12 14:10:09 +00:00
|
|
|
})
|
|
|
|
.await??;
|
2021-01-12 16:12:41 +00:00
|
|
|
|
2021-03-10 22:33:55 +00:00
|
|
|
if !person.deleted {
|
|
|
|
let apub = person.to_apub(context.pool()).await?;
|
2021-01-12 16:12:41 +00:00
|
|
|
|
|
|
|
Ok(create_apub_response(&apub))
|
|
|
|
} else {
|
2021-03-10 22:33:55 +00:00
|
|
|
Ok(create_apub_tombstone_response(&person.to_tombstone()?))
|
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-08-19 21:24:33 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum PersonInboxActivities {
|
|
|
|
AcceptFollowCommunity(AcceptFollowCommunity),
|
|
|
|
/// Some activities can also be sent from user to user, eg a comment with mentions
|
|
|
|
AnnouncableActivities(AnnouncableActivities),
|
|
|
|
CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
|
|
|
|
DeletePrivateMessage(DeletePrivateMessage),
|
|
|
|
UndoDeletePrivateMessage(UndoDeletePrivateMessage),
|
|
|
|
AnnounceActivity(Box<AnnounceActivity>),
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
payload: Payload,
|
|
|
|
_path: web::Path<String>,
|
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
|
|
|
let unparsed = payload_to_string(payload).await?;
|
2021-08-19 21:24:33 +00:00
|
|
|
trace!("Received person inbox activity {}", unparsed);
|
|
|
|
let activity = serde_json::from_str::<PersonInboxActivities>(&unparsed)?;
|
|
|
|
receive_person_inbox(activity, request, &context).await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(in crate::http) async fn receive_person_inbox(
|
|
|
|
activity: PersonInboxActivities,
|
|
|
|
request: HttpRequest,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
|
|
|
receive_activity(request, activity, 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-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>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
2021-03-10 22:33:55 +00:00
|
|
|
let person = blocking(context.pool(), move |conn| {
|
2021-07-05 16:07:26 +00:00
|
|
|
Person::find_by_name(conn, &info.user_name)
|
2020-11-18 16:04:35 +00:00
|
|
|
})
|
|
|
|
.await??;
|
2021-03-10 22:33:55 +00:00
|
|
|
// TODO: populate the person outbox
|
2020-11-18 16:04:35 +00:00
|
|
|
let mut collection = OrderedCollection::new();
|
|
|
|
collection
|
|
|
|
.set_many_items(Vec::<Url>::new())
|
2021-07-29 08:58:29 +00:00
|
|
|
.set_many_contexts(lemmy_context())
|
2021-03-10 22:33:55 +00:00
|
|
|
.set_id(person.get_outbox_url()?)
|
2020-11-18 16:04:35 +00:00
|
|
|
.set_total_items(0_u64);
|
|
|
|
Ok(create_apub_response(&collection))
|
|
|
|
}
|
2020-12-16 20:07:48 +00:00
|
|
|
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_inbox(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-12-16 20:07:48 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
2021-03-10 22:33:55 +00:00
|
|
|
let person = blocking(context.pool(), move |conn| {
|
2021-07-05 16:07:26 +00:00
|
|
|
Person::find_by_name(conn, &info.user_name)
|
2020-12-16 20:07:48 +00:00
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
let mut collection = OrderedCollection::new();
|
|
|
|
collection
|
2021-03-19 16:11:34 +00:00
|
|
|
.set_id(person.inbox_url.into())
|
2021-07-29 08:58:29 +00:00
|
|
|
.set_many_contexts(lemmy_context());
|
2020-12-16 20:07:48 +00:00
|
|
|
Ok(create_apub_response(&collection))
|
|
|
|
}
|