2 activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
3 objects::{person::ApubPerson, private_message::ApubPrivateMessage},
4 protocol::activities::private_message::delete::DeletePrivateMessage,
6 use activitystreams_kinds::activity::DeleteType;
7 use lemmy_api_common::blocking;
11 traits::{ActivityHandler, ActorType},
12 verify::verify_domains_match,
14 use lemmy_db_schema::{
15 source::{person::Person, private_message::PrivateMessage},
18 use lemmy_utils::LemmyError;
19 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
21 impl DeletePrivateMessage {
22 pub(in crate::activities::private_message) fn new(
25 context: &LemmyContext,
26 ) -> Result<DeletePrivateMessage, LemmyError> {
27 Ok(DeletePrivateMessage {
28 actor: ObjectId::new(actor.actor_id()),
29 to: [ObjectId::new(actor.actor_id())],
30 object: ObjectId::new(pm.ap_id.clone()),
31 kind: DeleteType::Delete,
32 id: generate_activity_id(
34 &context.settings().get_protocol_and_hostname(),
36 unparsed: Default::default(),
40 #[tracing::instrument(skip_all)]
43 pm: &ApubPrivateMessage,
44 context: &LemmyContext,
45 ) -> Result<(), LemmyError> {
46 let delete = DeletePrivateMessage::new(actor, pm, context)?;
47 let delete_id = delete.id.clone();
49 let recipient_id = pm.recipient_id;
50 let recipient: ApubPerson =
51 blocking(context.pool(), move |conn| Person::read(conn, recipient_id))
54 let inbox = vec![recipient.shared_inbox_or_inbox_url()];
55 send_lemmy_activity(context, &delete, &delete_id, actor, inbox, true).await
59 #[async_trait::async_trait(?Send)]
60 impl ActivityHandler for DeletePrivateMessage {
61 type DataType = LemmyContext;
63 #[tracing::instrument(skip_all)]
66 context: &Data<LemmyContext>,
67 request_counter: &mut i32,
68 ) -> Result<(), LemmyError> {
69 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
70 verify_person(&self.actor, context, request_counter).await?;
71 verify_domains_match(self.actor.inner(), self.object.inner())?;
75 #[tracing::instrument(skip_all)]
78 context: &Data<LemmyContext>,
79 _request_counter: &mut i32,
80 ) -> Result<(), LemmyError> {
81 let private_message = self.object.dereference_local(context).await?;
82 let deleted_private_message = blocking(context.pool(), move |conn| {
83 PrivateMessage::update_deleted(conn, private_message.id, true)
88 deleted_private_message.id,
89 UserOperationCrud::DeletePrivateMessage,