2021-03-25 15:19:40 -04:00
|
|
|
use crate::PerformCrud;
|
|
|
|
use actix_web::web::Data;
|
2021-12-15 14:49:59 -05:00
|
|
|
use lemmy_api_common::{
|
2022-05-03 13:44:13 -04:00
|
|
|
comment::{CommentResponse, GetComment},
|
2022-11-28 09:29:33 -05:00
|
|
|
context::LemmyContext,
|
2022-11-09 05:05:00 -05:00
|
|
|
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
|
2021-11-16 12:03:09 -05:00
|
|
|
};
|
2022-10-27 05:24:07 -04:00
|
|
|
use lemmy_db_schema::source::local_site::LocalSite;
|
2022-05-03 13:44:13 -04:00
|
|
|
use lemmy_db_views::structs::CommentView;
|
2022-06-02 10:33:41 -04:00
|
|
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
2021-03-25 15:19:40 -04:00
|
|
|
|
2021-11-23 10:53:48 -05:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl PerformCrud for GetComment {
|
|
|
|
type Response = CommentResponse;
|
|
|
|
|
2021-12-06 09:54:47 -05:00
|
|
|
#[tracing::instrument(skip(context, _websocket_id))]
|
2021-11-23 10:53:48 -05: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 09:54:47 -05:00
|
|
|
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
|
|
|
|
.await?;
|
2022-11-09 05:05:00 -05:00
|
|
|
let local_site = LocalSite::read(context.pool()).await?;
|
2021-11-23 10:53:48 -05:00
|
|
|
|
2022-10-27 05:24:07 -04:00
|
|
|
check_private_instance(&local_user_view, &local_site)?;
|
2021-12-15 14:49:59 -05:00
|
|
|
|
2021-11-23 10:53:48 -05:00
|
|
|
let person_id = local_user_view.map(|u| u.person.id);
|
|
|
|
let id = data.id;
|
2022-11-09 05:05:00 -05:00
|
|
|
let comment_view = CommentView::read(context.pool(), id, person_id)
|
|
|
|
.await
|
|
|
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_comment"))?;
|
2021-11-23 10:53:48 -05:00
|
|
|
|
|
|
|
Ok(Self::Response {
|
|
|
|
comment_view,
|
|
|
|
form_id: None,
|
|
|
|
recipient_ids: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|