2 activities::send::generate_activity_id,
3 activity_queue::send_activity_single_dest,
4 extensions::context::lemmy_context,
11 kind::{CreateType, DeleteType, UndoType, UpdateType},
19 use lemmy_db_queries::Crud;
20 use lemmy_db_schema::source::{private_message::PrivateMessage, user::User_};
21 use lemmy_structs::blocking;
22 use lemmy_utils::LemmyError;
23 use lemmy_websocket::LemmyContext;
25 #[async_trait::async_trait(?Send)]
26 impl ApubObjectType for PrivateMessage {
27 /// Send out information about a newly created private message
28 async fn send_create(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
29 let note = self.to_apub(context.pool()).await?;
31 let recipient_id = self.recipient_id;
32 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
34 let mut create = Create::new(
35 creator.actor_id.to_owned().into_inner(),
36 note.into_any_base()?,
40 .set_many_contexts(lemmy_context()?)
41 .set_id(generate_activity_id(CreateType::Create)?)
42 .set_to(recipient.actor_id());
44 send_activity_single_dest(create, creator, recipient.get_inbox_url()?, context).await?;
48 /// Send out information about an edited private message, to the followers of the community.
49 async fn send_update(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
50 let note = self.to_apub(context.pool()).await?;
52 let recipient_id = self.recipient_id;
53 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
55 let mut update = Update::new(
56 creator.actor_id.to_owned().into_inner(),
57 note.into_any_base()?,
60 .set_many_contexts(lemmy_context()?)
61 .set_id(generate_activity_id(UpdateType::Update)?)
62 .set_to(recipient.actor_id());
64 send_activity_single_dest(update, creator, recipient.get_inbox_url()?, context).await?;
68 async fn send_delete(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
69 let recipient_id = self.recipient_id;
70 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
72 let mut delete = Delete::new(
73 creator.actor_id.to_owned().into_inner(),
74 self.ap_id.to_owned().into_inner(),
77 .set_many_contexts(lemmy_context()?)
78 .set_id(generate_activity_id(DeleteType::Delete)?)
79 .set_to(recipient.actor_id());
81 send_activity_single_dest(delete, creator, recipient.get_inbox_url()?, context).await?;
85 async fn send_undo_delete(
88 context: &LemmyContext,
89 ) -> Result<(), LemmyError> {
90 let recipient_id = self.recipient_id;
91 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
93 let mut delete = Delete::new(
94 creator.actor_id.to_owned().into_inner(),
95 self.ap_id.to_owned().into_inner(),
98 .set_many_contexts(lemmy_context()?)
99 .set_id(generate_activity_id(DeleteType::Delete)?)
100 .set_to(recipient.actor_id());
102 // Undo that fake activity
103 let mut undo = Undo::new(
104 creator.actor_id.to_owned().into_inner(),
105 delete.into_any_base()?,
108 .set_many_contexts(lemmy_context()?)
109 .set_id(generate_activity_id(UndoType::Undo)?)
110 .set_to(recipient.actor_id());
112 send_activity_single_dest(undo, creator, recipient.get_inbox_url()?, context).await?;
116 async fn send_remove(&self, _mod_: &User_, _context: &LemmyContext) -> Result<(), LemmyError> {
120 async fn send_undo_remove(
123 _context: &LemmyContext,
124 ) -> Result<(), LemmyError> {