]> Untitled Git - lemmy.git/blob - crates/apub/src/activities/create_or_update/mod.rs
Check user accepted before sending jwt in password reset (fixes #2591) (#2597)
[lemmy.git] / crates / apub / src / activities / create_or_update / mod.rs
1 use crate::{local_instance, objects::person::ApubPerson};
2 use activitypub_federation::core::object_id::ObjectId;
3 use lemmy_db_schema::{
4   newtypes::LocalUserId,
5   source::{comment::Comment, post::Post},
6   traits::Crud,
7 };
8 use lemmy_utils::{error::LemmyError, utils::scrape_text_for_mentions};
9 use lemmy_websocket::{send::send_local_notifs, LemmyContext};
10
11 pub mod comment;
12 pub mod post;
13 pub mod private_message;
14
15 #[tracing::instrument(skip_all)]
16 async fn get_comment_notif_recipients(
17   actor: &ObjectId<ApubPerson>,
18   comment: &Comment,
19   do_send_email: bool,
20   context: &LemmyContext,
21   request_counter: &mut i32,
22 ) -> Result<Vec<LocalUserId>, LemmyError> {
23   let post_id = comment.post_id;
24   let post = Post::read(context.pool(), post_id).await?;
25   let actor = actor
26     .dereference(context, local_instance(context).await, request_counter)
27     .await?;
28
29   // Note:
30   // Although mentions could be gotten from the post tags (they are included there), or the ccs,
31   // Its much easier to scrape them from the comment body, since the API has to do that
32   // anyway.
33   // TODO: for compatibility with other projects, it would be much better to read this from cc or tags
34   let mentions = scrape_text_for_mentions(&comment.content);
35   send_local_notifs(mentions, comment, &actor, &post, do_send_email, context).await
36 }