Skip to content

Add blurhash term to JSON-LD context#3327

Merged
pfefferle merged 4 commits into
trunkfrom
add/jsonld-blurhash-term
May 20, 2026
Merged

Add blurhash term to JSON-LD context#3327
pfefferle merged 4 commits into
trunkfrom
add/jsonld-blurhash-term

Conversation

@kraftbj
Copy link
Copy Markdown
Contributor

@kraftbj kraftbj commented May 19, 2026

Proposed changes:

  • Adds one entry to the inner array of Activity::JSON_LD_CONTEXT:

    'blurhash' => 'toot:blurhash',

    This maps the blurhash term to Mastodon's toot: namespace (http://joinmastodon.org/ns#) so outbound activities that include a blurhash property on image attachments serialize as strictly correct JSON-LD.

Why

Downstream emitters are starting to ship attachment[].blurhash on outbound image activities so receivers (Mastodon, Pixelfed) can paint a colored-blur placeholder while images load. Real-world consumers read the property by name regardless of context, so it works today without this change — but the JSON-LD path wants the term mapped.

This patch is pure parity with Mastodon: Mastodon coined the property under the toot: namespace and emits exactly this mapping in its own outbound context. No new dependencies, no behavior change for code that doesn't already populate the property.

Use case driving the request: Automattic/fosse#159 (FOSSE adds blurhash to outbound image attachments).

References

  • Mastodon vocab namespace: http://joinmastodon.org/ns#
  • Blurhash spec: https://blurha.sh

Other information:

  • Have you written new tests for your changes, if applicable?

No tests added — the change is a single entry in a class constant. The constant is already covered indirectly by the collections controller tests (Base_Object::JSON_LD_CONTEXT shape assertions), and adding a term doesn't change any existing assertions because those test a different class's constant.

Testing instructions:

  • Inspect an outbound Activity payload (e.g. via the Outbox or by sending a Note with an image attachment to a remote actor) and confirm @context[1].blurhash is present and equals "toot:blurhash".
  • Confirm the rest of the context (https://www.w3.org/ns/activitystreams, toot, QuoteRequest) is unchanged.
  • Optional: emit an attachment with blurhash set on it and verify a JSON-LD validator no longer flags the property as unmapped.

Changelog entry

A changelog entry is included in this PR at .github/changelog/add-jsonld-blurhash-term (significance: patch, type: changed). The "Skip Changelog" label is not needed.

Adds the `blurhash` => `toot:blurhash` mapping to the outbound JSON-LD
context so attachments that include a `blurhash` property are strictly
correct JSON-LD. Mirrors Mastodon's own outbound context shape (Mastodon
coined the property under the `toot:` namespace), so this is pure parity.

Real-world consumers (Mastodon, Pixelfed) read `blurhash` by property name
regardless of context, so the practical effect is JSON-LD correctness for
downstream emitters that already populate the property on image attachments.
Copilot AI review requested due to automatic review settings May 19, 2026 20:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make outbound ActivityPub JSON-LD more semantically correct by adding a blurhash term mapping to the toot: namespace, aligning the plugin’s emitted @context with Mastodon’s vocabulary for image blur placeholders.

Changes:

  • Add blurhash => toot:blurhash to Activity::JSON_LD_CONTEXT.
  • Add a changelog entry documenting the JSON-LD context update.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/activity/class-activity.php Adds blurhash term mapping to the Activity JSON-LD context.
.github/changelog/add-jsonld-blurhash-term Documents the change in the project changelog system.

Comment thread includes/activity/class-activity.php
The prior commit added the `blurhash` => `toot:blurhash` mapping (and
the `toot` namespace) to `Activity::JSON_LD_CONTEXT`, but production
payloads serialize the activity's object and `Activity::get_json_ld_context()`
resolves the emitted context via the object's class constant
(`$class::JSON_LD_CONTEXT`) when an object is present — only falling
back to `static::JSON_LD_CONTEXT` (Activity's own) when there isn't
one. Outbound photo posts always have an object, so the term mapping
on `Activity` was never consulted for them and the `blurhash`
property on `Image` attachments still serialized without a JSON-LD
term declaration.

Add `toot` => `http://joinmastodon.org/ns#` and
`blurhash` => `toot:blurhash` to `Base_Object::JSON_LD_CONTEXT` so the
mapping actually lands in outbound envelopes.

Keep the existing entry on `Activity::JSON_LD_CONTEXT` as defensive
belt-and-suspenders — it costs nothing and remains correct for the
no-object fallback path.
@kraftbj
Copy link
Copy Markdown
Contributor Author

kraftbj commented May 19, 2026

Fix-up commit (368552e) — second adversarial review pointed out the term was on Activity::JSON_LD_CONTEXT, but production envelopes serialize the activity's object and Activity::get_json_ld_context() resolves via the object's class constant (Base_Object::JSON_LD_CONTEXT) whenever an object is present. Applied the same toot namespace and blurhash => toot:blurhash mapping there too, and kept the original entry on Activity as belt-and-suspenders for the no-object fallback path.

The toot/blurhash term additions to Base_Object::JSON_LD_CONTEXT in
the prior commit changed the literal shape of the outbound @context
object, breaking two snapshot-matching tests in Test_Outbox::test_add.

Add the same two terms to the expected JSON in both snapshots so they
match the new context shape exactly. No behavior change — the test
fixtures are the only callers that pinned the literal context bytes.
@pfefferle pfefferle merged commit 31cdcd0 into trunk May 20, 2026
10 checks passed
@pfefferle pfefferle deleted the add/jsonld-blurhash-term branch May 20, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants