From fe57f6330f089d023f0fa4db7f7c8a51551d2ee9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 7 Mar 2016 13:25:26 +0100 Subject: [PATCH] API methods for retrieving home and mentions timelines --- app/controllers/api/accounts_controller.rb | 2 +- app/controllers/api/statuses_controller.rb | 8 ++++++++ app/views/api/statuses/home.rabl | 2 ++ app/views/api/statuses/mentions.rabl | 2 ++ config/routes.rb | 5 +++++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/views/api/statuses/home.rabl create mode 100644 app/views/api/statuses/mentions.rabl diff --git a/app/controllers/api/accounts_controller.rb b/app/controllers/api/accounts_controller.rb index 927fd86b70..fc4c9d6812 100644 --- a/app/controllers/api/accounts_controller.rb +++ b/app/controllers/api/accounts_controller.rb @@ -15,7 +15,7 @@ class Api::AccountsController < ApiController end def statuses - @statuses = @account.statuses + @statuses = @account.statuses.order('created_at desc') end def follow diff --git a/app/controllers/api/statuses_controller.rb b/app/controllers/api/statuses_controller.rb index b1633ab6cc..82334a32f2 100644 --- a/app/controllers/api/statuses_controller.rb +++ b/app/controllers/api/statuses_controller.rb @@ -20,4 +20,12 @@ class Api::StatusesController < ApiController @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 diff --git a/app/views/api/statuses/home.rabl b/app/views/api/statuses/home.rabl new file mode 100644 index 0000000000..12f00dd21d --- /dev/null +++ b/app/views/api/statuses/home.rabl @@ -0,0 +1,2 @@ +collection @statuses +extends('api/statuses/show') diff --git a/app/views/api/statuses/mentions.rabl b/app/views/api/statuses/mentions.rabl new file mode 100644 index 0000000000..12f00dd21d --- /dev/null +++ b/app/views/api/statuses/mentions.rabl @@ -0,0 +1,2 @@ +collection @statuses +extends('api/statuses/show') diff --git a/config/routes.rb b/config/routes.rb index 98d892fd50..d63bdf9812 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,11 @@ Rails.application.routes.draw do # JSON / REST API resources :statuses, only: [:create, :show] do + collection do + get :home + get :mentions + end + member do post :reblog post :favourite