1 use actix_web::web::{Data, Json};
2 use lemmy_api_common::{
4 person::{CommentReplyResponse, MarkCommentReplyAsRead},
5 utils::local_user_view_from_jwt,
8 source::comment_reply::{CommentReply, CommentReplyUpdateForm},
11 use lemmy_db_views_actor::structs::CommentReplyView;
12 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
14 #[tracing::instrument(skip(context))]
15 pub async fn mark_reply_as_read(
16 data: Json<MarkCommentReplyAsRead>,
17 context: Data<LemmyContext>,
18 ) -> Result<Json<CommentReplyResponse>, LemmyError> {
19 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
21 let comment_reply_id = data.comment_reply_id;
22 let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
24 if local_user_view.person.id != read_comment_reply.recipient_id {
25 return Err(LemmyErrorType::CouldntUpdateComment)?;
28 let comment_reply_id = read_comment_reply.id;
29 let read = Some(data.read);
34 &CommentReplyUpdateForm { read },
37 .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
39 let comment_reply_id = read_comment_reply.id;
40 let person_id = local_user_view.person.id;
41 let comment_reply_view =
42 CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
44 Ok(Json(CommentReplyResponse { comment_reply_view }))