]> Untitled Git - lemmy.git/blob - crates/api/src/local_user/notifications/list_mentions.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / api / src / local_user / notifications / list_mentions.rs
1 use crate::Perform;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4   person::{GetPersonMentions, GetPersonMentionsResponse},
5   utils::{blocking, get_local_user_view_from_jwt},
6 };
7 use lemmy_db_views_actor::person_mention_view::PersonMentionQueryBuilder;
8 use lemmy_utils::{error::LemmyError, ConnectionId};
9 use lemmy_websocket::LemmyContext;
10
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetPersonMentions {
13   type Response = GetPersonMentionsResponse;
14
15   #[tracing::instrument(skip(context, _websocket_id))]
16   async fn perform(
17     &self,
18     context: &Data<LemmyContext>,
19     _websocket_id: Option<ConnectionId>,
20   ) -> Result<GetPersonMentionsResponse, LemmyError> {
21     let data: &GetPersonMentions = self;
22     let local_user_view =
23       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
24
25     let sort = data.sort;
26     let page = data.page;
27     let limit = data.limit;
28     let unread_only = data.unread_only;
29     let person_id = local_user_view.person.id;
30     let show_bot_accounts = local_user_view.local_user.show_bot_accounts;
31
32     let mentions = blocking(context.pool(), move |conn| {
33       PersonMentionQueryBuilder::create(conn)
34         .recipient_id(person_id)
35         .my_person_id(person_id)
36         .sort(sort)
37         .unread_only(unread_only)
38         .show_bot_accounts(show_bot_accounts)
39         .page(page)
40         .limit(limit)
41         .list()
42     })
43     .await??;
44
45     Ok(GetPersonMentionsResponse { mentions })
46   }
47 }