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.

70 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::AccountsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock, :mute, :unmute]
  4. before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock, :mute, :unmute]
  5. before_action :require_user!, except: [:show]
  6. before_action :set_account
  7. respond_to :json
  8. def show; end
  9. def follow
  10. FollowService.new.call(current_user.account, @account.acct)
  11. set_relationship
  12. render :relationship
  13. end
  14. def block
  15. BlockService.new.call(current_user.account, @account)
  16. @following = { @account.id => false }
  17. @followed_by = { @account.id => false }
  18. @blocking = { @account.id => true }
  19. @requested = { @account.id => false }
  20. @muting = { @account.id => current_account.muting?(@account.id) }
  21. @domain_blocking = { @account.id => current_account.domain_blocking?(@account.domain) }
  22. render :relationship
  23. end
  24. def mute
  25. MuteService.new.call(current_user.account, @account)
  26. set_relationship
  27. render :relationship
  28. end
  29. def unfollow
  30. UnfollowService.new.call(current_user.account, @account)
  31. set_relationship
  32. render :relationship
  33. end
  34. def unblock
  35. UnblockService.new.call(current_user.account, @account)
  36. set_relationship
  37. render :relationship
  38. end
  39. def unmute
  40. UnmuteService.new.call(current_user.account, @account)
  41. set_relationship
  42. render :relationship
  43. end
  44. private
  45. def set_account
  46. @account = Account.find(params[:id])
  47. end
  48. def set_relationship
  49. @following = Account.following_map([@account.id], current_user.account_id)
  50. @followed_by = Account.followed_by_map([@account.id], current_user.account_id)
  51. @blocking = Account.blocking_map([@account.id], current_user.account_id)
  52. @muting = Account.muting_map([@account.id], current_user.account_id)
  53. @requested = Account.requested_map([@account.id], current_user.account_id)
  54. @domain_blocking = Account.domain_blocking_map([@account.id], current_user.account_id)
  55. end
  56. end