From 27a687bcd0b2cd362d02f0fb10a16c80a6a6aa55 Mon Sep 17 00:00:00 2001
From: Felix Ableitner <me@nutomic.com>
Date: Wed, 24 Nov 2021 22:26:23 +0100
Subject: [PATCH] Dont send email notifications for edited comments (fixes
 #1925)

---
 crates/apub/src/activities/comment/create_or_update.rs | 10 +++++++++-
 crates/apub/src/activities/comment/mod.rs              |  3 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs
index 14fc1401..649f566c 100644
--- a/crates/apub/src/activities/comment/create_or_update.rs
+++ b/crates/apub/src/activities/comment/create_or_update.rs
@@ -108,7 +108,15 @@ impl ActivityHandler for CreateOrUpdateComment {
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
     let comment = ApubComment::from_apub(self.object, context, request_counter).await?;
-    let recipients = get_notif_recipients(&self.actor, &comment, context, request_counter).await?;
+    let do_send_email = self.kind == CreateOrUpdateType::Create;
+    let recipients = get_notif_recipients(
+      &self.actor,
+      &comment,
+      do_send_email,
+      context,
+      request_counter,
+    )
+    .await?;
     let notif_type = match self.kind {
       CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
       CreateOrUpdateType::Update => UserOperationCrud::EditComment,
diff --git a/crates/apub/src/activities/comment/mod.rs b/crates/apub/src/activities/comment/mod.rs
index b4253858..17b4f50c 100644
--- a/crates/apub/src/activities/comment/mod.rs
+++ b/crates/apub/src/activities/comment/mod.rs
@@ -14,6 +14,7 @@ pub mod create_or_update;
 async fn get_notif_recipients(
   actor: &ObjectId<ApubPerson>,
   comment: &Comment,
+  do_send_email: bool,
   context: &LemmyContext,
   request_counter: &mut i32,
 ) -> Result<Vec<LocalUserId>, LemmyError> {
@@ -27,5 +28,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, &*actor, &post, true, context).await
+  send_local_notifs(mentions, comment, &*actor, &post, do_send_email, context).await
 }
-- 
2.44.1