From bc5e32e737506f88cad82728fa7f8a769452e49f Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Tue, 18 Mar 2025 17:32:06 +0000 Subject: [PATCH] Only "published" notifies collection subscribers The other notifications are only sent to the watchers of the bubble. --- app/models/bubble/watchable.rb | 1 + app/models/notifier.rb | 2 +- app/models/notifier/published.rb | 4 ++++ app/models/user.rb | 2 +- app/views/bubbles/_messages.html.erb | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/bubble/watchable.rb b/app/models/bubble/watchable.rb index 05e5f9dbd..eff70c96f 100644 --- a/app/models/bubble/watchable.rb +++ b/app/models/bubble/watchable.rb @@ -3,6 +3,7 @@ module Bubble::Watchable included do has_many :watches, dependent: :destroy + has_many :watchers, ->{ merge(Watch.watching) }, through: :watches, source: :user after_create :set_watching_for_creator end diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 9c89d6bdf..10b1ba3c2 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -27,7 +27,7 @@ class Notifier end def recipients - bubble.watchers_and_subscribers.without(creator) + bubble.watchers.without(creator) end def resource diff --git a/app/models/notifier/published.rb b/app/models/notifier/published.rb index d5b50b87b..d43b8c8e3 100644 --- a/app/models/notifier/published.rb +++ b/app/models/notifier/published.rb @@ -1,2 +1,6 @@ class Notifier::Published < Notifier + private + def recipients + bubble.watchers_and_subscribers.without(creator) + end end diff --git a/app/models/user.rb b/app/models/user.rb index a79e4729e..57a8e636c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -31,7 +31,7 @@ class User < ApplicationRecord after_create_commit :grant_access_to_buckets scope :alphabetically, -> { order("lower(name)") } - scope :sorted_with_user_first, ->(user) { order(Arel.sql("id != ?, lower(name)", user.id)) } + scope :sorted_with_user_first, ->(user) { order(Arel.sql("users.id != ?, lower(name)", user.id)) } def initials name.to_s.scan(/\b\p{L}/).join.upcase diff --git a/app/views/bubbles/_messages.html.erb b/app/views/bubbles/_messages.html.erb index 5ddce595a..5a8eeea0e 100644 --- a/app/views/bubbles/_messages.html.erb +++ b/app/views/bubbles/_messages.html.erb @@ -7,7 +7,7 @@
Watching this…
- <%= render partial: "bubbles/watches/watcher", collection: bubble.watchers_and_subscribers.sorted_with_user_first(Current.user) %> + <%= render partial: "bubbles/watches/watcher", collection: bubble.watchers.sorted_with_user_first(Current.user) %>
<% end %>