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(),
41 pm: &ApubPrivateMessage,
42 context: &LemmyContext,
43 ) -> Result<(), LemmyError> {
44 let delete = DeletePrivateMessage::new(actor, pm, context)?;
45 let delete_id = delete.id.clone();
47 let recipient_id = pm.recipient_id;
48 let recipient: ApubPerson =
49 blocking(context.pool(), move |conn| Person::read(conn, recipient_id))
52 let inbox = vec![recipient.shared_inbox_or_inbox_url()];
53 send_lemmy_activity(context, &delete, &delete_id, actor, inbox, true).await
57 #[async_trait::async_trait(?Send)]
58 impl ActivityHandler for DeletePrivateMessage {
59 type DataType = LemmyContext;
62 context: &Data<LemmyContext>,
63 request_counter: &mut i32,
64 ) -> Result<(), LemmyError> {
65 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
66 verify_person(&self.actor, context, request_counter).await?;
67 verify_domains_match(self.actor.inner(), self.object.inner())?;
73 context: &Data<LemmyContext>,
74 _request_counter: &mut i32,
75 ) -> Result<(), LemmyError> {
76 let private_message = self.object.dereference_local(context).await?;
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,