4 private_message::delete::DeletePrivateMessage,
8 activity_queue::send_activity_new,
9 extensions::context::lemmy_context,
10 fetcher::object_id::ObjectId,
13 use activitystreams::{
14 activity::kind::UndoType,
16 primitives::OneOrMany,
19 use lemmy_api_common::blocking;
20 use lemmy_apub_lib::{verify_domains_match, verify_urls_match, ActivityFields, ActivityHandler};
21 use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
22 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
23 use lemmy_utils::LemmyError;
24 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
25 use serde::{Deserialize, Serialize};
28 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
29 #[serde(rename_all = "camelCase")]
30 pub struct UndoDeletePrivateMessage {
31 actor: ObjectId<Person>,
33 object: DeletePrivateMessage,
34 #[serde(rename = "type")]
37 #[serde(rename = "@context")]
38 context: OneOrMany<AnyBase>,
43 impl UndoDeletePrivateMessage {
47 context: &LemmyContext,
48 ) -> Result<(), LemmyError> {
49 let recipient_id = pm.recipient_id;
51 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
53 let object = DeletePrivateMessage::new(actor, pm, context)?;
54 let id = generate_activity_id(
56 &context.settings().get_protocol_and_hostname(),
58 let undo = UndoDeletePrivateMessage {
59 actor: ObjectId::new(actor.actor_id()),
60 to: ObjectId::new(recipient.actor_id()),
64 context: lemmy_context(),
65 unparsed: Default::default(),
67 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
68 send_activity_new(context, &undo, &id, actor, inbox, true).await
72 #[async_trait::async_trait(?Send)]
73 impl ActivityHandler for UndoDeletePrivateMessage {
76 context: &LemmyContext,
77 request_counter: &mut i32,
78 ) -> Result<(), LemmyError> {
79 verify_activity(self, &context.settings())?;
80 verify_person(&self.actor, context, request_counter).await?;
81 verify_urls_match(self.actor(), self.object.actor())?;
82 verify_domains_match(self.actor(), &self.object.object)?;
83 self.object.verify(context, request_counter).await?;
89 context: &LemmyContext,
90 _request_counter: &mut i32,
91 ) -> Result<(), LemmyError> {
92 let ap_id = self.object.object.clone();
93 let private_message = blocking(context.pool(), move |conn| {
94 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
98 let deleted_private_message = blocking(context.pool(), move |conn| {
99 PrivateMessage::update_deleted(conn, private_message.id, false)
104 deleted_private_message.id,
105 UserOperationCrud::EditPrivateMessage,