Files
fizzy/app/models/bubble/watchable.rb
T
Kevin McConnell 6157d8b4bd Start watching when participating on a bubble
If you're added as an assignee, or if you comment, then your watching
preference will be toggled on.
2025-02-26 10:53:03 +00:00

24 lines
611 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 :create_initial_watches
end
def watched_by?(user)
watches.where(user: user, watching: true).exists?
end
def set_watching(user, watching)
watches.where(user: user).first_or_create.update!(watching: watching)
end
private
def create_initial_watches
Watch.insert_all(bucket.users.pluck(:id).collect { |user_id| { user_id: user_id, bubble_id: id } })
end
end