|
|
|
@ -47,10 +47,25 @@ class Message < ApplicationRecord
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.bulk_move_to_other_board(message_ids, to_board_id, author_id)
|
|
|
|
|
message_ids.each do |id|
|
|
|
|
|
message = Message.find id
|
|
|
|
|
message.update_attributes(board_id: to_board_id, author_id: author_id) if message.parent_id.nil? # TODO 暂时只支持跟节点移动
|
|
|
|
|
def self.bulk_move_to_other_board(message_ids, to_board_id)
|
|
|
|
|
to_board = Board.find(to_board_id)
|
|
|
|
|
|
|
|
|
|
messages = Message.where(id: message_ids, parent_id: nil).select(:id, :board_id).to_a
|
|
|
|
|
return if messages.blank?
|
|
|
|
|
|
|
|
|
|
from_board = Board.find(messages.first.board_id)
|
|
|
|
|
|
|
|
|
|
root_ids = messages.map(&:id)
|
|
|
|
|
children = Message.where(parent_id: root_ids).select(:id).to_a
|
|
|
|
|
children_ids = children.map(&:id)
|
|
|
|
|
second_children = Message.where(parent_id: children_ids).select(:id).to_a
|
|
|
|
|
|
|
|
|
|
ids = root_ids.concat(children_ids).concat(second_children.map(&:id)).uniq
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id)
|
|
|
|
|
to_board.increment!(:messages_count, ids.size)
|
|
|
|
|
from_board.increment!(:messages_count, - ids.size)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|