闭社主体 forked from https://github.com/tootsuite/mastodon
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.

64 lines
2.0 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
  9. render json: @account, serializer: REST::AccountSerializer
  10. end
  11. def follow
  12. FollowService.new.call(current_user.account, @account.acct)
  13. unless @account.locked?
  14. relationships = AccountRelationshipsPresenter.new(
  15. [@account.id],
  16. current_user.account_id,
  17. following_map: { @account.id => true },
  18. requested_map: { @account.id => false }
  19. )
  20. end
  21. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  22. end
  23. def block
  24. BlockService.new.call(current_user.account, @account)
  25. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  26. end
  27. def mute
  28. MuteService.new.call(current_user.account, @account)
  29. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  30. end
  31. def unfollow
  32. UnfollowService.new.call(current_user.account, @account)
  33. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  34. end
  35. def unblock
  36. UnblockService.new.call(current_user.account, @account)
  37. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  38. end
  39. def unmute
  40. UnmuteService.new.call(current_user.account, @account)
  41. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  42. end
  43. private
  44. def set_account
  45. @account = Account.find(params[:id])
  46. end
  47. def relationships
  48. AccountRelationshipsPresenter.new([@account.id], current_user.account_id)
  49. end
  50. end