1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 private_message::{DeletePrivateMessage, PrivateMessageResponse},
6 utils::get_local_user_view_from_jwt,
7 websocket::UserOperationCrud,
10 source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
13 use lemmy_utils::{error::LemmyError, ConnectionId};
15 #[async_trait::async_trait(?Send)]
16 impl PerformCrud for DeletePrivateMessage {
17 type Response = PrivateMessageResponse;
19 #[tracing::instrument(skip(self, context, websocket_id))]
22 context: &Data<LemmyContext>,
23 websocket_id: Option<ConnectionId>,
24 ) -> Result<PrivateMessageResponse, LemmyError> {
25 let data: &DeletePrivateMessage = self;
27 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
29 // Checking permissions
30 let private_message_id = data.private_message_id;
31 let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
32 if local_user_view.person.id != orig_private_message.creator_id {
33 return Err(LemmyError::from_message("no_private_message_edit_allowed"));
37 let private_message_id = data.private_message_id;
38 let deleted = data.deleted;
39 PrivateMessage::update(
42 &PrivateMessageUpdateForm::builder()
43 .deleted(Some(deleted))
47 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
51 &UserOperationCrud::DeletePrivateMessage,
52 data.private_message_id,