Rescore bubble from Message, not Comment

This commit is contained in:
Jose Farias
2024-11-19 13:27:09 -06:00
parent 2a9be42c4e
commit 9ac136bace
4 changed files with 8 additions and 22 deletions
+2 -2
View File
@@ -5,12 +5,12 @@ module Bubble::Commentable
scope :ordered_by_comments, -> { order comments_count: :desc }
end
def comment_captured
def comment_created
increment! :comments_count
rescore
end
def comment_uncaptured
def comment_destroyed
decrement! :comments_count
rescore
end
-8
View File
@@ -4,12 +4,4 @@ class Comment < ApplicationRecord
belongs_to :creator, class_name: "User", default: -> { Current.user }
searchable_by :body, using: :comments_search_index
def captured_as(message)
message.bubble.comment_captured
end
def uncaptured_as(message)
message.bubble.comment_uncaptured
end
end
-6
View File
@@ -7,10 +7,4 @@ module Messageable
has_one :message, as: :messageable, touch: true
has_one :bubble, through: :message
end
def captured_as(...)
end
def uncaptured_as(...)
end
end
+6 -6
View File
@@ -5,15 +5,15 @@ class Message < ApplicationRecord
scope :chronologically, -> { order created_at: :asc, id: :desc }
after_create :captured
after_destroy :uncaptured
after_create :created
after_destroy :destroyed
private
def captured
messageable.captured_as(self)
def created
bubble.comment_created if comment?
end
def uncaptured
messageable.uncaptured_as(self)
def destroyed
bubble.comment_destroyed if comment?
end
end