|
|
|
@ -67,10 +67,10 @@ class Message < ActiveRecord::Base |
|
|
|
|
after_create :add_author_as_watcher, |
|
|
|
|
:update_last_reply_in_parent, |
|
|
|
|
:send_message_posted_mail |
|
|
|
|
after_update :update_ancestors |
|
|
|
|
after_update :update_ancestors, if: :saved_change_to_board_id? |
|
|
|
|
after_destroy :reset_counters |
|
|
|
|
|
|
|
|
|
scope :visible, -> (*args) { |
|
|
|
|
scope :visible, ->(*args) { |
|
|
|
|
includes(board: :project) |
|
|
|
|
.references(:projects) |
|
|
|
|
.merge(Project.allowed_to(args.first || User.current, :view_messages)) |
|
|
|
@ -90,11 +90,9 @@ class Message < ActiveRecord::Base |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def set_sticked_on_date |
|
|
|
|
if sticky? |
|
|
|
|
self.sticked_on = sticked_on.nil? ? Time.now : sticked_on |
|
|
|
|
else |
|
|
|
|
self.sticked_on = nil |
|
|
|
|
end |
|
|
|
|
self.sticked_on = if sticky? |
|
|
|
|
sticked_on.nil? ? Time.now : sticked_on |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def update_last_reply_in_parent |
|
|
|
@ -104,15 +102,6 @@ class Message < ActiveRecord::Base |
|
|
|
|
board.reset_counters! |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def update_ancestors |
|
|
|
|
if board_id_changed? |
|
|
|
|
Message.where(['id = ? OR parent_id = ?', root.id, root.id]) |
|
|
|
|
.update_all("board_id = #{board_id}") |
|
|
|
|
Board.reset_counters!(board_id_was) |
|
|
|
|
Board.reset_counters!(board_id) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def reset_counters |
|
|
|
|
board.reset_counters! |
|
|
|
|
end |
|
|
|
@ -135,6 +124,18 @@ class Message < ActiveRecord::Base |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def update_ancestors |
|
|
|
|
with_id = Message.where(id: root.id) |
|
|
|
|
with_parent_id = Message.where(parent_id: root.id) |
|
|
|
|
|
|
|
|
|
with_id |
|
|
|
|
.or(with_parent_id) |
|
|
|
|
.update_all("board_id = #{board_id}") |
|
|
|
|
|
|
|
|
|
Board.reset_counters!(board_id_was) |
|
|
|
|
Board.reset_counters!(board_id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def add_author_as_watcher |
|
|
|
|
Watcher.create(watchable: root, user: author) |
|
|
|
|
# update watchers and watcher_users |
|
|
|
|