4 private_message::send_websocket_message,
8 activity_queue::send_activity_new,
9 extensions::context::lemmy_context,
12 use activitystreams::activity::kind::DeleteType;
13 use lemmy_api_common::blocking;
14 use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, 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::{LemmyContext, UserOperationCrud};
21 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
22 #[serde(rename_all = "camelCase")]
23 pub struct DeletePrivateMessage {
24 pub(in crate::activities::private_message) to: Url,
25 pub(in crate::activities::private_message) object: Url,
26 #[serde(rename = "type")]
27 pub(in crate::activities::private_message) kind: DeleteType,
29 pub(in crate::activities::private_message) common: ActivityCommonFields,
32 impl DeletePrivateMessage {
36 context: &LemmyContext,
37 ) -> Result<(), LemmyError> {
38 let recipient_id = pm.recipient_id;
40 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
42 let id = generate_activity_id(DeleteType::Delete)?;
43 let delete = DeletePrivateMessage {
45 object: pm.ap_id.clone().into(),
46 kind: DeleteType::Delete,
47 common: ActivityCommonFields {
48 context: lemmy_context(),
50 actor: actor.actor_id(),
51 unparsed: Default::default(),
54 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
55 send_activity_new(context, &delete, &id, actor, inbox, true).await
59 #[async_trait::async_trait(?Send)]
60 impl ActivityHandler for DeletePrivateMessage {
63 context: &LemmyContext,
64 request_counter: &mut i32,
65 ) -> Result<(), LemmyError> {
66 verify_activity(self.common())?;
67 verify_person(&self.common.actor, context, request_counter).await?;
68 verify_domains_match(&self.common.actor, &self.object)?;
74 context: &LemmyContext,
75 _request_counter: &mut i32,
76 ) -> Result<(), LemmyError> {
77 let ap_id = self.object.clone();
78 let private_message = blocking(context.pool(), move |conn| {
79 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
82 let deleted_private_message = blocking(context.pool(), move |conn| {
83 PrivateMessage::update_deleted(conn, private_message.id, true)
87 send_websocket_message(
88 deleted_private_message.id,
89 UserOperationCrud::DeletePrivateMessage,
97 fn common(&self) -> &ActivityCommonFields {