diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-08 23:22:44 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-08 23:29:08 +0100 |
commit | 9aecc0f48a046e0a05b8ca69511f8b72756fb431 (patch) | |
tree | 636bb2399ec2f853af5ebd593af6c75e311c7dd7 /app/controllers/api_controller.rb | |
parent | 86574ea5248219fa35ecb0748920df9ff1ce6110 (diff) |
Move timelines API from statuses to its own controller, add a check for
resources that require a user context vs those that don't (such as public timeline) /api/v1/statuses/public -> /api/v1/timelines/public /api/v1/statuses/home -> /api/v1/timelines/home /api/v1/statuses/mentions -> /api/v1/timelines/mentions /api/v1/statuses/tag/:tag -> /api/v1/timelines/tag/:tag
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r-- | app/controllers/api_controller.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 273aaff85..db4035a96 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -60,6 +60,14 @@ class ApiController < ApplicationController def current_user super || current_resource_owner + rescue ActiveRecord::RecordNotFound + nil + end + + def require_user! + current_resource_owner + rescue ActiveRecord::RecordNotFound + render json: { error: 'This method requires an authenticated user' }, status: 422 end def render_empty @@ -67,8 +75,14 @@ class ApiController < ApplicationController end def set_maps(statuses) + if current_account.nil? + @reblogs_map = {} + @favourites_map = {} + return + end + status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.compact.uniq - @reblogs_map = Status.reblogs_map(status_ids, current_user.account) - @favourites_map = Status.favourites_map(status_ids, current_user.account) + @reblogs_map = Status.reblogs_map(status_ids, current_account) + @favourites_map = Status.favourites_map(status_ids, current_account) end end |