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.

73 lines
1.9 KiB

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