]> Untitled Git - lemmy.git/blob - crates/api/src/local_user/notifications/list_replies.rs
6d1d8f0bd3ea871b1b11cc68362e6f9986d59555
[lemmy.git] / crates / api / src / local_user / notifications / list_replies.rs
1 use crate::Perform;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4   context::LemmyContext,
5   person::{GetReplies, GetRepliesResponse},
6   utils::local_user_view_from_jwt,
7 };
8 use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
9 use lemmy_utils::error::LemmyError;
10
11 #[async_trait::async_trait(?Send)]
12 impl Perform for GetReplies {
13   type Response = GetRepliesResponse;
14
15   #[tracing::instrument(skip(context))]
16   async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
17     let data: &GetReplies = self;
18     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
19
20     let sort = data.sort;
21     let page = data.page;
22     let limit = data.limit;
23     let unread_only = data.unread_only;
24     let person_id = Some(local_user_view.person.id);
25     let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
26
27     let replies = CommentReplyQuery::builder()
28       .pool(context.pool())
29       .recipient_id(person_id)
30       .my_person_id(person_id)
31       .sort(sort)
32       .unread_only(unread_only)
33       .show_bot_accounts(show_bot_accounts)
34       .page(page)
35       .limit(limit)
36       .build()
37       .list()
38       .await?;
39
40     Ok(GetRepliesResponse { replies })
41   }
42 }