Closed anderspitman closed 7 months ago
This crate doesnt handle JSON-LD at all, message parsing is left to each application. Instead it mainly takes care of network connections and signatures. In fact you dont need to implement JSON-LD for federation, the Activitypub spec explicitly says that documents can be understood as plain JSON:
That is what Lemmy does, documents are handled as plain JSON using serde. You can see the parsing code here. With serde you can also support fields having different types like single value or array, see these helpers. And in practice it doesnt really matter which possible types the spec assigns to a field, but only what the existing platforms send. In most cases there is only one type used per field.
You could also use the activitystreams crate to parse things properly, but I found it way too verbose and impractical so I abandoned that approach.
@Nutomic sorry this is a super late response but just wanted to say thanks for the helpful reply. I'm back working on the project that prompted the question and this clarified things a lot.
Good to know! What is your project about?
Don't have anything to link you to yet, sorry. Basically I'm experimenting with rendering ActivityPub conversations in different layouts. Since replies
and inReplyTo
can be used to construct a tree, the user should be able to seamlessly switch between linear (twitter, forum, etc), chat (latest at bottom), tree (reddit, HN), or other views depending on the conversation they're looking at.
As mentioned here, part of the difficulty of implementing AP with static languages is that a given JSON-LD property might be a reference (IRI) to an object, or the object itself. The crate docs say:
I'm curious how Lemmy sidesteps this issue. Following along the examples in the docs it seems to assume a given property will always return either an IRI or an object, which doesn't handle the full functionality of AP/JSON-LD according to the specs. Am I missing something here?