2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{CommentReplyResponse, MarkCommentReplyAsRead},
5 utils::{blocking, get_local_user_view_from_jwt},
7 use lemmy_db_schema::{source::comment_reply::CommentReply, traits::Crud};
8 use lemmy_db_views_actor::structs::CommentReplyView;
9 use lemmy_utils::{error::LemmyError, ConnectionId};
10 use lemmy_websocket::LemmyContext;
12 #[async_trait::async_trait(?Send)]
13 impl Perform for MarkCommentReplyAsRead {
14 type Response = CommentReplyResponse;
16 #[tracing::instrument(skip(context, _websocket_id))]
19 context: &Data<LemmyContext>,
20 _websocket_id: Option<ConnectionId>,
21 ) -> Result<CommentReplyResponse, LemmyError> {
24 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
26 let comment_reply_id = data.comment_reply_id;
27 let read_comment_reply = blocking(context.pool(), move |conn| {
28 CommentReply::read(conn, comment_reply_id)
32 if local_user_view.person.id != read_comment_reply.recipient_id {
33 return Err(LemmyError::from_message("couldnt_update_comment"));
36 let comment_reply_id = read_comment_reply.id;
38 let update_reply = move |conn: &mut _| CommentReply::update_read(conn, comment_reply_id, read);
39 blocking(context.pool(), update_reply)
41 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
43 let comment_reply_id = read_comment_reply.id;
44 let person_id = local_user_view.person.id;
45 let comment_reply_view = blocking(context.pool(), move |conn| {
46 CommentReplyView::read(conn, comment_reply_id, Some(person_id))
50 Ok(CommentReplyResponse { comment_reply_view })