2017-07-15 03:01:39 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::OutboxesController < Api::BaseController
|
2018-05-04 19:19:11 +02:00
|
|
|
LIMIT = 20
|
|
|
|
|
2018-02-02 10:19:59 +01:00
|
|
|
include SignatureVerification
|
|
|
|
|
2017-07-15 03:01:39 +02:00
|
|
|
before_action :set_account
|
2018-05-04 19:19:11 +02:00
|
|
|
before_action :set_statuses
|
2019-04-04 01:30:44 +02:00
|
|
|
before_action :set_cache_headers
|
2017-07-15 03:01:39 +02:00
|
|
|
|
|
|
|
def show
|
2019-04-04 01:30:44 +02:00
|
|
|
unless page_requested?
|
|
|
|
skip_session!
|
|
|
|
expires_in 1.minute, public: true
|
|
|
|
end
|
|
|
|
|
2018-03-04 09:19:11 +01:00
|
|
|
render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
|
2017-07-15 03:01:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_account
|
|
|
|
@account = Account.find_local!(params[:account_username])
|
|
|
|
end
|
|
|
|
|
|
|
|
def outbox_presenter
|
2018-05-04 19:19:11 +02:00
|
|
|
if page_requested?
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
|
|
|
id: account_outbox_url(@account, page_params),
|
|
|
|
type: :ordered,
|
|
|
|
part_of: account_outbox_url(@account),
|
|
|
|
prev: prev_page,
|
|
|
|
next: next_page,
|
|
|
|
items: @statuses
|
|
|
|
)
|
|
|
|
else
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
|
|
|
id: account_outbox_url(@account),
|
|
|
|
type: :ordered,
|
|
|
|
size: @account.statuses_count,
|
|
|
|
first: account_outbox_url(@account, page: true),
|
|
|
|
last: account_outbox_url(@account, page: true, min_id: 0)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_page
|
|
|
|
account_outbox_url(@account, page: true, max_id: @statuses.last.id) if @statuses.size == LIMIT
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_page
|
|
|
|
account_outbox_url(@account, page: true, min_id: @statuses.first.id) unless @statuses.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_statuses
|
|
|
|
return unless page_requested?
|
|
|
|
|
|
|
|
@statuses = @account.statuses.permitted_for(@account, signed_request_account)
|
|
|
|
@statuses = params[:min_id].present? ? @statuses.paginate_by_min_id(LIMIT, params[:min_id]).reverse : @statuses.paginate_by_max_id(LIMIT, params[:max_id])
|
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_requested?
|
|
|
|
params[:page] == 'true'
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_params
|
|
|
|
{ page: true, max_id: params[:max_id], min_id: params[:min_id] }.compact
|
2017-07-15 03:01:39 +02:00
|
|
|
end
|
|
|
|
end
|