Files
fizzy/app/models/bubble/watchable.rb
T
Kevin McConnell bc5e32e737 Only "published" notifies collection subscribers
The other notifications are only sent to the watchers of the bubble.
2025-03-18 17:46:57 +00:00

29 lines
700 B
Ruby

module Bubble::Watchable
extend ActiveSupport::Concern
included do
has_many :watches, dependent: :destroy
has_many :watchers, ->{ merge(Watch.watching) }, through: :watches, source: :user
after_create :set_watching_for_creator
end
def watched_by?(user)
watchers_and_subscribers.include?(user)
end
def set_watching(user, watching)
watches.where(user: user).first_or_create.update!(watching: watching)
end
def watchers_and_subscribers
User.where(id: bucket.subscribers.pluck(:id) +
watches.watching.pluck(:user_id) - watches.not_watching.pluck(:user_id))
end
private
def set_watching_for_creator
set_watching(creator, true)
end
end