2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{MarkPersonMentionAsRead, PersonMentionResponse},
6 utils::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, LemmyErrorExt, LemmyErrorType};
15 #[async_trait::async_trait(?Send)]
16 impl Perform for MarkPersonMentionAsRead {
17 type Response = PersonMentionResponse;
19 #[tracing::instrument(skip(context))]
22 context: &Data<LemmyContext>,
23 ) -> Result<PersonMentionResponse, LemmyError> {
24 let data: &MarkPersonMentionAsRead = self;
25 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
27 let person_mention_id = data.person_mention_id;
28 let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;
30 if local_user_view.person.id != read_person_mention.recipient_id {
31 return Err(LemmyErrorType::CouldntUpdateComment)?;
34 let person_mention_id = read_person_mention.id;
35 let read = Some(data.read);
36 PersonMention::update(
39 &PersonMentionUpdateForm { read },
42 .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
44 let person_mention_id = read_person_mention.id;
45 let person_id = local_user_view.person.id;
46 let person_mention_view =
47 PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id)).await?;
49 Ok(PersonMentionResponse {