2 http::{create_apub_response, create_apub_tombstone_response, err_object_not_local},
3 objects::comment::ApubComment,
5 use activitypub_federation::{config::Data, traits::Object};
6 use actix_web::{web::Path, HttpResponse};
7 use lemmy_api_common::context::LemmyContext;
8 use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
9 use lemmy_utils::error::LemmyError;
10 use serde::Deserialize;
12 #[derive(Deserialize)]
13 pub(crate) struct CommentQuery {
17 /// Return the ActivityPub json representation of a local comment over HTTP.
18 #[tracing::instrument(skip_all)]
19 pub(crate) async fn get_apub_comment(
20 info: Path<CommentQuery>,
21 context: Data<LemmyContext>,
22 ) -> Result<HttpResponse, LemmyError> {
23 let id = CommentId(info.comment_id.parse::<i32>()?);
24 let comment: ApubComment = Comment::read(&mut context.pool(), id).await?.into();
26 return Err(err_object_not_local());
29 if !comment.deleted && !comment.removed {
30 create_apub_response(&comment.into_json(&context).await?)
32 create_apub_tombstone_response(comment.ap_id.clone())