remote_interaction_controller.rb 1.2 KB

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