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.

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