diff --git a/Changelog.md b/Changelog.md index ee3c9e7e485d9f913f60deafcb2f8f1634ab42cc..a704a5c37a3adc1be0838c96db6a7b1a4d706d4d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -90,6 +90,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure. ## Bug fixes * Redirect to sign in page when a background request fails with 401 [#6496](https://github.com/diaspora/diaspora/pull/6496) * Correctly skip setting sidekiq logfile on Heroku [#6500](https://github.com/diaspora/diaspora/pull/6500) +* Fix notifications for interactions by non-contacts [#6498](https://github.com/diaspora/diaspora/pull/6498) ## Features diff --git a/app/models/comment.rb b/app/models/comment.rb index b4194e7c8764ceee1e2128288c47042c88f76733..b1cb6243a8f322b4a5618eef821387e68a72cd65 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -98,6 +98,7 @@ class Comment < ActiveRecord::Base def initialize(person, target, text) @text = text + @dispatcher_opts = {additional_subscribers: target.comments_authors.where.not(id: person.id)} super(person, target) end diff --git a/features/desktop/notifications.feature b/features/desktop/notifications.feature index 8707dbf9b66be8452403ef63f17c08c512e54e19..efb697c0d8ac95ac7bd7b4a4b6e59c124d226032 100644 --- a/features/desktop/notifications.feature +++ b/features/desktop/notifications.feature @@ -9,6 +9,7 @@ Feature: Notifications | email | | bob@bob.bob | | alice@alice.alice | + | carol@carol.carol | Scenario: someone shares with me When I sign in as "bob@bob.bob" @@ -67,6 +68,80 @@ Feature: Notifications Then I should see "commented on your post" And I should have 1 email delivery + Scenario: unconnected user comments in reply to comment by another user who commented a post of someone who she shares with + Given "alice@alice.alice" has a public post with text "check this out!" + When I sign in as "bob@bob.bob" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great post, alice! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment" + When I sign out + And I sign in as "carol@carol.carol" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great comment, bob! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment:nth-child(2)" + When I sign out + And I sign in as "bob@bob.bob" + And I follow "Notifications" in the header + Then the notification dropdown should be visible + And I should see "also commented on" + And I should have 3 email delivery + + + Scenario: unconnected user comments in reply to my comment to her post + Given "alice@alice.alice" has a public post with text "check this out!" + When I sign in as "carol@carol.carol" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great post, alice! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment" + When I sign out + And I sign in as "alice@alice.alice" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great post, carol! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment:nth-child(2)" + When I sign out + And I sign in as "carol@carol.carol" + And I follow "Notifications" in the header + Then the notification dropdown should be visible + And I should see "also commented on" + And I should have 2 email delivery + + Scenario: connected user comments in reply to my comment to an unconnected user's post + Given "alice@alice.alice" has a public post with text "check this out!" + And a user with email "bob@bob.bob" is connected with "carol@carol.carol" + When I sign in as "carol@carol.carol" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great post! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment" + When I sign out + And I sign in as "bob@bob.bob" + And I am on "alice@alice.alice"'s page + And I focus the comment field + And I fill in the following: + | text | great post! | + And I press "Comment" + Then I should see "less than a minute ago" within ".comment:nth-child(2)" + When I sign out + And I sign in as "carol@carol.carol" + And I follow "Notifications" in the header + Then the notification dropdown should be visible + And I should see "also commented on" + And I should have 3 email delivery + Scenario: someone mentioned me in their post Given a user with email "bob@bob.bob" is connected with "alice@alice.alice" And Alice has a post mentioning Bob diff --git a/lib/diaspora/commentable.rb b/lib/diaspora/commentable.rb index 22df55010f4d11a30604713b13739084c399b7c3..0e5e06b4458354f665f9b1474d1f07252c05587e 100644 --- a/lib/diaspora/commentable.rb +++ b/lib/diaspora/commentable.rb @@ -24,5 +24,8 @@ module Diaspora update_all(:comments_count => self.comments.count) end + def comments_authors + Person.where(id: comments.select(:author_id).distinct) + end end end diff --git a/lib/federated/generator.rb b/lib/federated/generator.rb index 4ee81511ae71c09815b6f2002e2eb483e14a511f..da3a8390e4a64e378b7c44cb2d6909ad00b2679a 100644 --- a/lib/federated/generator.rb +++ b/lib/federated/generator.rb @@ -5,13 +5,14 @@ module Federated def initialize(user, target) @user = user @target = target + @dispatcher_opts ||= {} end def create!(options={}) relayable = build(options) if relayable.save! logger.info "user:#{@user.id} dispatching #{relayable.class}:#{relayable.guid}" - Postzord::Dispatcher.defer_build_and_post(@user, relayable) + Postzord::Dispatcher.defer_build_and_post(@user, relayable, @dispatcher_opts) relayable end end diff --git a/lib/postzord/receiver/local_batch.rb b/lib/postzord/receiver/local_batch.rb index 5ff2e42c0073028422a1cf64e6a8b2bd115668e2..01a6ff47faa346f1e71c095d0e9de87fe7446a0e 100644 --- a/lib/postzord/receiver/local_batch.rb +++ b/lib/postzord/receiver/local_batch.rb @@ -61,5 +61,18 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver @users.find_each do |user| Notification.notify(user, @object, @object.author) end + if @object.respond_to?(:target) + additional_subscriber = @object.target.author.owner + elsif @object.respond_to?(:post) + additional_subscriber = @object.post.author.owner + end + + Notification.notify(additional_subscriber, @object, @object.author) if needs_notification?(additional_subscriber) + end + + private + + def needs_notification?(person) + person && person != @object.author.owner && !@users.exists?(person.id) end end