mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 00:43:59 +00:00
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
|
use crate::PerformCrud;
|
||
|
use actix_web::web::Data;
|
||
|
use lemmy_api_common::{
|
||
|
blocking,
|
||
|
get_local_user_view_from_jwt,
|
||
|
person::{GetPrivateMessages, PrivateMessagesResponse},
|
||
|
};
|
||
|
use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
|
||
|
use lemmy_utils::{ConnectionId, LemmyError};
|
||
|
use lemmy_websocket::LemmyContext;
|
||
|
|
||
|
#[async_trait::async_trait(?Send)]
|
||
|
impl PerformCrud for GetPrivateMessages {
|
||
|
type Response = PrivateMessagesResponse;
|
||
|
|
||
|
async fn perform(
|
||
|
&self,
|
||
|
context: &Data<LemmyContext>,
|
||
|
_websocket_id: Option<ConnectionId>,
|
||
|
) -> Result<PrivateMessagesResponse, LemmyError> {
|
||
|
let data: &GetPrivateMessages = &self;
|
||
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||
|
let person_id = local_user_view.person.id;
|
||
|
|
||
|
let page = data.page;
|
||
|
let limit = data.limit;
|
||
|
let unread_only = data.unread_only;
|
||
|
let messages = blocking(context.pool(), move |conn| {
|
||
|
PrivateMessageQueryBuilder::create(&conn, person_id)
|
||
|
.page(page)
|
||
|
.limit(limit)
|
||
|
.unread_only(unread_only)
|
||
|
.list()
|
||
|
})
|
||
|
.await??;
|
||
|
|
||
|
Ok(PrivateMessagesResponse {
|
||
|
private_messages: messages,
|
||
|
})
|
||
|
}
|
||
|
}
|