remote_interaction_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. class RemoteInteractionController < ApplicationController
  3. include Authorization
  4. layout 'modal'
  5. before_action :set_interaction_type
  6. before_action :set_status
  7. before_action :set_body_classes
  8. def new
  9. @remote_follow = RemoteFollow.new(session_params)
  10. end
  11. def create
  12. @remote_follow = RemoteFollow.new(resource_params)
  13. if @remote_follow.valid?
  14. session[:remote_follow] = @remote_follow.acct
  15. redirect_to @remote_follow.interact_address_for(@status)
  16. else
  17. render :new
  18. end
  19. end
  20. private
  21. def resource_params
  22. params.require(:remote_follow).permit(:acct)
  23. end
  24. def session_params
  25. { acct: session[:remote_follow] }
  26. end
  27. def set_status
  28. @status = Status.find(params[:id])
  29. authorize @status, :show?
  30. rescue Mastodon::NotPermittedError
  31. # Reraise in order to get a 404
  32. raise ActiveRecord::RecordNotFound
  33. end
  34. def set_body_classes
  35. @body_classes = 'modal-layout'
  36. @hide_header = true
  37. end
  38. def set_interaction_type
  39. @interaction_type = %w(reply reblog favourite).include?(params[:type]) ? params[:type] : 'reply'
  40. end
  41. end