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::builder()
42 .distinguished(Some(data.distinguished))
44 Comment::update(&mut context.pool(), comment_id, &form)
46 .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
48 let comment_id = data.comment_id;
49 let person_id = local_user_view.person.id;
50 let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
52 Ok(Json(CommentResponse {
54 recipient_ids: Vec::new(),