2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{MarkPersonMentionAsRead, PersonMentionResponse},
5 utils::get_local_user_view_from_jwt,
9 source::person_mention::{PersonMention, PersonMentionUpdateForm},
12 use lemmy_db_views_actor::structs::PersonMentionView;
13 use lemmy_utils::{error::LemmyError, ConnectionId};
15 #[async_trait::async_trait(?Send)]
16 impl Perform for MarkPersonMentionAsRead {
17 type Response = PersonMentionResponse;
19 #[tracing::instrument(skip(context, _websocket_id))]
22 context: &Data<LemmyContext>,
23 _websocket_id: Option<ConnectionId>,
24 ) -> Result<PersonMentionResponse, LemmyError> {
25 let data: &MarkPersonMentionAsRead = self;
27 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
29 let person_mention_id = data.person_mention_id;
30 let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
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;
37 let read = Some(data.read);
38 PersonMention::update(
41 &PersonMentionUpdateForm { read },
44 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
46 let person_mention_id = read_person_mention.id;
47 let person_id = local_user_view.person.id;
48 let person_mention_view =
49 PersonMentionView::read(context.pool(), person_mention_id, Some(person_id)).await?;
51 Ok(PersonMentionResponse {