Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2018-02-21 05:03:52 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2018-02-22 02:49:21 +0300
commitc89b2ad8096df63d2b3d4a49fde73d258221588b (patch)
tree7535561226425429c2de71074c55884db0cafe40
parentb80eb01f34115a58a65d44b39df51f499a945f41 (diff)
Prevent duplicate mention notifications when the post is received twice
closes #7721
-rw-r--r--Changelog.md1
-rw-r--r--app/models/notifications/mentioned.rb5
-rw-r--r--spec/models/notifications/mentioned_spec.rb12
3 files changed, 17 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 40a66b663..9c9c0daf5 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -5,6 +5,7 @@
* Make script/server work on readonly filesystems [#7719](https://github.com/diaspora/diaspora/pull/7719)
## Bug fixes
+* Prevent duplicate mention notifications when the post is received twice [#7721](https://github.com/diaspora/diaspora/pull/7721)
## Features
* Add basic html5 audio/video embedding support [#6418](https://github.com/diaspora/diaspora/pull/6418)
diff --git a/app/models/notifications/mentioned.rb b/app/models/notifications/mentioned.rb
index d49b384d7..732cbb41e 100644
--- a/app/models/notifications/mentioned.rb
+++ b/app/models/notifications/mentioned.rb
@@ -18,7 +18,10 @@ module Notifications
)
relevant_mentions.each do |mention|
- create_notification(mention.person.owner, mention, actor).try(:email_the_user, mention, actor)
+ recipient = mention.person.owner
+ unless exists?(recipient: recipient, target: mention)
+ create_notification(recipient, mention, actor).try(:email_the_user, mention, actor)
+ end
end
end
end
diff --git a/spec/models/notifications/mentioned_spec.rb b/spec/models/notifications/mentioned_spec.rb
index 90e112aa3..ca77f960f 100644
--- a/spec/models/notifications/mentioned_spec.rb
+++ b/spec/models/notifications/mentioned_spec.rb
@@ -51,5 +51,17 @@ describe Notifications::Mentioned do
expect(TestNotification).not_to receive(:create_notification)
TestNotification.notify(status_message, nil)
end
+
+ it "doesn't create notification if it already exists" do
+ status_message = FactoryGirl.create(:status_message, text: text_mentioning(alice), author: eve.person)
+ TestNotification.create(
+ recipient: alice,
+ target: Mention.where(mentions_container: status_message, person: alice.person_id).first,
+ actors: [status_message.author]
+ )
+
+ expect(TestNotification).not_to receive(:create_notification)
+ TestNotification.notify(status_message, nil)
+ end
end
end