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;
26 #[async_trait::async_trait(?Send)]
27 impl ApubObjectType for PrivateMessage {
28 /// Send out information about a newly created private message
29 async fn send_create(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
30 let note = self.to_apub(context.pool()).await?;
32 let recipient_id = self.recipient_id;
33 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
35 let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
38 .set_many_contexts(lemmy_context()?)
39 .set_id(generate_activity_id(CreateType::Create)?)
40 .set_to(recipient.actor_id()?);
42 send_activity_single_dest(create, creator, recipient.get_inbox_url()?, context).await?;
46 /// Send out information about an edited private message, to the followers of the community.
47 async fn send_update(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
48 let note = self.to_apub(context.pool()).await?;
50 let recipient_id = self.recipient_id;
51 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
53 let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
55 .set_many_contexts(lemmy_context()?)
56 .set_id(generate_activity_id(UpdateType::Update)?)
57 .set_to(recipient.actor_id()?);
59 send_activity_single_dest(update, creator, recipient.get_inbox_url()?, context).await?;
63 async fn send_delete(&self, creator: &User_, context: &LemmyContext) -> Result<(), LemmyError> {
64 let recipient_id = self.recipient_id;
65 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
67 let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
69 .set_many_contexts(lemmy_context()?)
70 .set_id(generate_activity_id(DeleteType::Delete)?)
71 .set_to(recipient.actor_id()?);
73 send_activity_single_dest(delete, creator, recipient.get_inbox_url()?, context).await?;
77 async fn send_undo_delete(
80 context: &LemmyContext,
81 ) -> Result<(), LemmyError> {
82 let recipient_id = self.recipient_id;
83 let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
85 let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
87 .set_many_contexts(lemmy_context()?)
88 .set_id(generate_activity_id(DeleteType::Delete)?)
89 .set_to(recipient.actor_id()?);
91 // Undo that fake activity
92 let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
94 .set_many_contexts(lemmy_context()?)
95 .set_id(generate_activity_id(UndoType::Undo)?)
96 .set_to(recipient.actor_id()?);
98 send_activity_single_dest(undo, creator, recipient.get_inbox_url()?, context).await?;
102 async fn send_remove(&self, _mod_: &User_, _context: &LemmyContext) -> Result<(), LemmyError> {
106 async fn send_undo_remove(
109 _context: &LemmyContext,
110 ) -> Result<(), LemmyError> {