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_api_structs::blocking;
20 use lemmy_db_queries::Crud;
21 use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
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: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
29 let note = self.to_apub(context.pool()).await?;
31 let recipient_id = self.recipient_id;
33 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
35 let mut create = Create::new(
36 creator.actor_id.to_owned().into_inner(),
37 note.into_any_base()?,
41 .set_many_contexts(lemmy_context()?)
42 .set_id(generate_activity_id(CreateType::Create)?)
43 .set_to(recipient.actor_id());
45 send_activity_single_dest(create, creator, recipient.inbox_url.into(), context).await?;
49 /// Send out information about an edited private message, to the followers of the community.
50 async fn send_update(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
51 let note = self.to_apub(context.pool()).await?;
53 let recipient_id = self.recipient_id;
55 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
57 let mut update = Update::new(
58 creator.actor_id.to_owned().into_inner(),
59 note.into_any_base()?,
62 .set_many_contexts(lemmy_context()?)
63 .set_id(generate_activity_id(UpdateType::Update)?)
64 .set_to(recipient.actor_id());
66 send_activity_single_dest(update, creator, recipient.inbox_url.into(), context).await?;
70 async fn send_delete(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
71 let recipient_id = self.recipient_id;
73 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
75 let mut delete = Delete::new(
76 creator.actor_id.to_owned().into_inner(),
77 self.ap_id.to_owned().into_inner(),
80 .set_many_contexts(lemmy_context()?)
81 .set_id(generate_activity_id(DeleteType::Delete)?)
82 .set_to(recipient.actor_id());
84 send_activity_single_dest(delete, creator, recipient.inbox_url.into(), context).await?;
88 async fn send_undo_delete(
91 context: &LemmyContext,
92 ) -> Result<(), LemmyError> {
93 let recipient_id = self.recipient_id;
95 blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
97 let mut delete = Delete::new(
98 creator.actor_id.to_owned().into_inner(),
99 self.ap_id.to_owned().into_inner(),
102 .set_many_contexts(lemmy_context()?)
103 .set_id(generate_activity_id(DeleteType::Delete)?)
104 .set_to(recipient.actor_id());
106 // Undo that fake activity
107 let mut undo = Undo::new(
108 creator.actor_id.to_owned().into_inner(),
109 delete.into_any_base()?,
112 .set_many_contexts(lemmy_context()?)
113 .set_id(generate_activity_id(UndoType::Undo)?)
114 .set_to(recipient.actor_id());
116 send_activity_single_dest(undo, creator, recipient.inbox_url.into(), context).await?;
120 async fn send_remove(&self, _mod_: &Person, _context: &LemmyContext) -> Result<(), LemmyError> {
124 async fn send_undo_remove(
127 _context: &LemmyContext,
128 ) -> Result<(), LemmyError> {