From 2ccb46b66daa560efc52fbea4866cee01676fb55 Mon Sep 17 00:00:00 2001 From: abdel-m Date: Tue, 30 Jul 2024 14:34:58 +0200 Subject: [PATCH] pass local user to send local notifs (#4920) * pass local user to send local notif * pass local user to all crud calls * execution of command "cargo +nightly fmt" * Formatting and mode fixes. --------- Co-authored-by: Dessalines --- crates/api_common/src/build_response.rs | 11 ++++++++--- crates/api_crud/src/comment/create.rs | 1 + crates/api_crud/src/comment/delete.rs | 11 +++++++++-- crates/api_crud/src/comment/remove.rs | 11 +++++++++-- crates/api_crud/src/comment/update.rs | 1 + .../apub/src/activities/create_or_update/comment.rs | 2 +- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index 200284b00..8f140f2fe 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -100,15 +100,20 @@ pub async fn send_local_notifs( person: &Person, do_send_email: bool, context: &LemmyContext, + local_user_view: Option<&LocalUserView>, ) -> LemmyResult> { let mut recipient_ids = Vec::new(); let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname()); // let person = my_local_user.person; // Read the comment view to get extra info - let comment_view = CommentView::read(&mut context.pool(), comment_id, None) - .await? - .ok_or(LemmyErrorType::CouldntFindComment)?; + let comment_view = CommentView::read( + &mut context.pool(), + comment_id, + local_user_view.map(|view| &view.local_user), + ) + .await? + .ok_or(LemmyErrorType::CouldntFindComment)?; let comment = comment_view.comment; let post = comment_view.post; let community = comment_view.community; diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index b7c65740c..49de9d5de 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -134,6 +134,7 @@ pub async fn create_comment( &local_user_view.person, true, &context, + Some(&local_user_view), ) .await?; diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index 29706d365..8c81608c8 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -59,8 +59,15 @@ pub async fn delete_comment( .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; - let recipient_ids = - send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?; + let recipient_ids = send_local_notifs( + vec![], + comment_id, + &local_user_view.person, + false, + &context, + Some(&local_user_view), + ) + .await?; let updated_comment_id = updated_comment.id; ActivityChannel::submit_activity( diff --git a/crates/api_crud/src/comment/remove.rs b/crates/api_crud/src/comment/remove.rs index f810c8275..ec4923e93 100644 --- a/crates/api_crud/src/comment/remove.rs +++ b/crates/api_crud/src/comment/remove.rs @@ -81,8 +81,15 @@ pub async fn remove_comment( }; ModRemoveComment::create(&mut context.pool(), &form).await?; - let recipient_ids = - send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?; + let recipient_ids = send_local_notifs( + vec![], + comment_id, + &local_user_view.person, + false, + &context, + Some(&local_user_view), + ) + .await?; let updated_comment_id = updated_comment.id; ActivityChannel::submit_activity( diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 32bd08240..ed9460825 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -91,6 +91,7 @@ pub async fn update_comment( &local_user_view.person, false, &context, + Some(&local_user_view), ) .await?; diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index 2406d2eb3..89be8d49e 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -179,7 +179,7 @@ impl ActivityHandler for CreateOrUpdateNote { // 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.id, &actor, do_send_email, context).await?; + send_local_notifs(mentions, comment.id, &actor, do_send_email, context, None).await?; Ok(()) } }