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