1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 get_local_user_view_from_jwt,
6 person::{GetPrivateMessages, PrivateMessagesResponse},
8 use lemmy_db_schema::traits::DeleteableOrRemoveable;
9 use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
10 use lemmy_utils::{ConnectionId, LemmyError};
11 use lemmy_websocket::LemmyContext;
13 #[async_trait::async_trait(?Send)]
14 impl PerformCrud for GetPrivateMessages {
15 type Response = PrivateMessagesResponse;
17 #[tracing::instrument(skip(self, context, _websocket_id))]
20 context: &Data<LemmyContext>,
21 _websocket_id: Option<ConnectionId>,
22 ) -> Result<PrivateMessagesResponse, LemmyError> {
23 let data: &GetPrivateMessages = self;
25 get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
26 let person_id = local_user_view.person.id;
29 let limit = data.limit;
30 let unread_only = data.unread_only;
31 let mut messages = blocking(context.pool(), move |conn| {
32 PrivateMessageQueryBuilder::create(conn, person_id)
35 .unread_only(unread_only)
40 // Blank out deleted or removed info
43 .filter(|pmv| pmv.private_message.deleted)
45 pmv.private_message = pmv
48 .blank_out_deleted_or_removed_info();
51 Ok(PrivateMessagesResponse {
52 private_messages: messages,