2 activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
3 objects::{person::ApubPerson, private_message::ApubPrivateMessage},
4 protocol::activities::private_message::{
5 delete::DeletePrivateMessage,
6 undo_delete::UndoDeletePrivateMessage,
9 use activitystreams_kinds::activity::UndoType;
10 use lemmy_api_common::blocking;
14 traits::{ActivityHandler, ActorType},
15 verify::{verify_domains_match, verify_urls_match},
17 use lemmy_db_schema::{
18 source::{person::Person, private_message::PrivateMessage},
21 use lemmy_utils::LemmyError;
22 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
24 impl UndoDeletePrivateMessage {
27 pm: &ApubPrivateMessage,
28 context: &LemmyContext,
29 ) -> Result<(), LemmyError> {
30 let recipient_id = pm.recipient_id;
31 let recipient: ApubPerson =
32 blocking(context.pool(), move |conn| Person::read(conn, recipient_id))
36 let object = DeletePrivateMessage::new(actor, pm, context)?;
37 let id = generate_activity_id(
39 &context.settings().get_protocol_and_hostname(),
41 let undo = UndoDeletePrivateMessage {
42 actor: ObjectId::new(actor.actor_id()),
43 to: [ObjectId::new(recipient.actor_id())],
47 unparsed: Default::default(),
49 let inbox = vec![recipient.shared_inbox_or_inbox_url()];
50 send_lemmy_activity(context, &undo, &id, actor, inbox, true).await
54 #[async_trait::async_trait(?Send)]
55 impl ActivityHandler for UndoDeletePrivateMessage {
56 type DataType = LemmyContext;
59 context: &Data<LemmyContext>,
60 request_counter: &mut i32,
61 ) -> Result<(), LemmyError> {
62 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
63 verify_person(&self.actor, context, request_counter).await?;
64 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
65 verify_domains_match(self.actor.inner(), self.object.object.inner())?;
66 self.object.verify(context, request_counter).await?;
72 context: &Data<LemmyContext>,
73 _request_counter: &mut i32,
74 ) -> Result<(), LemmyError> {
75 let ap_id = self.object.object.clone();
76 let private_message = ap_id.dereference_local(context).await?;
78 let deleted_private_message = blocking(context.pool(), move |conn| {
79 PrivateMessage::update_deleted(conn, private_message.id, false)
84 deleted_private_message.id,
85 UserOperationCrud::EditPrivateMessage,