4 private_message::{delete::DeletePrivateMessage, send_websocket_message},
8 activity_queue::send_activity_new,
9 extensions::context::lemmy_context,
12 use activitystreams::activity::kind::{DeleteType, UndoType};
13 use lemmy_api_common::blocking;
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::{LemmyContext, UserOperationCrud};
26 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
27 #[serde(rename_all = "camelCase")]
28 pub struct UndoDeletePrivateMessage {
30 object: DeletePrivateMessage,
31 #[serde(rename = "type")]
34 common: ActivityCommonFields,
37 impl UndoDeletePrivateMessage {
41 context: &LemmyContext,
42 ) -> Result<(), LemmyError> {
43 let recipient_id = pm.recipient_id;
45 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
47 let object = DeletePrivateMessage {
48 to: recipient.actor_id(),
49 object: pm.ap_id.clone().into(),
50 kind: DeleteType::Delete,
51 common: ActivityCommonFields {
52 context: lemmy_context(),
53 id: generate_activity_id(DeleteType::Delete)?,
54 actor: actor.actor_id(),
55 unparsed: Default::default(),
59 let id = generate_activity_id(UndoType::Undo)?;
60 let undo = UndoDeletePrivateMessage {
61 to: recipient.actor_id(),
64 common: ActivityCommonFields {
65 context: lemmy_context(),
67 actor: actor.actor_id(),
68 unparsed: Default::default(),
71 let inbox = vec![recipient.get_shared_inbox_or_inbox_url()];
72 send_activity_new(context, &undo, &id, actor, inbox, true).await
76 #[async_trait::async_trait(?Send)]
77 impl ActivityHandler for UndoDeletePrivateMessage {
80 context: &LemmyContext,
81 request_counter: &mut i32,
82 ) -> Result<(), LemmyError> {
83 verify_activity(self.common())?;
84 verify_person(&self.common.actor, context, request_counter).await?;
85 verify_urls_match(&self.common.actor, &self.object.common.actor)?;
86 verify_domains_match(&self.common.actor, &self.object.object)?;
87 self.object.verify(context, request_counter).await?;
93 context: &LemmyContext,
94 _request_counter: &mut i32,
95 ) -> Result<(), LemmyError> {
96 let ap_id = self.object.object.clone();
97 let private_message = blocking(context.pool(), move |conn| {
98 PrivateMessage::read_from_apub_id(conn, &ap_id.into())
102 let deleted_private_message = blocking(context.pool(), move |conn| {
103 PrivateMessage::update_deleted(conn, private_message.id, false)
107 send_websocket_message(
108 deleted_private_message.id,
109 UserOperationCrud::EditPrivateMessage,
117 fn common(&self) -> &ActivityCommonFields {