We have created documentation on how exactly Lemmy federation works

for the benefit of other software, sending an incorrect @context is actually worse than sending no @context at all – all you really need to know is that in a json-ld aware software, the “plain json” property names derive their namespace from the @context property like so:

  • any URI (like https://www.w3.org/ns/activitystreams) gets fetched for a application/ld+json context document (like https://www.w3.org/ns/activitystreams.jsonld); all properties within that document get added to the understood context
  • aliases can be defined by mapping a prefix property to its expanded form, e.g. "as": "https://www.w3.org/ns/activitystreams#" maps the as: prefix to the full URI prefix (you can see this in the context document near the top)

so for example the following are all supposed to be equivalent:

  • Public (when @context includes https://www.w3.org/ns/activitystreams)
  • as:Public (when @context includes "as": "https://www.w3.org/ns/activitystreams#")
  • https://www.w3.org/ns/activitystreams#Public (no @context needed)

the purpose of json-ld normalization is to convert all properties to a fully-qualified URI like https://www.w3.org/ns/activitystreams#Publicthis removes all ambiguity. a json-ld parser would not check for Public, it would check for https://www.w3.org/ns/activitystreams#Public in order to be absolutely sure we both mean “the activitystreams definition of public” and not “some other definition of public”.


as far as lemmy’s @context goes, i see the following issues:

  • "stickied": "as:stickied", implies that stickied exists in the as: namespace, but it does not
    • likewise for "moderators": "as:moderators"
  • "pt": "https://join-lemmy.org#", implies that the pt: namespace is owned by / expands to lemmy’s domain; i assume this is supposed to be peertube
  • "matrixUserId" has a nonsensical id; based on a sample user payload it seems like it just maps to a matrix identifier?

using JSON-LD Playground i came up with the following sample:

  "@context": [
  "https://www.w3.org/ns/activitystreams",
  {
    "pt": "https://joinpeertube.org/ns#",
    "lemmy": "https://join-lemmy.org/ns#",
    "sc": "http://schema.org/",
    "sensitive": "as:sensitive",
    "stickied": {
      "@type": "sc:Boolean",
      "@id": "lemmy:stickied"
    },
    "matrixUserId": {
      "@type": "sc:Text",
      "@id": "lemmy:matrixUserId"
    },
    "commentsEnabled": "pt:commentsEnabled",
    "moderators": {
      "@type": "@id",
      "@id": "lemmy:moderators"
    }
  },
  "https://w3id.org/security/v1"
]

PR here: Fix: Use correctly parseable JSON-LD context by trwnh · Pull Request #2299 · LemmyNet/lemmy · GitHub

3 Likes