You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

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