1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 private_message::{DeletePrivateMessage, PrivateMessageResponse},
6 utils::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;
26 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
28 // Checking permissions
29 let private_message_id = data.private_message_id;
30 let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
31 if local_user_view.person.id != orig_private_message.creator_id {
32 return Err(LemmyError::from_message("no_private_message_edit_allowed"));
36 let private_message_id = data.private_message_id;
37 let deleted = data.deleted;
38 PrivateMessage::update(
41 &PrivateMessageUpdateForm::builder()
42 .deleted(Some(deleted))
46 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
50 &UserOperationCrud::DeletePrivateMessage,
51 data.private_message_id,