2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 get_local_user_view_from_jwt,
6 person::{MarkPersonMentionAsRead, PersonMentionResponse},
8 use lemmy_db_schema::{source::person_mention::PersonMention, traits::Crud};
9 use lemmy_db_views_actor::person_mention_view::PersonMentionView;
10 use lemmy_utils::{ConnectionId, LemmyError};
11 use lemmy_websocket::LemmyContext;
13 #[async_trait::async_trait(?Send)]
14 impl Perform for MarkPersonMentionAsRead {
15 type Response = PersonMentionResponse;
17 #[tracing::instrument(skip(context, _websocket_id))]
20 context: &Data<LemmyContext>,
21 _websocket_id: Option<ConnectionId>,
22 ) -> Result<PersonMentionResponse, LemmyError> {
23 let data: &MarkPersonMentionAsRead = self;
25 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
27 let person_mention_id = data.person_mention_id;
28 let read_person_mention = blocking(context.pool(), move |conn| {
29 PersonMention::read(conn, person_mention_id)
33 if local_user_view.person.id != read_person_mention.recipient_id {
34 return Err(LemmyError::from_message("couldnt_update_comment"));
37 let person_mention_id = read_person_mention.id;
40 move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
41 blocking(context.pool(), update_mention)
43 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
45 let person_mention_id = read_person_mention.id;
46 let person_id = local_user_view.person.id;
47 let person_mention_view = blocking(context.pool(), move |conn| {
48 PersonMentionView::read(conn, person_mention_id, Some(person_id))
52 Ok(PersonMentionResponse {