diff options
Diffstat (limited to 'app/controllers')
4 files changed, 44 insertions, 22 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index d79ed142a..8eda96336 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -15,9 +15,7 @@ class AccountsController < ApplicationController render xml: AtomSerializer.render(AtomSerializer.new.feed(@account, @entries.to_a)) end - format.activitystreams2 do - headers['Access-Control-Allow-Origin'] = '*' - end + format.activitystreams2 end end diff --git a/app/controllers/api/activitypub/activities_controller.rb b/app/controllers/api/activitypub/activities_controller.rb index 03f27c7f6..ba03738fc 100644 --- a/app/controllers/api/activitypub/activities_controller.rb +++ b/app/controllers/api/activitypub/activities_controller.rb @@ -8,8 +8,6 @@ class Api::Activitypub::ActivitiesController < ApiController # Show a status in AS2 format, as either an Announce (reblog) or a Create (post) activity. def show_status - headers['Access-Control-Allow-Origin'] = '*' - return forbidden unless @status.permitted? if @status.reblog? diff --git a/app/controllers/api/activitypub/notes_controller.rb b/app/controllers/api/activitypub/notes_controller.rb index 722961ec6..6489243dc 100644 --- a/app/controllers/api/activitypub/notes_controller.rb +++ b/app/controllers/api/activitypub/notes_controller.rb @@ -6,8 +6,6 @@ class Api::Activitypub::NotesController < ApiController respond_to :activitystreams2 def show - headers['Access-Control-Allow-Origin'] = '*' - forbidden unless @status.permitted? end diff --git a/app/controllers/api/activitypub/outbox_controller.rb b/app/controllers/api/activitypub/outbox_controller.rb index 05d779910..7b6cbdd38 100644 --- a/app/controllers/api/activitypub/outbox_controller.rb +++ b/app/controllers/api/activitypub/outbox_controller.rb @@ -6,30 +6,47 @@ class Api::Activitypub::OutboxController < ApiController respond_to :activitystreams2 def show - headers['Access-Control-Allow-Origin'] = '*' + if params[:max_id] || params[:since_id] + show_outbox_page + else + show_base_outbox + end + end + + private - @statuses = Status.as_outbox_timeline(@account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id]) + def show_base_outbox + @statuses = Status.as_outbox_timeline(@account) @statuses = cache_collection(@statuses) set_maps(@statuses) - # Since the statuses are in reverse chronological order, last is the lowest ID. - @next_path = api_activitypub_outbox_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT) + set_first_last_page(@statuses) - unless @statuses.empty? - if @statuses.first.id == 1 - @prev_path = api_activitypub_outbox_url - elsif params[:max_id] - @prev_path = api_activitypub_outbox_url(since_id: @statuses.first.id) - end - end + render :show + end - @paginated = @next_path || @prev_path + def show_outbox_page + all_statuses = Status.as_outbox_timeline(@account) + @statuses = all_statuses.paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id]) - set_pagination_headers(@next_path, @prev_path) - end + all_statuses = cache_collection(all_statuses) + @statuses = cache_collection(@statuses) - private + set_maps(@statuses) + + set_first_last_page(all_statuses) + + @next_page_url = api_activitypub_outbox_url(pagination_params(max_id: @statuses.last.id)) unless @statuses.empty? + @prev_page_url = api_activitypub_outbox_url(pagination_params(since_id: @statuses.first.id)) unless @statuses.empty? + + @paginated = @next_page_url || @prev_page_url + @part_of_url = api_activitypub_outbox_url + + set_pagination_headers(@next_page_url, @prev_page_url) + + render :show_page + end def cache_collection(raw) super(raw, Status) @@ -38,4 +55,15 @@ class Api::Activitypub::OutboxController < ApiController def set_account @account = Account.find(params[:id]) end + + def set_first_last_page(statuses) # rubocop:disable Style/AccessorMethodName + return if statuses.empty? + + @first_page_url = api_activitypub_outbox_url(max_id: statuses.first.id + 1) + @last_page_url = api_activitypub_outbox_url(since_id: statuses.last.id - 1) + end + + def pagination_params(core_params) + params.permit(:local, :limit).merge(core_params) + end end |