Files
once-campfire/app/controllers/messages/boosts_controller.rb
T
Stanko Krtalić 1e9f681b3a Scope boosts to the current message
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-08-11 14:33:05 +02:00

46 lines
1006 B
Ruby

class Messages::BoostsController < ApplicationController
before_action :set_message
before_action :set_boost, only: :destroy
def index
end
def new
end
def create
@boost = @message.boosts.create!(boost_params)
broadcast_create
redirect_to message_boosts_url(@message)
end
def destroy
@boost.destroy!
broadcast_remove
end
private
def set_message
@message = Current.user.reachable_messages.find(params[:message_id])
end
def set_boost
@boost = @message.boosts.find_by!(id: params[:id], booster: Current.user)
end
def boost_params
params.require(:boost).permit(:content)
end
def broadcast_create
@boost.broadcast_append_to @boost.message.room, :messages,
target: "boosts_message_#{@boost.message.client_message_id}", partial: "messages/boosts/boost", attributes: { maintain_scroll: true }
end
def broadcast_remove
@boost.broadcast_remove_to @boost.message.room, :messages
end
end