Fix serialization of context pages (#37376)

This commit is contained in:
Claire 2026-01-05 12:59:10 +01:00
parent ad4ba5aa00
commit 3013039720
3 changed files with 10 additions and 4 deletions

View file

@ -36,9 +36,8 @@ class ActivityPub::ContextsController < ActivityPub::BaseController
def context_presenter def context_presenter
first_page = ActivityPub::CollectionPresenter.new( first_page = ActivityPub::CollectionPresenter.new(
id: items_context_url(@conversation, page_params),
type: :unordered, type: :unordered,
part_of: items_context_url(@conversation), part_of: context_url(@conversation),
next: next_page, next: next_page,
items: @items.map { |status| status.local? ? ActivityPub::TagManager.instance.uri_for(status) : status.uri } items: @items.map { |status| status.local? ? ActivityPub::TagManager.instance.uri_for(status) : status.uri }
) )
@ -52,7 +51,7 @@ class ActivityPub::ContextsController < ActivityPub::BaseController
page = ActivityPub::CollectionPresenter.new( page = ActivityPub::CollectionPresenter.new(
id: items_context_url(@conversation, page_params), id: items_context_url(@conversation, page_params),
type: :unordered, type: :unordered,
part_of: items_context_url(@conversation), part_of: context_url(@conversation),
next: next_page, next: next_page,
items: @items.map { |status| status.local? ? ActivityPub::TagManager.instance.uri_for(status) : status.uri } items: @items.map { |status| status.local? ? ActivityPub::TagManager.instance.uri_for(status) : status.uri }
) )

View file

@ -3,7 +3,9 @@
class ActivityPub::ContextSerializer < ActivityPub::Serializer class ActivityPub::ContextSerializer < ActivityPub::Serializer
include RoutingHelper include RoutingHelper
attributes :id, :type, :attributed_to, :first attributes :id, :type, :attributed_to
has_one :first, serializer: ActivityPub::CollectionSerializer
def type def type
'Collection' 'Collection'

View file

@ -24,6 +24,11 @@ RSpec.describe 'ActivityPub Contexts' do
expect(response.parsed_body[:type]) expect(response.parsed_body[:type])
.to eq 'Collection' .to eq 'Collection'
expect(response.parsed_body[:first])
.to include(
type: 'CollectionPage',
partOf: context_url(conversation)
)
expect(response.parsed_body[:first][:items]) expect(response.parsed_body[:first][:items])
.to be_an(Array) .to be_an(Array)
.and have_attributes(size: 2) .and have_attributes(size: 2)