4 private_message::delete::DeletePrivateMessage,
8 activity_queue::send_activity_new,
9 extensions::context::lemmy_context,
12 use activitystreams::{
13 activity::kind::UndoType,
15 primitives::OneOrMany,
18 use lemmy_api_common::blocking;
19 use lemmy_apub_lib::{verify_domains_match, verify_urls_match, ActivityFields, ActivityHandler};
20 use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
21 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
22 use lemmy_utils::LemmyError;
23 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
24 use serde::{Deserialize, Serialize};
27 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
28 #[serde(rename_all = "camelCase")]
29 pub struct UndoDeletePrivateMessage {
32 object: DeletePrivateMessage,
33 #[serde(rename = "type")]
36 #[serde(rename = "@context")]
37 context: OneOrMany<AnyBase>,
42 impl UndoDeletePrivateMessage {
46 context: &LemmyContext,
47 ) -> Result<(), LemmyError> {
48 let recipient_id = pm.recipient_id;
50 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
52 let object = DeletePrivateMessage::new(actor, pm)?;
53 let id = generate_activity_id(UndoType::Undo)?;
54 let undo = UndoDeletePrivateMessage {
55 actor: actor.actor_id(),
56 to: recipient.actor_id(),
60 context: lemmy_context(),
61 unparsed: Default::default(),
63 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
64 send_activity_new(context, &undo, &id, actor, inbox, true).await
68 #[async_trait::async_trait(?Send)]
69 impl ActivityHandler for UndoDeletePrivateMessage {
72 context: &LemmyContext,
73 request_counter: &mut i32,
74 ) -> Result<(), LemmyError> {
75 verify_activity(self)?;
76 verify_person(&self.actor, context, request_counter).await?;
77 verify_urls_match(&self.actor, self.object.actor())?;
78 verify_domains_match(&self.actor, &self.object.object)?;
79 self.object.verify(context, request_counter).await?;
85 context: &LemmyContext,
86 _request_counter: &mut i32,
87 ) -> Result<(), LemmyError> {
88 let ap_id = self.object.object.clone();
89 let private_message = blocking(context.pool(), move |conn| {
90 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
94 let deleted_private_message = blocking(context.pool(), move |conn| {
95 PrivateMessage::update_deleted(conn, private_message.id, false)
100 deleted_private_message.id,
101 UserOperationCrud::EditPrivateMessage,