]> Untitled Git - lemmy.git/blob - crates/apub/src/http/comment.rs
Add SendActivity trait so that api crates compile in parallel with lemmy_apub
[lemmy.git] / crates / apub / src / http / comment.rs
1 use crate::{
2   http::{create_apub_response, create_apub_tombstone_response},
3   objects::comment::ApubComment,
4 };
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;
12
13 #[derive(Deserialize)]
14 pub(crate) struct CommentQuery {
15   comment_id: String,
16 }
17
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();
26   if !comment.local {
27     return Err(NotFound.into());
28   }
29
30   if !comment.deleted && !comment.removed {
31     Ok(create_apub_response(&comment.into_apub(&context).await?))
32   } else {
33     Ok(create_apub_tombstone_response(comment.ap_id.clone()))
34   }
35 }