lemmy/lemmy_apub/src/http/comment.rs
Nutomic 9cc1cfc973
Apub local object handling (#1297)
* 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
2020-12-08 12:38:48 -05:00

36 lines
1 KiB
Rust

use crate::{
http::{create_apub_response, create_apub_tombstone_response},
objects::ToApub,
};
use actix_web::{body::Body, web, web::Path, HttpResponse};
use diesel::result::Error::NotFound;
use lemmy_db::{comment::Comment, Crud};
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct CommentQuery {
comment_id: String,
}
/// Return the ActivityPub json representation of a local comment over HTTP.
pub async fn get_apub_comment(
info: Path<CommentQuery>,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse<Body>, LemmyError> {
let id = info.comment_id.parse::<i32>()?;
let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
if !comment.local {
return Err(NotFound.into());
}
if !comment.deleted {
Ok(create_apub_response(
&comment.to_apub(context.pool()).await?,
))
} else {
Ok(create_apub_tombstone_response(&comment.to_tombstone()?))
}
}