1 use actix_web::web::{Data, Json};
2 use lemmy_api_common::{
3 comment::{CommentResponse, DistinguishComment},
5 utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
8 source::comment::{Comment, CommentUpdateForm},
11 use lemmy_db_views::structs::CommentView;
12 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
14 #[tracing::instrument(skip(context))]
15 pub async fn distinguish_comment(
16 data: Json<DistinguishComment>,
17 context: Data<LemmyContext>,
18 ) -> Result<Json<CommentResponse>, LemmyError> {
19 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
21 let comment_id = data.comment_id;
22 let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
25 local_user_view.person.id,
26 orig_comment.community.id,
31 // Verify that only a mod or admin can distinguish a comment
34 local_user_view.person.id,
35 orig_comment.community.id,
40 let comment_id = data.comment_id;
41 let form = CommentUpdateForm {
42 distinguished: Some(data.distinguished),
45 Comment::update(&mut context.pool(), comment_id, &form)
47 .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
49 let comment_id = data.comment_id;
50 let person_id = local_user_view.person.id;
51 let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
53 Ok(Json(CommentResponse {
55 recipient_ids: Vec::new(),