2017-07-15 10:01:39 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-17 07:00:39 +09:00
|
|
|
class ActivityPub::OutboxesController < ActivityPub::BaseController
|
2018-05-05 02:19:11 +09:00
|
|
|
LIMIT = 20
|
|
|
|
|
2023-04-19 23:07:29 +09:00
|
|
|
vary_by -> { 'Signature' if authorized_fetch_mode? || page_requested? }
|
|
|
|
|
2022-09-22 05:45:57 +09:00
|
|
|
before_action :require_account_signature!, if: :authorized_fetch_mode?
|
2018-05-05 02:19:11 +09:00
|
|
|
before_action :set_statuses
|
2017-07-15 10:01:39 +09:00
|
|
|
|
|
|
|
def show
|
2021-07-04 04:13:47 +09:00
|
|
|
if page_requested?
|
|
|
|
expires_in(1.minute, public: public_fetch_mode? && signed_request_account.nil?)
|
|
|
|
else
|
|
|
|
expires_in(3.minutes, public: public_fetch_mode?)
|
|
|
|
end
|
2023-04-19 23:07:29 +09:00
|
|
|
|
2018-03-04 17:19:11 +09:00
|
|
|
render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
|
2017-07-15 10:01:39 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def outbox_presenter
|
2018-05-05 02:19:11 +09:00
|
|
|
if page_requested?
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
2021-05-06 21:22:54 +09:00
|
|
|
id: outbox_url(**page_params),
|
2018-05-05 02:19:11 +09:00
|
|
|
type: :ordered,
|
2020-09-03 01:42:50 +09:00
|
|
|
part_of: outbox_url,
|
2018-05-05 02:19:11 +09:00
|
|
|
prev: prev_page,
|
|
|
|
next: next_page,
|
|
|
|
items: @statuses
|
|
|
|
)
|
|
|
|
else
|
|
|
|
ActivityPub::CollectionPresenter.new(
|
2021-06-01 05:59:30 +09:00
|
|
|
id: outbox_url,
|
2018-05-05 02:19:11 +09:00
|
|
|
type: :ordered,
|
|
|
|
size: @account.statuses_count,
|
2020-09-03 01:42:50 +09:00
|
|
|
first: outbox_url(page: true),
|
|
|
|
last: outbox_url(page: true, min_id: 0)
|
2018-05-05 02:19:11 +09:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-03 01:42:50 +09:00
|
|
|
def outbox_url(**kwargs)
|
|
|
|
if params[:account_username].present?
|
|
|
|
account_outbox_url(@account, **kwargs)
|
|
|
|
else
|
|
|
|
instance_actor_outbox_url(**kwargs)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-05 02:19:11 +09:00
|
|
|
def next_page
|
2021-06-01 05:59:30 +09:00
|
|
|
outbox_url(page: true, max_id: @statuses.last.id) if @statuses.size == LIMIT
|
2018-05-05 02:19:11 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def prev_page
|
2021-06-01 05:59:30 +09:00
|
|
|
outbox_url(page: true, min_id: @statuses.first.id) unless @statuses.empty?
|
2018-05-05 02:19:11 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_statuses
|
|
|
|
return unless page_requested?
|
|
|
|
|
2024-05-16 17:03:46 +09:00
|
|
|
@statuses = preload_collection_paginated_by_id(
|
2022-03-08 17:14:39 +09:00
|
|
|
AccountStatusesFilter.new(@account, signed_request_account).results,
|
2020-08-28 19:31:56 +09:00
|
|
|
Status,
|
|
|
|
LIMIT,
|
|
|
|
params_slice(:max_id, :min_id, :since_id)
|
|
|
|
)
|
2018-05-05 02:19:11 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def page_requested?
|
2020-05-03 23:30:36 +09:00
|
|
|
truthy_param?(:page)
|
2018-05-05 02:19:11 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def page_params
|
|
|
|
{ page: true, max_id: params[:max_id], min_id: params[:min_id] }.compact
|
2017-07-15 10:01:39 +09:00
|
|
|
end
|
2020-09-03 01:42:50 +09:00
|
|
|
|
|
|
|
def set_account
|
|
|
|
@account = params[:account_username].present? ? Account.find_local!(username_param) : Account.representative
|
|
|
|
end
|
2017-07-15 10:01:39 +09:00
|
|
|
end
|