2020-12-08 17:38:48 +00:00
|
|
|
use crate::{
|
|
|
|
extensions::context::lemmy_context,
|
|
|
|
http::create_apub_response,
|
|
|
|
objects::ToApub,
|
|
|
|
ActorType,
|
|
|
|
};
|
2020-11-18 16:04:35 +00:00
|
|
|
use activitystreams::{
|
|
|
|
base::BaseExt,
|
|
|
|
collection::{CollectionExt, OrderedCollection},
|
|
|
|
};
|
2020-10-12 14:10:09 +00:00
|
|
|
use actix_web::{body::Body, web, HttpResponse};
|
2020-12-18 18:38:32 +00:00
|
|
|
use lemmy_db::source::user::User;
|
|
|
|
use lemmy_db_schema::source::user::User_;
|
2020-10-12 14:10:09 +00:00
|
|
|
use lemmy_structs::blocking;
|
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use serde::Deserialize;
|
2020-11-18 16:04:35 +00:00
|
|
|
use url::Url;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UserQuery {
|
|
|
|
user_name: String,
|
|
|
|
}
|
|
|
|
|
2020-10-19 14:29:35 +00:00
|
|
|
/// Return the ActivityPub json representation of a local user over HTTP.
|
2020-10-12 14:10:09 +00:00
|
|
|
pub async fn get_apub_user_http(
|
|
|
|
info: web::Path<UserQuery>,
|
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
|
|
|
let user_name = info.into_inner().user_name;
|
|
|
|
let user = blocking(context.pool(), move |conn| {
|
|
|
|
User_::find_by_email_or_username(conn, &user_name)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
let u = user.to_apub(context.pool()).await?;
|
|
|
|
Ok(create_apub_response(&u))
|
|
|
|
}
|
2020-11-18 16:04:35 +00:00
|
|
|
|
|
|
|
pub async fn get_apub_user_outbox(
|
|
|
|
info: web::Path<UserQuery>,
|
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
|
|
|
let user = blocking(context.pool(), move |conn| {
|
|
|
|
User_::read_from_name(&conn, &info.user_name)
|
|
|
|
})
|
|
|
|
.await??;
|
2020-11-19 12:50:43 +00:00
|
|
|
// TODO: populate the user outbox
|
2020-11-18 16:04:35 +00:00
|
|
|
let mut collection = OrderedCollection::new();
|
|
|
|
collection
|
|
|
|
.set_many_items(Vec::<Url>::new())
|
2020-11-25 17:44:49 +00:00
|
|
|
.set_many_contexts(lemmy_context()?)
|
2020-11-18 16:04:35 +00:00
|
|
|
.set_id(user.get_outbox_url()?)
|
|
|
|
.set_total_items(0_u64);
|
|
|
|
Ok(create_apub_response(&collection))
|
|
|
|
}
|