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.

39 lines
786 B

  1. # frozen_string_literal: true
  2. class RemoteUnfollowsController < ApplicationController
  3. layout 'modal'
  4. before_action :authenticate_user!
  5. before_action :set_body_classes
  6. def create
  7. @account = unfollow_attempt.try(:target_account)
  8. if @account.nil?
  9. render :error
  10. else
  11. render :success
  12. end
  13. rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
  14. render :error
  15. end
  16. private
  17. def unfollow_attempt
  18. username, domain = acct_without_prefix.split('@')
  19. UnfollowService.new.call(current_account, Account.find_remote!(username, domain))
  20. end
  21. def acct_without_prefix
  22. acct_params.gsub(/\Aacct:/, '')
  23. end
  24. def acct_params
  25. params.fetch(:acct, '')
  26. end
  27. def set_body_classes
  28. @body_classes = 'modal-layout'
  29. end
  30. end