2 activities::{generate_activity_id, verify_activity, verify_person},
3 activity_queue::send_activity_new,
4 extensions::context::lemmy_context,
5 fetcher::object_id::ObjectId,
9 activity::kind::DeleteType,
11 primitives::OneOrMany,
14 use lemmy_api_common::blocking;
15 use lemmy_apub_lib::{verify_domains_match, ActivityFields, ActivityHandler};
16 use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
17 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
18 use lemmy_utils::LemmyError;
19 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
20 use serde::{Deserialize, Serialize};
23 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
24 #[serde(rename_all = "camelCase")]
25 pub struct DeletePrivateMessage {
26 actor: ObjectId<Person>,
28 pub(in crate::activities::private_message) object: Url,
29 #[serde(rename = "type")]
32 #[serde(rename = "@context")]
33 context: OneOrMany<AnyBase>,
38 impl DeletePrivateMessage {
39 pub(in crate::activities::private_message) fn new(
42 context: &LemmyContext,
43 ) -> Result<DeletePrivateMessage, LemmyError> {
44 Ok(DeletePrivateMessage {
45 actor: ObjectId::new(actor.actor_id()),
46 to: ObjectId::new(actor.actor_id()),
47 object: pm.ap_id.clone().into(),
48 kind: DeleteType::Delete,
49 id: generate_activity_id(
51 &context.settings().get_protocol_and_hostname(),
53 context: lemmy_context(),
54 unparsed: Default::default(),
60 context: &LemmyContext,
61 ) -> Result<(), LemmyError> {
62 let delete = DeletePrivateMessage::new(actor, pm, context)?;
63 let delete_id = delete.id.clone();
65 let recipient_id = pm.recipient_id;
67 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
68 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
69 send_activity_new(context, &delete, &delete_id, actor, inbox, true).await
73 #[async_trait::async_trait(?Send)]
74 impl ActivityHandler for DeletePrivateMessage {
77 context: &LemmyContext,
78 request_counter: &mut i32,
79 ) -> Result<(), LemmyError> {
80 verify_activity(self, &context.settings())?;
81 verify_person(&self.actor, context, request_counter).await?;
82 verify_domains_match(self.actor.inner(), &self.object)?;
88 context: &LemmyContext,
89 _request_counter: &mut i32,
90 ) -> Result<(), LemmyError> {
91 let ap_id = self.object.clone();
92 let private_message = blocking(context.pool(), move |conn| {
93 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
96 let deleted_private_message = blocking(context.pool(), move |conn| {
97 PrivateMessage::update_deleted(conn, private_message.id, true)
102 deleted_private_message.id,
103 UserOperationCrud::DeletePrivateMessage,