logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

accounts_controller.rb (2013B)


  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, reblogs: truthy_param?(:reblogs))
  13. options = @account.locked? ? {} : { following_map: { @account.id => { reblogs: truthy_param?(:reblogs) } }, 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: truthy_param?(: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