2 activities::{generate_activity_id, verify_activity, verify_person},
3 activity_queue::send_activity_new,
4 extensions::context::lemmy_context,
7 use activitystreams::activity::kind::DeleteType;
8 use lemmy_api_common::blocking;
9 use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler};
10 use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
11 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
12 use lemmy_utils::LemmyError;
13 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
16 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
17 #[serde(rename_all = "camelCase")]
18 pub struct DeletePrivateMessage {
19 pub(in crate::activities::private_message) to: Url,
20 pub(in crate::activities::private_message) object: Url,
21 #[serde(rename = "type")]
22 pub(in crate::activities::private_message) kind: DeleteType,
24 pub(in crate::activities::private_message) common: ActivityCommonFields,
27 impl DeletePrivateMessage {
31 context: &LemmyContext,
32 ) -> Result<(), LemmyError> {
33 let recipient_id = pm.recipient_id;
35 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
37 let id = generate_activity_id(DeleteType::Delete)?;
38 let delete = DeletePrivateMessage {
40 object: pm.ap_id.clone().into(),
41 kind: DeleteType::Delete,
42 common: ActivityCommonFields {
43 context: lemmy_context(),
45 actor: actor.actor_id(),
46 unparsed: Default::default(),
49 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
50 send_activity_new(context, &delete, &id, actor, inbox, true).await
54 #[async_trait::async_trait(?Send)]
55 impl ActivityHandler for DeletePrivateMessage {
58 context: &LemmyContext,
59 request_counter: &mut i32,
60 ) -> Result<(), LemmyError> {
61 verify_activity(self.common())?;
62 verify_person(&self.common.actor, context, request_counter).await?;
63 verify_domains_match(&self.common.actor, &self.object)?;
69 context: &LemmyContext,
70 _request_counter: &mut i32,
71 ) -> Result<(), LemmyError> {
72 let ap_id = self.object.clone();
73 let private_message = blocking(context.pool(), move |conn| {
74 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
77 let deleted_private_message = blocking(context.pool(), move |conn| {
78 PrivateMessage::update_deleted(conn, private_message.id, true)
83 deleted_private_message.id,
84 UserOperationCrud::DeletePrivateMessage,
93 fn common(&self) -> &ActivityCommonFields {