2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{GetPersonMentions, GetPersonMentionsResponse},
5 utils::{blocking, get_local_user_view_from_jwt},
7 use lemmy_db_views_actor::person_mention_view::PersonMentionQueryBuilder;
8 use lemmy_utils::{error::LemmyError, ConnectionId};
9 use lemmy_websocket::LemmyContext;
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetPersonMentions {
13 type Response = GetPersonMentionsResponse;
15 #[tracing::instrument(skip(context, _websocket_id))]
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<GetPersonMentionsResponse, LemmyError> {
21 let data: &GetPersonMentions = self;
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
27 let limit = data.limit;
28 let unread_only = data.unread_only;
29 let person_id = local_user_view.person.id;
30 let mentions = blocking(context.pool(), move |conn| {
31 PersonMentionQueryBuilder::create(conn)
32 .recipient_id(person_id)
33 .my_person_id(person_id)
35 .unread_only(unread_only)
42 Ok(GetPersonMentionsResponse { mentions })