Add blurhash term to JSON-LD context#3327
Conversation
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.
There was a problem hiding this comment.
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:blurhashtoActivity::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. |
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.
|
Fix-up commit (368552e) — second adversarial review pointed out the term was on |
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.
Proposed changes:
Adds one entry to the inner array of
Activity::JSON_LD_CONTEXT:This maps the
blurhashterm to Mastodon'stoot:namespace (http://joinmastodon.org/ns#) so outbound activities that include ablurhashproperty on image attachments serialize as strictly correct JSON-LD.Why
Downstream emitters are starting to ship
attachment[].blurhashon 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
blurhashto outbound image attachments).References
http://joinmastodon.org/ns#Other information:
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_CONTEXTshape assertions), and adding a term doesn't change any existing assertions because those test a different class's constant.Testing instructions:
@context[1].blurhashis present and equals"toot:blurhash".https://www.w3.org/ns/activitystreams,toot,QuoteRequest) is unchanged.blurhashset 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.