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