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.
This commit is contained in:
Kevin McConnell
2025-02-24 14:27:36 +00:00
parent 2d0c9d309b
commit 6157d8b4bd
7 changed files with 34 additions and 7 deletions
+2
View File
@@ -21,6 +21,8 @@ module Bubble::Assignable
private
def assign(user)
assignments.create! assignee: user, assigner: Current.user
set_watching(user, true)
track_event :assigned, assignee_ids: [ user.id ]
rescue ActiveRecord::RecordNotUnique
# Already assigned
+2
View File
@@ -7,6 +7,8 @@ module Bubble::Commentable
def comment_created(comment)
increment! :comments_count
set_watching comment.creator, true
track_event :commented, comment_id: comment.id
rescore
end
+1 -1
View File
@@ -8,7 +8,7 @@ module Bubble::Watchable
after_create :create_initial_watches
end
def watching?(user)
def watched_by?(user)
watches.where(user: user, watching: true).exists?
end
+1 -1
View File
@@ -1,5 +1,5 @@
<%= turbo_frame_tag dom_id(@bubble, :watch) do %>
<% if @bubble.watching? Current.user %>
<% if @bubble.watched_by? Current.user %>
<%= button_to bucket_bubble_watch_path(@bubble.bucket, @bubble), method: :delete, class: "btn" do %>
<%= image_tag "bookmark.svg", aria: { hidden: true }, size: 24 %>
<span class="overflow-ellipsis">Stop watching</span>
-5
View File
@@ -38,11 +38,6 @@ text_jz:
user: jz
watching: true
text_kevin:
bubble: text
user: kevin
watching: true
shipping_david:
bubble: shipping
user: david
+15
View File
@@ -0,0 +1,15 @@
require "test_helper"
class Bubble::AssignableTest < ActiveSupport::TestCase
test "assigning a user makes them watch the bubble" do
assert_not bubbles(:layout).assigned_to?(users(:kevin))
bubbles(:layout).set_watching(users(:kevin), false)
with_current_user(:jz) do
bubbles(:layout).toggle_assignment(users(:kevin))
end
assert bubbles(:layout).assigned_to?(users(:kevin))
assert bubbles(:layout).watched_by?(users(:kevin))
end
end
+13
View File
@@ -0,0 +1,13 @@
require "test_helper"
class Bubble::CommentableTest < ActiveSupport::TestCase
test "creating a comment on a bubble makes the creator watch the bubble" do
assert_not bubbles(:text).watched_by?(users(:kevin))
with_current_user(:kevin) do
bubbles(:text).capture Comment.new(body: "This sounds interesting!")
end
assert bubbles(:text).watched_by?(users(:kevin))
end
end