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.

65 lines
2.3 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::AccountsController < Api::BaseController
  3. before_action -> { authorize_if_got_token! :read, :'read:accounts' }, except: [:follow, :unfollow, :block, :unblock, :mute, :unmute]
  4. before_action -> { doorkeeper_authorize! :follow, :'write:follows' }, only: [:follow, :unfollow]
  5. before_action -> { doorkeeper_authorize! :follow, :'write:mutes' }, only: [:mute, :unmute]
  6. before_action -> { doorkeeper_authorize! :follow, :'write:blocks' }, only: [:block, :unblock]
  7. before_action :require_user!, except: [:show]
  8. before_action :set_account
  9. before_action :check_account_suspension, only: [:show]
  10. respond_to :json
  11. def show
  12. render json: @account, serializer: REST::AccountSerializer
  13. end
  14. def follow
  15. FollowService.new.call(current_user.account, @account, reblogs: truthy_param?(:reblogs))
  16. options = @account.locked? ? {} : { following_map: { @account.id => { reblogs: truthy_param?(:reblogs) } }, requested_map: { @account.id => false } }
  17. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships(options)
  18. end
  19. def block
  20. BlockService.new.call(current_user.account, @account)
  21. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  22. end
  23. def mute
  24. MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications))
  25. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  26. end
  27. def unfollow
  28. UnfollowService.new.call(current_user.account, @account)
  29. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  30. end
  31. def unblock
  32. UnblockService.new.call(current_user.account, @account)
  33. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  34. end
  35. def unmute
  36. UnmuteService.new.call(current_user.account, @account)
  37. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
  38. end
  39. private
  40. def set_account
  41. @account = Account.find(params[:id])
  42. end
  43. def relationships(**options)
  44. AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
  45. end
  46. def check_account_suspension
  47. gone if @account.suspended?
  48. end
  49. end