]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/comment/mod.rs
Create and Note always need to tag parent creator, for mastodon notifications
[lemmy.git] / crates / apub / src / activities / comment / mod.rs
index 292d57bf404d10d0108089044e14f59b67cc4ce6..b425385877fcbe9808fc2623cb87b38b674b946c 100644 (file)
@@ -1,28 +1,25 @@
-use crate::fetcher::person::get_or_fetch_and_upsert_person;
-use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs};
-use lemmy_db_queries::Crud;
+use crate::objects::person::ApubPerson;
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::object_id::ObjectId;
 use lemmy_db_schema::{
+  newtypes::LocalUserId,
   source::{comment::Comment, post::Post},
-  CommentId,
-  LocalUserId,
+  traits::Crud,
 };
-use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{utils::scrape_text_for_mentions, LemmyError};
-use lemmy_websocket::{messages::SendComment, LemmyContext};
-use url::Url;
+use lemmy_websocket::{send::send_local_notifs, LemmyContext};
 
-pub mod create;
-pub mod update;
+pub mod create_or_update;
 
 async fn get_notif_recipients(
-  actor: &Url,
+  actor: &ObjectId<ApubPerson>,
   comment: &Comment,
   context: &LemmyContext,
   request_counter: &mut i32,
 ) -> Result<Vec<LocalUserId>, LemmyError> {
   let post_id = comment.post_id;
   let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
-  let actor = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
+  let actor = actor.dereference(context, request_counter).await?;
 
   // Note:
   // Although mentions could be gotten from the post tags (they are included there), or the ccs,
@@ -30,36 +27,5 @@ async fn get_notif_recipients(
   // anyway.
   // TODO: for compatibility with other projects, it would be much better to read this from cc or tags
   let mentions = scrape_text_for_mentions(&comment.content);
-  send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await
-}
-
-// TODO: in many call sites we are setting an empty vec for recipient_ids, we should get the actual
-//       recipient actors from somewhere
-pub(crate) async fn send_websocket_message<
-  OP: ToString + Send + lemmy_websocket::OperationType + 'static,
->(
-  comment_id: CommentId,
-  recipient_ids: Vec<LocalUserId>,
-  op: OP,
-  context: &LemmyContext,
-) -> Result<(), LemmyError> {
-  // Refetch the view
-  let comment_view = blocking(context.pool(), move |conn| {
-    CommentView::read(conn, comment_id, None)
-  })
-  .await??;
-
-  let res = CommentResponse {
-    comment_view,
-    recipient_ids,
-    form_id: None,
-  };
-
-  context.chat_server().do_send(SendComment {
-    op,
-    comment: res,
-    websocket_id: None,
-  });
-
-  Ok(())
+  send_local_notifs(mentions, comment, &*actor, &post, true, context).await
 }