mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-16 09:24:00 +00:00
Nutomic
9cc1cfc973
* Limit visibility of some traits and methods * WIP: alternative way to handle non-local object parsing * finish this * cleanup * Move check for locked post into Comment::from_apub() * Mark user as updated after fetching * Should set last_refreshed_at, not updated * Add ApubObject trait in DB, with method read_from_apub_id() * Create shared, generic implementation for `FromApub`, prefer local data * Check for community ban when parsing post/comment (fixes #1287) * Fix tests (changes in get_object_from_apub() prevented `Update` from working) * Support parsing `like.object` either as URL or object * Send out like.object as URL, instead of full object (fixes #1283) * add todo
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
use crate::{
|
|
extensions::context::lemmy_context,
|
|
http::create_apub_response,
|
|
objects::ToApub,
|
|
ActorType,
|
|
};
|
|
use activitystreams::{
|
|
base::BaseExt,
|
|
collection::{CollectionExt, OrderedCollection},
|
|
};
|
|
use actix_web::{body::Body, web, HttpResponse};
|
|
use lemmy_db::user::User_;
|
|
use lemmy_structs::blocking;
|
|
use lemmy_utils::LemmyError;
|
|
use lemmy_websocket::LemmyContext;
|
|
use serde::Deserialize;
|
|
use url::Url;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UserQuery {
|
|
user_name: String,
|
|
}
|
|
|
|
/// Return the ActivityPub json representation of a local user over HTTP.
|
|
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))
|
|
}
|
|
|
|
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??;
|
|
// TODO: populate the user outbox
|
|
let mut collection = OrderedCollection::new();
|
|
collection
|
|
.set_many_items(Vec::<Url>::new())
|
|
.set_many_contexts(lemmy_context()?)
|
|
.set_id(user.get_outbox_url()?)
|
|
.set_total_items(0_u64);
|
|
Ok(create_apub_response(&collection))
|
|
}
|