about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-03 14:50:22 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-03 14:50:22 +0100
commite4671adc25081161268c885b3427fd84cbecb249 (patch)
tree0bd6e1cdbdad43225574a64a712e2fe0bc4f1817 /app/controllers
parentc003e7075880071743af06cfb5865bdb943db024 (diff)
Fix reblogged/favourited caching; add API endpoints for who favd/reblogged status
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api/v1/statuses_controller.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 3db4dbbd0..a87e1528d 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -2,18 +2,28 @@ class Api::V1::StatusesController < ApiController
   before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
   before_action -> { doorkeeper_authorize! :write }, only:  [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
 
-  respond_to    :json
+  before_action :set_status, only: [:show, :context, :reblogged_by, :favourited_by]
+
+  respond_to :json
 
   def show
-    @status = Status.find(params[:id])
   end
 
   def context
-    @status  = Status.find(params[:id])
     @context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
     set_maps([@status] + @context[:ancestors] + @context[:descendants])
   end
 
+  def reblogged_by
+    @accounts = @status.reblogs.includes(:account).limit(40).map(&:account)
+    render action: :accounts
+  end
+
+  def favourited_by
+    @accounts = @status.favourites.includes(:account).limit(40).map(&:account)
+    render action: :accounts
+  end
+
   def create
     @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])
     render action: :show
@@ -63,4 +73,10 @@ class Api::V1::StatusesController < ApiController
     set_maps(@statuses)
     render action: :index
   end
+
+  private
+
+  def set_status
+    @status = Status.find(params[:id])
+  end
 end