Skip to content

Commit

Permalink
API methods for retrieving home and mentions timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Mar 7, 2016
1 parent f099bc6 commit fe57f63
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def followers
end

def statuses
@statuses = @account.statuses
@statuses = @account.statuses.order('created_at desc')
end

def follow
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/api/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ def favourite
@status = FavouriteService.new.(current_user.account, Status.find(params[:id])).status
render action: :show
end

def home
@statuses = Status.where(account: [current_user.account] + current_user.account.following).order('created_at desc')
end

def mentions
@statuses = Status.where(id: Mention.where(account: current_user.account).pluck(:status_id)).order('created_at desc')
end
end
2 changes: 2 additions & 0 deletions app/views/api/statuses/home.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @statuses
extends('api/statuses/show')
2 changes: 2 additions & 0 deletions app/views/api/statuses/mentions.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collection @statuses
extends('api/statuses/show')
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

# JSON / REST API
resources :statuses, only: [:create, :show] do
collection do
get :home
get :mentions
end

member do
post :reblog
post :favourite
Expand Down

0 comments on commit fe57f63

Please sign in to comment.