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.

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