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.

95 lines
2.7 KiB

7 years ago
  1. class Api::V1::StatusesController < ApiController
  2. before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
  3. before_action -> { doorkeeper_authorize! :write }, only: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
  4. before_action :set_status, only: [:show, :context, :reblogged_by, :favourited_by]
  5. respond_to :json
  6. def show
  7. end
  8. def context
  9. @context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
  10. set_maps([@status] + @context[:ancestors] + @context[:descendants])
  11. end
  12. def reblogged_by
  13. @accounts = @status.reblogged_by(40)
  14. render action: :accounts
  15. end
  16. def favourited_by
  17. @accounts = @status.favourited_by(40)
  18. render action: :accounts
  19. end
  20. def create
  21. @status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), params[:media_ids])
  22. render action: :show
  23. end
  24. def destroy
  25. @status = Status.where(account_id: current_user.account).find(params[:id])
  26. RemoveStatusService.new.call(@status)
  27. render_empty
  28. end
  29. def reblog
  30. @status = ReblogService.new.call(current_user.account, Status.find(params[:id])).reload
  31. render action: :show
  32. end
  33. def unreblog
  34. RemoveStatusService.new.call(Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first!)
  35. @status = Status.find(params[:id])
  36. render action: :show
  37. end
  38. def favourite
  39. @status = FavouriteService.new.call(current_user.account, Status.find(params[:id])).status.reload
  40. render action: :show
  41. end
  42. def unfavourite
  43. @status = UnfavouriteService.new.call(current_user.account, Status.find(params[:id])).status.reload
  44. render action: :show
  45. end
  46. def home
  47. @statuses = Feed.new(:home, current_user.account).get(20, params[:max_id], params[:since_id]).to_a
  48. set_maps(@statuses)
  49. render action: :index
  50. end
  51. def mentions
  52. @statuses = Feed.new(:mentions, current_user.account).get(20, params[:max_id], params[:since_id]).to_a
  53. set_maps(@statuses)
  54. render action: :index
  55. end
  56. def public
  57. @statuses = Status.as_public_timeline(current_user.account).paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
  58. set_maps(@statuses)
  59. render action: :index
  60. end
  61. def tag
  62. @tag = Tag.find_by(name: params[:id].downcase)
  63. if @tag.nil?
  64. @statuses = []
  65. else
  66. @statuses = Status.as_tag_timeline(@tag, current_user.account).paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
  67. set_maps(@statuses)
  68. end
  69. render action: :index
  70. end
  71. private
  72. def set_status
  73. @status = Status.find(params[:id])
  74. end
  75. end