2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{CommentReplyResponse, MarkCommentReplyAsRead},
6 utils::local_user_view_from_jwt,
9 source::comment_reply::{CommentReply, CommentReplyUpdateForm},
12 use lemmy_db_views_actor::structs::CommentReplyView;
13 use lemmy_utils::error::LemmyError;
15 #[async_trait::async_trait(?Send)]
16 impl Perform for MarkCommentReplyAsRead {
17 type Response = CommentReplyResponse;
19 #[tracing::instrument(skip(context))]
22 context: &Data<LemmyContext>,
23 ) -> Result<CommentReplyResponse, LemmyError> {
25 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
27 let comment_reply_id = data.comment_reply_id;
28 let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
30 if local_user_view.person.id != read_comment_reply.recipient_id {
31 return Err(LemmyError::from_message("couldnt_update_comment"));
34 let comment_reply_id = read_comment_reply.id;
35 let read = Some(data.read);
40 &CommentReplyUpdateForm { read },
43 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
45 let comment_reply_id = read_comment_reply.id;
46 let person_id = local_user_view.person.id;
47 let comment_reply_view =
48 CommentReplyView::read(context.pool(), comment_reply_id, Some(person_id)).await?;
50 Ok(CommentReplyResponse { comment_reply_view })