Merge pull request #472 from trails-cool/federation/profile-fields-array
fix(journal): actor profile fields must serialize as a JSON array
This commit is contained in:
commit
95b21e2c44
2 changed files with 20 additions and 6 deletions
|
|
@ -95,12 +95,18 @@ describe("actor object", () => {
|
||||||
expect(actor.preferredUsername).toBe("bruno");
|
expect(actor.preferredUsername).toBe("bruno");
|
||||||
expect(actor.name).toBe("Bruno");
|
expect(actor.name).toBe("Bruno");
|
||||||
expect(actor.summary).toBe("Riding bikes");
|
expect(actor.summary).toBe("Riding bikes");
|
||||||
// Profile-metadata field Mastodon renders ("this is a trails profile")
|
// Profile-metadata fields Mastodon renders ("this is a trails
|
||||||
const attachments = Array.isArray(actor.attachment) ? actor.attachment : [actor.attachment];
|
// profile"). MUST serialize as a JSON array — Mastodon's parser
|
||||||
const field = attachments.find((a: { type: string }) => a?.type === "PropertyValue");
|
// silently ignores a bare attachment object, which is what Fedify
|
||||||
expect(field?.name).toBe("🥾 trails.cool");
|
// compacts single-element arrays into (hence two fields).
|
||||||
expect(field?.value).toContain('href="http://localhost:3000/users/bruno"');
|
expect(Array.isArray(actor.attachment)).toBe(true);
|
||||||
expect(field?.value).toContain('rel="me"');
|
const fields = actor.attachment.filter((a: { type: string }) => a?.type === "PropertyValue");
|
||||||
|
expect(fields.length).toBeGreaterThanOrEqual(2);
|
||||||
|
const trails = fields.find((f: { name: string }) => f.name === "🥾 trails.cool");
|
||||||
|
expect(trails?.value).toContain('href="http://localhost:3000/users/bruno"');
|
||||||
|
expect(trails?.value).toContain('rel="me"');
|
||||||
|
const instance = fields.find((f: { name: string }) => f.name === "Instance");
|
||||||
|
expect(instance?.value).toContain("localhost:3000");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("404s the actor for a private user", async () => {
|
it("404s the actor for a private user", async () => {
|
||||||
|
|
|
||||||
|
|
@ -180,11 +180,19 @@ function buildFederation(): Federation<void> {
|
||||||
// metadata table — a human-visible "this is a trails profile"
|
// metadata table — a human-visible "this is a trails profile"
|
||||||
// marker. (The machine-readable marker is NodeInfo; this is
|
// marker. (The machine-readable marker is NodeInfo; this is
|
||||||
// flair.) Mastodon strips most HTML in values but keeps links.
|
// flair.) Mastodon strips most HTML in values but keeps links.
|
||||||
|
// NOTE: Mastodon's parser requires `attachment` to be a JSON
|
||||||
|
// *array* and silently ignores a bare object — and Fedify
|
||||||
|
// compacts single-element arrays to bare objects. Keep at least
|
||||||
|
// two fields here so the array survives serialization.
|
||||||
attachments: [
|
attachments: [
|
||||||
new PropertyValue({
|
new PropertyValue({
|
||||||
name: "🥾 trails.cool",
|
name: "🥾 trails.cool",
|
||||||
value: `<a href="${localActorIri(identifier)}" rel="me">${getOrigin().replace(/^https?:\/\//, "")}/users/${identifier}</a>`,
|
value: `<a href="${localActorIri(identifier)}" rel="me">${getOrigin().replace(/^https?:\/\//, "")}/users/${identifier}</a>`,
|
||||||
}),
|
}),
|
||||||
|
new PropertyValue({
|
||||||
|
name: "Instance",
|
||||||
|
value: `<a href="${getOrigin()}">${getOrigin().replace(/^https?:\/\//, "")}</a>`,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue