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.

76 lines
2.1 KiB

  1. class Api::V1::AccountsController < ApiController
  2. before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock]
  3. before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock]
  4. before_action :set_account, except: [:verify_credentials, :suggestions]
  5. respond_to :json
  6. def show
  7. end
  8. def verify_credentials
  9. @account = current_user.account
  10. render action: :show
  11. end
  12. def following
  13. @following = @account.following
  14. end
  15. def followers
  16. @followers = @account.followers
  17. end
  18. def suggestions
  19. @accounts = FollowSuggestion.get(current_user.account_id)
  20. end
  21. def statuses
  22. @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
  23. set_maps(@statuses)
  24. end
  25. def follow
  26. FollowService.new.call(current_user.account, @account.acct)
  27. set_relationship
  28. render action: :relationship
  29. end
  30. def block
  31. BlockService.new.call(current_user.account, @account)
  32. set_relationship
  33. render action: :relationship
  34. end
  35. def unfollow
  36. UnfollowService.new.call(current_user.account, @account)
  37. set_relationship
  38. render action: :relationship
  39. end
  40. def unblock
  41. UnblockService.new.call(current_user.account, @account)
  42. set_relationship
  43. render action: :relationship
  44. end
  45. def relationships
  46. ids = params[:id].is_a?(Enumerable) ? params[:id].map(&:to_i) : [params[:id].to_i]
  47. @accounts = Account.where(id: ids).select('id')
  48. @following = Account.following_map(ids, current_user.account_id)
  49. @followed_by = Account.followed_by_map(ids, current_user.account_id)
  50. @blocking = Account.blocking_map(ids, current_user.account_id)
  51. end
  52. private
  53. def set_account
  54. @account = Account.find(params[:id])
  55. end
  56. def set_relationship
  57. @following = Account.following_map([@account.id], current_user.account_id)
  58. @followed_by = Account.followed_by_map([@account.id], current_user.account_id)
  59. @blocking = Account.blocking_map([@account.id], current_user.account_id)
  60. end
  61. end