]> Untitled Git - lemmy.git/blob - crates/api/src/local_user/notifications/list_replies.rs
Replace Option<bool> with bool for PostQuery and CommentQuery (#3819) (#3857)
[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.unwrap_or_default();
24     let person_id = Some(local_user_view.person.id);
25     let show_bot_accounts = local_user_view.local_user.show_bot_accounts;
26
27     let replies = CommentReplyQuery {
28       recipient_id: person_id,
29       my_person_id: person_id,
30       sort,
31       unread_only,
32       show_bot_accounts,
33       page,
34       limit,
35     }
36     .list(&mut context.pool())
37     .await?;
38
39     Ok(GetRepliesResponse { replies })
40   }
41 }