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},
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::{check_private_instance, local_user_view_from_jwt_opt},
|
2021-11-16 17:03:09 +00:00
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
use lemmy_db_schema::source::local_site::LocalSite;
|
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
|
|
|
|
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;
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
2022-11-09 10:05:00 +00:00
|
|
|
let local_site = LocalSite::read(context.pool()).await?;
|
2021-11-23 15:53:48 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
check_private_instance(&local_user_view, &local_site)?;
|
2021-12-15 19:49:59 +00:00
|
|
|
|
2021-11-23 15:53:48 +00:00
|
|
|
let person_id = local_user_view.map(|u| u.person.id);
|
|
|
|
let id = data.id;
|
2022-11-09 10:05:00 +00: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 15:53:48 +00:00
|
|
|
|
|
|
|
Ok(Self::Response {
|
|
|
|
comment_view,
|
|
|
|
form_id: None,
|
|
|
|
recipient_ids: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|