2021-03-25 19:19:40 +00:00
|
|
|
use crate::PerformCrud;
|
|
|
|
use actix_web::web::Data;
|
2021-12-15 19:49:59 +00:00
|
|
|
use lemmy_api_common::{
|
2022-05-03 17:44:13 +00:00
|
|
|
comment::{CommentResponse, GetComment},
|
|
|
|
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
|
2021-11-16 17:03:09 +00:00
|
|
|
};
|
2022-05-03 17:44:13 +00:00
|
|
|
use lemmy_db_views::structs::CommentView;
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
2021-03-25 19:19:40 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
|
2021-11-23 15:53:48 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl PerformCrud for GetComment {
|
|
|
|
type Response = CommentResponse;
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip(context, _websocket_id))]
|
2021-11-23 15:53:48 +00:00
|
|
|
async fn perform(
|
|
|
|
&self,
|
|
|
|
context: &Data<LemmyContext>,
|
|
|
|
_websocket_id: Option<ConnectionId>,
|
|
|
|
) -> Result<Self::Response, LemmyError> {
|
|
|
|
let data = self;
|
|
|
|
let local_user_view =
|
2021-12-06 14:54:47 +00:00
|
|
|
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
|
|
.await?;
|
2021-11-23 15:53:48 +00:00
|
|
|
|
2021-12-15 19:49:59 +00:00
|
|
|
check_private_instance(&local_user_view, context.pool()).await?;
|
|
|
|
|
2021-11-23 15:53:48 +00:00
|
|
|
let person_id = local_user_view.map(|u| u.person.id);
|
|
|
|
let id = data.id;
|
|
|
|
let comment_view = blocking(context.pool(), move |conn| {
|
|
|
|
CommentView::read(conn, id, person_id)
|
|
|
|
})
|
|
|
|
.await?
|
2022-03-16 20:11:49 +00:00
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_comment"))?;
|
2021-11-23 15:53:48 +00:00
|
|
|
|
|
|
|
Ok(Self::Response {
|
|
|
|
comment_view,
|
|
|
|
form_id: None,
|
|
|
|
recipient_ids: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|