2 activities::{generate_activity_id, verify_activity, verify_person},
3 activity_queue::send_activity_new,
4 extensions::context::lemmy_context,
8 activity::kind::DeleteType,
10 primitives::OneOrMany,
13 use lemmy_api_common::blocking;
14 use lemmy_apub_lib::{verify_domains_match, ActivityFields, ActivityHandler};
15 use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
16 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
17 use lemmy_utils::LemmyError;
18 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
19 use serde::{Deserialize, Serialize};
22 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
23 #[serde(rename_all = "camelCase")]
24 pub struct DeletePrivateMessage {
27 pub(in crate::activities::private_message) object: Url,
28 #[serde(rename = "type")]
31 #[serde(rename = "@context")]
32 context: OneOrMany<AnyBase>,
37 impl DeletePrivateMessage {
38 pub(in crate::activities::private_message) fn new(
41 ) -> Result<DeletePrivateMessage, LemmyError> {
42 Ok(DeletePrivateMessage {
43 actor: actor.actor_id(),
45 object: pm.ap_id.clone().into(),
46 kind: DeleteType::Delete,
47 id: generate_activity_id(DeleteType::Delete)?,
48 context: lemmy_context(),
49 unparsed: Default::default(),
55 context: &LemmyContext,
56 ) -> Result<(), LemmyError> {
57 let delete = DeletePrivateMessage::new(actor, pm)?;
58 let delete_id = delete.id.clone();
60 let recipient_id = pm.recipient_id;
62 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
63 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
64 send_activity_new(context, &delete, &delete_id, actor, inbox, true).await
68 #[async_trait::async_trait(?Send)]
69 impl ActivityHandler for DeletePrivateMessage {
72 context: &LemmyContext,
73 request_counter: &mut i32,
74 ) -> Result<(), LemmyError> {
75 verify_activity(self)?;
76 verify_person(&self.actor, context, request_counter).await?;
77 verify_domains_match(&self.actor, &self.object)?;
83 context: &LemmyContext,
84 _request_counter: &mut i32,
85 ) -> Result<(), LemmyError> {
86 let ap_id = self.object.clone();
87 let private_message = blocking(context.pool(), move |conn| {
88 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
91 let deleted_private_message = blocking(context.pool(), move |conn| {
92 PrivateMessage::update_deleted(conn, private_message.id, true)
97 deleted_private_message.id,
98 UserOperationCrud::DeletePrivateMessage,