Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Version 1.9.5

To be released.

### @fedify/fedify

- Fixed `traverseCollection()` yielding no items when a `Collection` has
an inline `CollectionPage` in its `first` property without an explicit
`id`. This is common in Mastodon's `replies` collections. The function
previously used `collection.firstId` to determine pagination, which
returned `null` for inline pages without an `id`, causing it to
incorrectly fall into the non-paginated branch.


Version 1.9.4
-------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/inline-paged-collection",
"type": "Collection",
"first": {
"type": "CollectionPage",
"partOf": "https://example.com/inline-paged-collection",
"next": "https://example.com/inline-paged/a",
"items": [
{ "type": "Note", "content": "Inline first note" }
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "CollectionPage",
"partOf": "https://example.com/inline-paged-collection",
"items": [
{ "type": "Note", "content": "Inline second note" }
]
}
16 changes: 16 additions & 0 deletions packages/fedify/src/vocab/lookup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertEquals, assertInstanceOf, assertRejects } from "@std/assert";
import fetchMock from "fetch-mock";
import { deepStrictEqual } from "node:assert";
import { mockDocumentLoader } from "../testing/docloader.ts";
import { test } from "../testing/mod.ts";
import { lookupObject, traverseCollection } from "./lookup.ts";
Expand Down Expand Up @@ -260,6 +261,21 @@ test("traverseCollection()", {
new Note({ content: "This is a third simple note" }),
],
);
// Inline-paged collection (CollectionPage embedded without id, with next)
const inlinePagedCollection = await lookupObject(
"https://example.com/inline-paged-collection",
options,
);
assertInstanceOf(inlinePagedCollection, Collection);
deepStrictEqual(
await Array.fromAsync(
traverseCollection(inlinePagedCollection, options),
),
[
new Note({ content: "Inline first note" }),
new Note({ content: "Inline second note" }),
],
);
});

test("FEP-fe34: lookupObject() cross-origin security", {
Expand Down
8 changes: 4 additions & 4 deletions packages/fedify/src/vocab/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ export async function* traverseCollection(
collection: Collection,
options: TraverseCollectionOptions = {},
): AsyncIterable<Object | Link> {
if (collection.firstId == null) {
const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 })
.total("millisecond");
let page = await collection.getFirst(options);
if (page == null) {
for await (const item of collection.getItems(options)) {
yield item;
}
} else {
const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 })
.total("millisecond");
let page = await collection.getFirst(options);
while (page != null) {
for await (const item of page.getItems(options)) {
yield item;
Expand Down
Loading