1 use crate::APUB_JSON_CONTENT_TYPE;
2 use actix_web::{body::Body, web, HttpResponse};
4 use lemmy_api_structs::blocking;
5 use lemmy_db_queries::source::activity::Activity_;
6 use lemmy_db_schema::source::activity::Activity;
7 use lemmy_utils::{settings::Settings, LemmyError};
8 use lemmy_websocket::LemmyContext;
9 use serde::{Deserialize, Serialize};
16 /// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
18 fn create_apub_response<T>(data: &T) -> HttpResponse<Body>
23 .content_type(APUB_JSON_CONTENT_TYPE)
27 fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
32 .content_type(APUB_JSON_CONTENT_TYPE)
33 .status(StatusCode::GONE)
37 #[derive(Deserialize)]
38 pub struct CommunityQuery {
43 /// Return the ActivityPub json representation of a local community over HTTP.
44 pub async fn get_activity(
45 info: web::Path<CommunityQuery>,
46 context: web::Data<LemmyContext>,
47 ) -> Result<HttpResponse<Body>, LemmyError> {
48 let settings = Settings::get();
49 let activity_id = format!(
50 "{}/activities/{}/{}",
51 settings.get_protocol_and_hostname(),
55 let activity = blocking(context.pool(), move |conn| {
56 Activity::read_from_apub_id(&conn, &activity_id)
60 let sensitive = activity.sensitive.unwrap_or(true);
61 if !activity.local || sensitive {
62 Ok(HttpResponse::NotFound().finish())
64 Ok(create_apub_response(&activity.data))