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.

54 lines
1.7 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. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  14. end
  15. def block
  16. BlockService.new.call(current_user.account, @account)
  17. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  18. end
  19. def mute
  20. MuteService.new.call(current_user.account, @account)
  21. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  22. end
  23. def unfollow
  24. UnfollowService.new.call(current_user.account, @account)
  25. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  26. end
  27. def unblock
  28. UnblockService.new.call(current_user.account, @account)
  29. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  30. end
  31. def unmute
  32. UnmuteService.new.call(current_user.account, @account)
  33. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  34. end
  35. private
  36. def set_account
  37. @account = Account.find(params[:id])
  38. end
  39. def relationships
  40. AccountRelationshipsPresenter.new([@account.id], current_user.account_id)
  41. end
  42. end