2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{MarkPersonMentionAsRead, PersonMentionResponse},
5 utils::{blocking, get_local_user_view_from_jwt},
7 use lemmy_db_schema::{source::person_mention::PersonMention, traits::Crud};
8 use lemmy_db_views_actor::structs::PersonMentionView;
9 use lemmy_utils::{error::LemmyError, ConnectionId};
10 use lemmy_websocket::LemmyContext;
12 #[async_trait::async_trait(?Send)]
13 impl Perform for MarkPersonMentionAsRead {
14 type Response = PersonMentionResponse;
16 #[tracing::instrument(skip(context, _websocket_id))]
19 context: &Data<LemmyContext>,
20 _websocket_id: Option<ConnectionId>,
21 ) -> Result<PersonMentionResponse, LemmyError> {
22 let data: &MarkPersonMentionAsRead = self;
24 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
26 let person_mention_id = data.person_mention_id;
27 let read_person_mention = blocking(context.pool(), move |conn| {
28 PersonMention::read(conn, person_mention_id)
32 if local_user_view.person.id != read_person_mention.recipient_id {
33 return Err(LemmyError::from_message("couldnt_update_comment"));
36 let person_mention_id = read_person_mention.id;
39 move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
40 blocking(context.pool(), update_mention)
42 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
44 let person_mention_id = read_person_mention.id;
45 let person_id = local_user_view.person.id;
46 let person_mention_view = blocking(context.pool(), move |conn| {
47 PersonMentionView::read(conn, person_mention_id, Some(person_id))
51 Ok(PersonMentionResponse {