2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 comment::{CommentResponse, DistinguishComment},
6 utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
9 source::comment::{Comment, CommentUpdateForm},
12 use lemmy_db_views::structs::CommentView;
13 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
15 #[async_trait::async_trait(?Send)]
16 impl Perform for DistinguishComment {
17 type Response = CommentResponse;
19 #[tracing::instrument(skip(context))]
20 async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
21 let data: &DistinguishComment = self;
22 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
24 let comment_id = data.comment_id;
25 let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
28 local_user_view.person.id,
29 orig_comment.community.id,
34 // Verify that only a mod or admin can distinguish a comment
37 local_user_view.person.id,
38 orig_comment.community.id,
43 let comment_id = data.comment_id;
44 let form = CommentUpdateForm::builder()
45 .distinguished(Some(data.distinguished))
47 Comment::update(&mut context.pool(), comment_id, &form)
49 .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
51 let comment_id = data.comment_id;
52 let person_id = local_user_view.person.id;
53 let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
57 recipient_ids: Vec::new(),