Browse Source

API methods for retrieving home and mentions timelines

pull/4/head
Eugen Rochko 6 years ago
parent
commit
fe57f6330f
5 changed files with 18 additions and 1 deletions
  1. +1
    -1
      app/controllers/api/accounts_controller.rb
  2. +8
    -0
      app/controllers/api/statuses_controller.rb
  3. +2
    -0
      app/views/api/statuses/home.rabl
  4. +2
    -0
      app/views/api/statuses/mentions.rabl
  5. +5
    -0
      config/routes.rb

+ 1
- 1
app/controllers/api/accounts_controller.rb View File

@ -15,7 +15,7 @@ class Api::AccountsController < ApiController
end
def statuses
@statuses = @account.statuses
@statuses = @account.statuses.order('created_at desc')
end
def follow

+ 8
- 0
app/controllers/api/statuses_controller.rb View File

@ -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

+ 2
- 0
app/views/api/statuses/home.rabl View File

@ -0,0 +1,2 @@
collection @statuses
extends('api/statuses/show')

+ 2
- 0
app/views/api/statuses/mentions.rabl View File

@ -0,0 +1,2 @@
collection @statuses
extends('api/statuses/show')

+ 5
- 0
config/routes.rb View File

@ -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

Loading…
Cancel
Save