pana

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2025 License: MPL-2.0 Imports: 15 Imported by: 0

README

Pana

A Go library for building on the Fediverse.

Pana provides everything you need to process and create ActivityStreams messages. These are the kinds of messages that are exchanged between clients and servers on the Fediverse.

The API Pana provides is tailored towards social media style applications. The underlying library, longdistance, can be used for anything that use JSON-LD.

Usage

The Go documentation includes a few examples.

Contributing

PRs are very welcome for:

  • Completing current ActivityStreams types.
  • Fixes to existing types.
  • Adding new object types that are in use on the Fediverse.
  • Documentation improvements.

If you run into a bug, feel free to open up an issue.

License

This library is licensed under the Mozilla Public License Version 2.0.

Documentation

Overview

Package pana can be used to process ActivityStreams messages.

This library is meant to help with implementing fediverse (ActivityPub) clients and servers.

Usage

An application starts with creating a Processor using NewProcessor. This processor should exist for the lifetime of the application, and not a single request.

Incoming messages can then be processed by calling Processor.Unmarshal. This will return an Activity that you can inspect and drill into.

Call Activity.GetType to figure out what type of activity it is. With that information you can then cast the activity to a more specific type which will add new getters and setters for the properties that are set on that activity. You can use Properties to get a set of all properties set on the activity. This lets you handle any property you're interested in.

If an activity has an Object, you can do the same thing. Use Activity.GetObject to get the object. An object may be a reference, or a full object. You can check this with [Object.IsReference]. Once you have a full object, you can use Object.GetType to determine the type and cast it to a more specific type. And you can use Properties to determine the properties set on the object.

Once you've created an Object you wrap it in an Activity and call Processor.Marshal. You can then exchange the resulting JSON using the client-to-server or server-to-server APIs.

If you're going to store ActivityStreams messages, ensure you always store the original you received. Should an implementation bug in Unmarshal result in a problem, you can then always reprocess messages after that's been fixed. But if you store a potentially incorrectly unmarshalled document you may not be able to return to its original form even if you retain the context.

JSON-LD

ActivityStreams uses JSON-LD for its JSON serialisatoin format. Pana doesn't hide this from you, but aims to provide an API that makes working with this simple enough so that you don't have to think about it.

Pana's Unmarshal converts a document to JSON-LD Expanded Document Form. The Marshal method does the opposite, converting to JSON-LD Compacted Document Form.

In JSON-LD all properties, with the exception of 'id' / '@id', are arrays. But if an array only has a single etnry it's typically reduced to its member. This distinction is removed in expanded document form, but it makes the resulting Object a bit verbose to handle.

API

The API Pana exposes is meant to do the right thing for you in 99.9% of cases. Its API is based on what properties are used in practice across the fediverse, and what their values are. This is a more restrictive subset of what the ActivityStreams specification allows for. Pana does this on purpose to guide you towards maximal interoperability with other, potentially JSON-LD unaware, implementations.

For any proprety, you'll either have:

  • GetXXX and SetXXX for single-valued properties. These will accept and return strings or encoding/json.RawMessage.
  • GetXXX and AddXXX for multi-valued properties. Get will return an iter.Seq, and Add will be variadic. Add appends so can be called multiple times too.

Most value properties return encoding/json.RawMessage. You can look at the JSON-LD context definition to determine what the type of the value should be. This will also be part of the vocabulary documentation for the property you're retrieving. However, remember that this is not enforced, so even if a property is defined as a number it can hold a boolean.

All types in Pana are a code.dny.dev/longdistance.Node. This struct type has exported fields for every JSON-LD keyword, as well as a catch-all Properties field for all other properties. You can directly manipulate any of these, but at that point you're responsible for ensuring you create valid JSON-LD nodes that will compact to a representation non-JSON-LD aware processors will understand. In order to Get, Add or Set properties you need to use the IRI a property maps to. This is part of what the JSON-LD context defines. The code.dny.dev/pana/vocab packages provide the necessary consts.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Has

func Has[T ld.Internal](in *T, property string) bool

Has checks if an object has a specific property set.

It handles JSON-LD keyword aliasses for id and type.

func IsObjec

func IsObjec[T ld.Internal](in *T) bool

IsObject indicates if this object is a (partially) complete object.

This means it has an ID, optionally a Type and at least one other property. It doesn't mean the object representation is complete, and you may need to retrieve the object using the ID to get additional properties.

func IsReference

func IsReference[T ld.Internal](in *T) bool

IsReference indicates if this object is a reference.

This means it only has the ID, and optionally a Type, set. You'll need to retrieve the object using the ID to get additional properties.

func Properties

func Properties[T ld.Internal](in *T) map[string]struct{}

Properties returns a set with an entry for each property set on an object.

It handles JSON-LD keyword aliasses for id and type.

Types

type Accept

type Accept = Activity

Accept is the Accept activity.

func NewAccept

func NewAccept() *Accept

NewAccept initialises a new Accept activity with as.TypeAccept.

type Activity

type Activity Object

Activity is the ActivityStreams Activity type.

This is a more limited view of Object with property getters and setters for the properties that are commonly set on the toplevel activity.

func NewActivity

func NewActivity() *Activity

NewActivity initialises a new activity.

It's initialised with as.TypeCreate. Use Activity.SetType to override it.

func (*Activity) AddActor

func (a *Activity) AddActor(ids ...string) *Activity

AddActor appends actor IDs to as.Actor.

func (*Activity) AddCc

func (a *Activity) AddCc(ids ...string) *Activity

See Object.AddCc.

func (*Activity) AddTo

func (a *Activity) AddTo(ids ...string) *Activity

See Object.AddTo.

func (*Activity) AsAny

func (a *Activity) AsAny() *Any

AsAny casts to Any which is accepted by package helper functions.

func (*Activity) Build

func (a *Activity) Build() Activity

Build finalises the Activity.

func (*Activity) GetActor

func (a *Activity) GetActor() iter.Seq[string]

GetActor returns the actor IDs from as.Actor.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor.

func (*Activity) GetCc

func (a *Activity) GetCc() iter.Seq[string]

See Object.GetCc.

func (*Activity) GetID

func (a *Activity) GetID() string

See Object.GetID.

func (*Activity) GetInstrument

func (a *Activity) GetInstrument() *Instrument

GetInstrument returns the instrument in as.Instrument.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument.

func (*Activity) GetObject

func (a *Activity) GetObject() *Any

GetObject returns the object in as.Object.

This returns as.Any because it can be of many different types. If the Any.GetType doesn't match any known type you can cast it to Object.

https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object.

func (*Activity) GetPublished

func (a *Activity) GetPublished() json.RawMessage

See Object.GetPublished.

func (*Activity) GetTarget

func (a *Activity) GetTarget() string

GetTarget returns the ID in as.Target.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target.

func (*Activity) GetTo

func (a *Activity) GetTo() iter.Seq[string]

See Object.GetTo.

func (*Activity) GetType

func (a *Activity) GetType() string

See Object.GetType.

func (*Activity) IsIntransitive

func (a *Activity) IsIntransitive() bool

IsIntransitive returns true if the activity has no object.

func (*Activity) SetID

func (a *Activity) SetID(id string) *Activity

See Object.SetID.

func (*Activity) SetInstrument

func (a *Activity) SetInstrument(in Instrument) *Activity

SetInstrument sets the instrument in as.Instrument.

func (*Activity) SetObject

func (a *Activity) SetObject(obj Any) *Activity

SetObject sets the object in as.Object.

It is possible to have more than one object. However, except for JSON-LD aware processors, nobody understands this. If you want to send multiple objects, send multiple activities instead.

func (*Activity) SetPublished

func (a *Activity) SetPublished(v json.RawMessage) *Activity

See Object.SetPublished.

func (*Activity) SetTarget

func (a *Activity) SetTarget(id string) *Activity

SetTarget sets the ID in as.Target.

func (*Activity) SetType

func (a *Activity) SetType(typ string) *Activity

See Object.SetType.

type Actor

type Actor Object

Actor is the ActivityStreams Actor type.

See https://www.w3.org/TR/activitypub/#actor-objects.

func NewActor

func NewActor() *Actor

NewActor initialises a new Actor.

func (*Actor) AddName

func (a *Actor) AddName(ls ...Localised) *Actor

See Object.AddName.

func (*Actor) AddSummary

func (a *Actor) AddSummary(ls ...Localised) *Actor

See Object.AddSummary.

func (*Actor) Build

func (a *Actor) Build() Any

Build finalises the Actor.

This returns Any since that's what Activity.SetObject expects.

func (*Actor) GetDiscoverable

func (a *Actor) GetDiscoverable() json.RawMessage

GetDiscoverable returns the value in mastodon.Discoverable.

When discoverable is absent this returns false. We treat discoverable as opt-in, not opt-out.

See https://docs.joinmastodon.org/spec/activitypub/#toot.

func (*Actor) GetEndpoints

func (a *Actor) GetEndpoints() *Endpoints

GetEndpoints returns the Endpoints from as.Endpoints.

func (*Actor) GetFeatured

func (a *Actor) GetFeatured() *Collection

GetFeatured returns the Collection stored in mastodon.Featured.

See https://docs.joinmastodon.org/spec/activitypub/#toot.

func (*Actor) GetFeaturedTags

func (a *Actor) GetFeaturedTags() *Collection

GetFeaturedTags returns the Collection stored in mastodon.FeaturedTags.

See https://docs.joinmastodon.org/spec/activitypub/#toot.

func (*Actor) GetFollowers

func (a *Actor) GetFollowers() *Collection

GetFollowers returns the Collection stored in as.Followers.

See https://www.w3.org/TR/activitypub/#followers.

func (*Actor) GetFollowing

func (a *Actor) GetFollowing() *Collection

GetFollowing returns the Collection stored in as.Following.

See https://www.w3.org/TR/activitypub/#following.

func (*Actor) GetIcon

func (a *Actor) GetIcon() *Image

GetIcon returns the Image in as.Icon.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon.

func (*Actor) GetImage

func (a *Actor) GetImage() *Image

GetImage returns the Image in as.Image.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image.

func (*Actor) GetInbox

func (a *Actor) GetInbox() string

GetIndox returns the URL in ldp.Inbox.

func (*Actor) GetIndexable

func (a *Actor) GetIndexable() json.RawMessage

GetIndexable returns the value in mastodon.Indexable.

When discoverable is absent this returns false. We treat indexable as opt-in, not opt-out.

See https://docs.joinmastodon.org/spec/activitypub/#toot.

func (*Actor) GetLiked

func (a *Actor) GetLiked() *Collection

GetLiked returns the Collection stored in as.Liked.

See https://www.w3.org/TR/activitypub/#liked.

func (*Actor) GetManuallyApprovesFollowers

func (a *Actor) GetManuallyApprovesFollowers() json.RawMessage

GetManuallyApprovesFollowers returns the value in as.ManuallyApprovesFollowers.

See https://swicg.github.io/miscellany/#manuallyApprovesFollowers.

func (*Actor) GetMemorial

func (a *Actor) GetMemorial() json.RawMessage

GetMemorial returns the value in mastodon.Memorial.

It returns false if the property was absent.

func (*Actor) GetMovedTo

func (a *Actor) GetMovedTo() string

GetMovedTo returns the URL from as.MovedTo.

See https://swicg.github.io/miscellany/#movedTo.

func (*Actor) GetName

func (a *Actor) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Actor) GetOutbox

func (a *Actor) GetOutbox() string

GetIndox returns the URL in as.Outbox.

func (*Actor) GetPreferredUsername

func (a *Actor) GetPreferredUsername() json.RawMessage

GetPreferredUsername returns the value in as.PreferredUsername.

See https://www.w3.org/TR/activitypub/#actor-objects.

func (*Actor) GetPublicKey

func (a *Actor) GetPublicKey() *PublicKey

GetPublickKey returns the PublicKey stored in secv1.PublicKey.

func (*Actor) GetPublished

func (a *Actor) GetPublished() json.RawMessage

See Object.GetPublished.

func (*Actor) GetSummary

func (a *Actor) GetSummary() iter.Seq[*Localised]

See Object.GetSummary.

func (*Actor) GetType

func (a *Actor) GetType() string

See Object.GetType.

func (*Actor) GetURL

func (a *Actor) GetURL() string

See Object.GetURL.

func (*Actor) SetDiscoverable

func (a *Actor) SetDiscoverable(v json.RawMessage) *Actor

SetDiscoverable sets the value in mastodon.Discoverable.

func (*Actor) SetEndpoints

func (a *Actor) SetEndpoints(ep Endpoints) *Actor

SetEndpoints sets the Endpoints in as.Endpoints.

func (*Actor) SetFeatured

func (a *Actor) SetFeatured(c Collection) *Actor

SetFeatured sets the Collection in mastodon.Featured.

func (*Actor) SetFeaturedTags

func (a *Actor) SetFeaturedTags(c Collection) *Actor

SetFeaturedTags sets the Collection in mastodon.FeaturedTags.

func (*Actor) SetFollowers

func (a *Actor) SetFollowers(c Collection) *Actor

SetFollowers sets the Collection in as.Followers.

func (*Actor) SetFollowing

func (a *Actor) SetFollowing(c Collection) *Actor

SetFollowing sets the Collection in as.Following.

func (*Actor) SetIcon

func (a *Actor) SetIcon(img Image) *Actor

SetIcon sets the Image in as.Icon.

func (*Actor) SetImage

func (a *Actor) SetImage(img Image) *Actor

SetImage sets the Image in as.Image.

func (*Actor) SetInbox

func (a *Actor) SetInbox(url string) *Actor

SetInbox sets the URL in ldp.Inbox.

func (*Actor) SetIndexable

func (a *Actor) SetIndexable(v json.RawMessage) *Actor

SetIndexable sets the value in mastodon.Indexable.

func (*Actor) SetLiked

func (a *Actor) SetLiked(c Collection) *Actor

SetLiked sets the Collection in as.Liked.

func (*Actor) SetManuallyApprovesFollowers

func (a *Actor) SetManuallyApprovesFollowers(v json.RawMessage) *Actor

SetManuallyApprovesFollowers sets the value in as.ManuallyApprovesFollowers.

func (*Actor) SetMemorial

func (a *Actor) SetMemorial(v json.RawMessage) *Actor

SetMemorial sets the value in mastodon.Memorial.

func (*Actor) SetMovedTo

func (a *Actor) SetMovedTo(url string) *Actor

SetMovedTo sets the URL in as.MovedTo.

func (*Actor) SetOutbox

func (a *Actor) SetOutbox(url string) *Actor

SetOutbox sets the URL in as.Outbox.

func (*Actor) SetPreferredUsername

func (a *Actor) SetPreferredUsername(v json.RawMessage) *Actor

SetPreferredUsername sets the value in as.PreferredUsername.

func (*Actor) SetPublicKey

func (a *Actor) SetPublicKey(pk PublicKey) *Actor

SetPublicKey sets the PublicKey in secv1.PublicKey.

func (*Actor) SetPublished

func (a *Actor) SetPublished(v json.RawMessage) *Actor

See Object.SetPublished.

func (*Actor) SetType

func (a *Actor) SetType(typ string) *Actor

See Object.SetType.

func (*Actor) SetURL

func (a *Actor) SetURL(url string) *Actor

See Object.SetURL.

type Add

type Add = Activity

func NewAdd

func NewAdd() *Add

NewAdd initialises a new Add activity with as.TypeAdd.

type Announce

type Announce = Activity

func NewAnnounce

func NewAnnounce() *Announce

NewAnnounce initialises a new Announce activity with as.TypeAnnounce.

type Any

type Any ld.Node

Any is returned when a property can return Link or Object.

You can use Any.GetType to determine what to cast it to.

func (*Any) GetType

func (a *Any) GetType() string

See Object.GetType.

type Application

type Application = Actor

type Article

type Article Object

Article is the ActivityStreams Article type.

func NewArticle

func NewArticle() *Article

NewArticle initialises a new Article.

func (*Article) Build

func (a *Article) Build() Any

Build finalises the Article.

This returns Any since that's what Activity.SetObject expects.

type Audio

type Audio Document

Audio is the ActivityStreams Audio type.

It is a Document without width/height but with duration.

func NewAudio

func NewAudio() *Audio

NewAudio initialises a new Audio.

func (*Audio) AddName

func (a *Audio) AddName(ls ...Localised) *Audio

See Object.AddName.

func (*Audio) Build

func (a *Audio) Build() Audio

Build finalises the Audio.

func (*Audio) GetDuration

func (a *Audio) GetDuration() json.RawMessage

GetDuration returns the value in as.Duration.

func (*Audio) GetMediaType

func (a *Audio) GetMediaType() json.RawMessage

GetMediaType returns the value in as.MediaType.

func (*Audio) GetName

func (a *Audio) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Audio) GetType

func (a *Audio) GetType() string

See Object.GetType.

func (*Audio) GetURL

func (a *Audio) GetURL() string

See Object.GetURL.

func (*Audio) SetDuration

func (a *Audio) SetDuration(v json.RawMessage) *Audio

SetDuration sets the value in as.Duration.

func (*Audio) SetMediaType

func (a *Audio) SetMediaType(v json.RawMessage) *Audio

SetMediaType sets the value in as.MediaType.

func (*Audio) SetType

func (a *Audio) SetType(typ string) *Audio

See Object.SetType.

func (*Audio) SetURL

func (a *Audio) SetURL(url string) *Audio

See Object.SetURL.

type Block

type Block = Activity

func NewBlock

func NewBlock() *Block

NewBlock initialises a new Block activity with as.TypeBlock.

type Choice

type Choice Note

Choice represents a choice in a poll. It is a much more limited Note.

func NewChoice

func NewChoice() *Choice

NewChoice initialises a new Choice.

func (*Choice) AddName

func (c *Choice) AddName(ls ...Localised) *Choice

See Object.AddName.

func (*Choice) Build

func (c *Choice) Build() Choice

Build finalises the Choice.

func (*Choice) GetName

func (c *Choice) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Choice) GetReplies

func (c *Choice) GetReplies() *Collection

See Object.GetReplies.

func (*Choice) SetReplies

func (c *Choice) SetReplies(cl Collection) *Choice

See Object.SetReplies.

type Collection

type Collection Object

Collection is the ActivityStreams Collection type.

It is also used for the OrderedCollection. Use [Collection.IsOrdered] to see, or Collection.GetType.

func NewCollection

func NewCollection() *Collection

NewCollection initialises a new Collection.

func (*Collection) Build

func (c *Collection) Build() Collection

Build finalises the Collection.

func (*Collection) GetFirst

func (c *Collection) GetFirst() *CollectionPage

GetFirst returns the CollectionPage in as.First.

func (*Collection) GetID

func (c *Collection) GetID() string

See Object.GetID.

func (*Collection) GetTotalItems

func (c *Collection) GetTotalItems() json.RawMessage

GetTotalItems returns the value from as.TotalItems

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-totalitems.

func (*Collection) GetType

func (c *Collection) GetType() string

See Object.GetType.

func (*Collection) SetFirst

func (c *Collection) SetFirst(p CollectionPage) *Collection

SetFirst sets the CollectionPage in as.First.

func (*Collection) SetID

func (c *Collection) SetID(id string) *Collection

See Object.SetID.

func (*Collection) SetTotalItems

func (c *Collection) SetTotalItems(v json.RawMessage) *Collection

SetTotalItems sets the value in as.TotalItems.

func (*Collection) SetType

func (c *Collection) SetType(typ string) *Collection

See Object.SetType.

type CollectionPage

type CollectionPage Object

CollectionPage is the ActivityStreams CollectionPage type.

It is also used for the OrderedCollectionPage. Use [CollectionPage.IsOrdered] to see, or CollectionPage.GetType.

func NewCollectionPage

func NewCollectionPage() *CollectionPage

NewCollectionPage initialises a new CollectionPage.

func (*CollectionPage) Build

func (p *CollectionPage) Build() CollectionPage

Build finalises the CollectionPage.

func (*CollectionPage) GetNext

func (p *CollectionPage) GetNext() string

GetNext returns the URL stored in as.Next.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-next.

func (*CollectionPage) GetPartOf

func (p *CollectionPage) GetPartOf() string

GetPartOf returns the URL stored in as.PartOf.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-partof.

func (*CollectionPage) GetPrev

func (p *CollectionPage) GetPrev() string

GetPrev returns the URL stored in as.Prev.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-prev.

func (*CollectionPage) GetType

func (p *CollectionPage) GetType() string

See Object.GetType.

func (*CollectionPage) SetNext

func (p *CollectionPage) SetNext(url string) *CollectionPage

SetNext sets the URL in as.Next.

func (*CollectionPage) SetPartOf

func (p *CollectionPage) SetPartOf(url string) *CollectionPage

SetPartOf sets the URL in as.PartOf.

func (*CollectionPage) SetPrev

func (p *CollectionPage) SetPrev(url string) *CollectionPage

SetPrev sets the URL in as.Prev.

func (*CollectionPage) SetType

func (p *CollectionPage) SetType(typ string) *CollectionPage

See Object.SetType.

type Create

type Create = Activity

func NewCreate

func NewCreate() *Create

NewCreate initialises a new Create activity with as.TypeCreate.

type Delete

type Delete = Activity

func NewDelete

func NewDelete() *Delete

NewDelete initialises a new Delete activity with as.TypeDelete.

type Document

type Document Object

Document is the ActivityStreams Document type.

It shares all properties with Link.

func NewDocument

func NewDocument() *Document

NewDocument initialises a new Document.

func (*Document) AddName

func (d *Document) AddName(ls ...Localised) *Document

See Object.AddName.

func (*Document) Build

func (d *Document) Build() Document

Build finalises the Document.

func (*Document) GetBlurhash

func (d *Document) GetBlurhash() json.RawMessage

GetBlurhash returns the value in mastodon.Blurhash.

func (*Document) GetDuration

func (d *Document) GetDuration() json.RawMessage

GetDuration returns the value in as.Duration.

func (*Document) GetFocalPoint

func (d *Document) GetFocalPoint() []json.RawMessage

GetFocalPoint returns the value in mastodon.FocalPoint.

func (*Document) GetHeight

func (d *Document) GetHeight() json.RawMessage

GetHeight returns the value in as.Height.

func (*Document) GetMediaType

func (d *Document) GetMediaType() json.RawMessage

GetMediaType returns the value in as.MediaType.

func (*Document) GetName

func (d *Document) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Document) GetType

func (d *Document) GetType() string

See Object.GetType.

func (*Document) GetURL

func (d *Document) GetURL() string

See Object.GetURL.

func (*Document) GetWidth

func (d *Document) GetWidth() json.RawMessage

GetWidth returns the value in as.Width.

func (*Document) SetBlurhash

func (d *Document) SetBlurhash(v json.RawMessage) *Document

SetBlurhash sets the value in mastodon.Blurhash.

func (*Document) SetDuration

func (d *Document) SetDuration(v json.RawMessage) *Document

SetDuration sets the value in as.Duration.

func (*Document) SetFocalPoint

func (d *Document) SetFocalPoint(x, y json.RawMessage) *Document

SetFocalPoint sets the value in mastodon.FocalPoint.

func (*Document) SetHeight

func (d *Document) SetHeight(v json.RawMessage) *Document

SetHeight sets the value in as.Height.

func (*Document) SetMediaType

func (d *Document) SetMediaType(v json.RawMessage) *Document

SetMediaType sets the value in as.MediaType.

func (*Document) SetType

func (d *Document) SetType(typ string) *Document

See Object.SetType.

func (*Document) SetURL

func (d *Document) SetURL(url string) *Document

See Object.SetURL.

func (*Document) SetWidth

func (d *Document) SetWidth(v json.RawMessage) *Document

SetWidth sets the value in as.Width.

type Emoji

type Emoji Object

func NewEmoji

func NewEmoji() *Emoji

NewEmoji initialises a new Emoji.

func (*Emoji) AddName

func (e *Emoji) AddName(ls ...Localised) *Emoji

See [Object.SetName].

func (*Emoji) Build

func (e *Emoji) Build() Emoji

Build finalises the Emoji.

func (*Emoji) GetID

func (e *Emoji) GetID() string

See Object.GetID.

Beware that Emoji's might not have an ID. This is used for instance-local emoji.

func (*Emoji) GetIcon

func (e *Emoji) GetIcon() *Icon

GetIcon returns the Image in as.Icon.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon.

func (*Emoji) GetName

func (e *Emoji) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Emoji) GetType

func (e *Emoji) GetType() string

See Object.GetType.

func (*Emoji) GetUpdated

func (e *Emoji) GetUpdated() json.RawMessage

See Object.GetUpdated.

func (*Emoji) SetID

func (e *Emoji) SetID(id string) *Emoji

See Object.SetID.

func (*Emoji) SetIcon

func (e *Emoji) SetIcon(img Icon) *Emoji

SetIcon sets the Image in as.Icon.

func (*Emoji) SetType

func (e *Emoji) SetType() *Emoji

See Object.SetType.

func (*Emoji) SetUpdated

func (e *Emoji) SetUpdated(v json.RawMessage) *Emoji

See Object.SetUpdated.

type EmojiReact

type EmojiReact = Activity

func NewEmojiReact

func NewEmojiReact() *EmojiReact

NewEmojiReact initialises a new EmojiReact activity with litepub.TypeEmojiReact.

type Endpoints

type Endpoints ld.Node

Endpoints from ActivityPub.

Endpoints does not include support for as.ProvideClientKey or as.SignClientKey because Linked Data Signatures are a menace and should not be used. Use HTTP Signatures instead.

See https://www.w3.org/TR/activitypub/#actor-objects.

func NewEndpoints

func NewEndpoints() *Endpoints

NewEndpoints initialises a new Endpoints.

func (*Endpoints) Build

func (ep *Endpoints) Build() Endpoints

Build finalises the Endpoints.

func (*Endpoints) GetOauthAuthzEndpoint

func (ep *Endpoints) GetOauthAuthzEndpoint() string

GetOauthAuthzEndpoint returns the URL in as.OauthAuthzEndpoint.

func (*Endpoints) GetOauthTokenEndpoint

func (ep *Endpoints) GetOauthTokenEndpoint() string

GetOauthTokenEndpoint returns the URL in as.OauthTokenEndpoint.

func (*Endpoints) GetProxyURL

func (ep *Endpoints) GetProxyURL() string

GetProxyURL returns the URL in as.ProxyURL.

func (*Endpoints) GetSharedInbox

func (ep *Endpoints) GetSharedInbox() string

GetSharedInbox returns the URL in as.SharedInbox.

func (*Endpoints) SetOauthAuthzEndpoint

func (ep *Endpoints) SetOauthAuthzEndpoint(url string) *Endpoints

SetOauthAuthzEndpoint sets the URL in as.OauthAuthzEndpoint.

func (*Endpoints) SetOauthTokenEndpoint

func (ep *Endpoints) SetOauthTokenEndpoint(url string) *Endpoints

SetOauthTokenEndpoint sets the URL in as.OauthTokenEndpoint.

func (*Endpoints) SetProxyURL

func (ep *Endpoints) SetProxyURL(url string) *Endpoints

SetProxyURL sets the URL in as.ProxyURL.

func (*Endpoints) SetSharedInbox

func (ep *Endpoints) SetSharedInbox(url string) *Endpoints

SetSharedInbox sets the URL in as.SharedInbox.

type Event

type Event Object

Event is the Activitystreams Event type.

func NewEvent

func NewEvent() *Event

NewEvent initialises a new Event.

func (*Event) Build

func (e *Event) Build() Any

Build finalises the Event.

This returns Any since that's what Activity.SetObject expects.

type Follow

type Follow = Activity

func NewFollow

func NewFollow() *Follow

NewFollow initialises a new Follow activity with as.TypeFollow.

type Group

type Group = Actor

type Hashtag

type Hashtag = LinkTag

Hashtag is the ActivityStreams Hashtag.

func NewHashtag

func NewHashtag() *Hashtag

NewHashtag initialises a new Hashtag.

type Icon

type Icon Image

Icon is a more constrained version of Image used with as.Icon.

func NewIcon

func NewIcon() *Icon

NewIcon initialises a new Icon.

func (*Icon) Build

func (i *Icon) Build() Icon

Build finalises the Icon.

func (*Icon) GetMediaType

func (i *Icon) GetMediaType() json.RawMessage

GetMediaType returns the value in as.MediaType.

func (*Icon) GetType

func (i *Icon) GetType() string

See Object.GetType.

func (*Icon) GetURL

func (i *Icon) GetURL() string

See Object.GetURL.

func (*Icon) SetMediaType

func (i *Icon) SetMediaType(v json.RawMessage) *Icon

SetMediaType sets the value in as.MediaType.

func (*Icon) SetType

func (i *Icon) SetType() *Icon

See Object.SetType.

func (*Icon) SetURL

func (i *Icon) SetURL(url string) *Icon

See Object.SetURL.

type Image

type Image = Document

Image is the ActivityStreams Image type.

It shares all properties with Document.

func NewImage

func NewImage() *Image

type Instrument

type Instrument Object

func NewInstrument

func NewInstrument() *Instrument

NewInstrument initialises a new Instrument.

func (*Instrument) Build

func (i *Instrument) Build() Instrument

Build finalises the Instrument.

type IntransitiveActivity

type IntransitiveActivity = Object

IntransitiveActivity is the ActivityStreams Intransitive Activity type.

It's aliassed to Object because that's basically what it is. In practice this is rarely if ever used. Polls are modelled as Create Question, even though Question is intransitive.

type Like

type Like = Activity

func NewLike

func NewLike() *Like

NewLike initialises a new Like activity with as.TypeLike.

type Link ld.Node

Link is the ActivityStreams Link type.

Though Link can have an ID, this never happens in practice because the target of a link is stored in as.Href instead.

func NewLink() *Link

NewLink initialises a new Link.

func (*Link) AddName

func (l *Link) AddName(ls ...Localised) *Link

SetName sets a value in as.Name.

func (*Link) Build

func (l *Link) Build() Link

Build finalises the Link.

func (*Link) GetHeight

func (l *Link) GetHeight() json.RawMessage

GetHeight returns the value from as.Height.

func (*Link) GetHref

func (l *Link) GetHref() string

GetHref returns the value from as.Href.

func (*Link) GetHreflang

func (l *Link) GetHreflang() json.RawMessage

GetHreflang returns the value from as.Hreflang.

func (*Link) GetMediaType

func (l *Link) GetMediaType() json.RawMessage

GetMediaType returns the value from as.MediaType.

func (*Link) GetName

func (l *Link) GetName() iter.Seq[*Localised]

GetName returns the value from as.Name.

func (*Link) GetRel

func (l *Link) GetRel() json.RawMessage

GetRel returns the value from as.Rel.

func (*Link) GetType

func (l *Link) GetType() string

See Object.GetType.

This will most commonly be one of:

You'll probably want to use LinkTag for Mention and Hashtag.

func (*Link) GetWidth

func (l *Link) GetWidth() json.RawMessage

GetWidth returns the value from as.Width.

func (*Link) SetHeight

func (l *Link) SetHeight(height json.RawMessage) *Link

SetHeight sets a value in as.Height.

func (*Link) SetHref

func (l *Link) SetHref(url string) *Link

SetHref sets a URL in as.Href.

func (*Link) SetHreflang

func (l *Link) SetHreflang(hreflang json.RawMessage) *Link

SetHreflang sets a value in as.Hreflang.

func (*Link) SetMediaType

func (l *Link) SetMediaType(mediaType json.RawMessage) *Link

SetMediaType sets a value in as.MediaType.

func (*Link) SetRel

func (l *Link) SetRel(rel json.RawMessage) *Link

SetRel sets a value in as.Rel.

func (*Link) SetType

func (l *Link) SetType(t string) *Link

See Object.SetType.

func (*Link) SetWidth

func (l *Link) SetWidth(width json.RawMessage) *Link

SetWidth sets a value in as.Width.

type LinkTag

type LinkTag Link

LinkTag is a more constrained version of Link that is used in as.Tag.

It's usually used to represent hashtags and mentions.

func NewLinkTag

func NewLinkTag() *LinkTag

func (*LinkTag) AddName

func (l *LinkTag) AddName(ls ...Localised) *LinkTag

See Link.AddName.

func (*LinkTag) GetHref

func (l *LinkTag) GetHref() string

See Link.GetHref

func (*LinkTag) GetName

func (l *LinkTag) GetName() iter.Seq[*Localised]

See Link.GetName.

func (*LinkTag) GetType

func (l *LinkTag) GetType() string

See Link.GetType.

func (*LinkTag) SetHref

func (l *LinkTag) SetHref(url string) *LinkTag

See Link.SetHref.

func (*LinkTag) SetType

func (l *LinkTag) SetType(t string) *LinkTag

See Link.SetType.

type Localised

type Localised ld.Node

Localised represents a value with an optional language tag and direction.

It mirrors a language-mapped attribute in JSON-LD.

func NewLocalised

func NewLocalised() *Localised

NewLocalised initialises a new Localised.

func (*Localised) Build

func (l *Localised) Build() Localised

Build finalises the Localised.

func (*Localised) GetLanguage

func (l *Localised) GetLanguage() string

GetLanguage returns a normalised to lower-case BCP-47 language tag.

The empty string indicates that the language is unknown, not English.

func (*Localised) GetValue

func (l *Localised) GetValue() json.RawMessage

GetValue returns the value.

func (*Localised) SetLanguage

func (l *Localised) SetLanguage(lang string) *Localised

SetLanguage sets the language tag for the value.

This must be a valid BCP-47 language tag and may be normalised to lower-case.

func (*Localised) SetValue

func (l *Localised) SetValue(value json.RawMessage) *Localised

SetValue sets the value.

type Localized

type Localized = Localised

type Mention

type Mention = LinkTag

Mention is the ActivityStreams Mention.

func NewMention

func NewMention() *Mention

NewMention initialises a new Mention.

type Move

type Move = Activity

func NewMove

func NewMove() *Move

NewMove initialises a new Move activity with as.TypeMove.

type Note

type Note Object

Note is the ActivityStreams Note type.

func NewNote

func NewNote() *Note

NewNote initialises a new Note.

func (*Note) AddActor

func (n *Note) AddActor(ids ...string) *Note

See Activity.AddActor.

func (*Note) AddAttachment

func (n *Note) AddAttachment(atch ...Any) *Note

See Object.AddAttachment.

func (*Note) AddAttributedTo

func (n *Note) AddAttributedTo(ids ...string) *Note

See Object.AddAttributedTo.

func (*Note) AddCc

func (n *Note) AddCc(ids ...string) *Note

See Object.AddCc.

func (*Note) AddContent

func (n *Note) AddContent(ls ...Localised) *Note

See Object.AddContent.

func (*Note) AddSummary

func (n *Note) AddSummary(ls ...Localised) *Note

See Object.AddSummary.

func (*Note) AddTag

func (n *Note) AddTag(tags ...Any) *Note

See Object.AddTag.

func (*Note) AddTo

func (n *Note) AddTo(ids ...string) *Note

See Object.AddTo.

func (*Note) Build

func (n *Note) Build() Any

Build finalises the Note.

This returns Any since that's what Activity.SetObject expects.

func (*Note) GetActor

func (n *Note) GetActor() iter.Seq[string]

See Activity.GetActor.

func (*Note) GetAtomURI

func (n *Note) GetAtomURI() string

See Object.GetAtomURI.

func (*Note) GetAttachment

func (n *Note) GetAttachment() iter.Seq[*Any]

See Object.GetAttachment.

func (*Note) GetAttributedTo

func (n *Note) GetAttributedTo() iter.Seq[string]

See Object.GetAttributedTo.

func (*Note) GetCc

func (n *Note) GetCc() iter.Seq[string]

See Object.GetCc.

func (*Note) GetContent

func (n *Note) GetContent() iter.Seq[*Localised]

See Object.GetContent.

func (*Note) GetContext

func (n *Note) GetContext() string

See Object.GetContext.

func (*Note) GetConversation

func (n *Note) GetConversation() string

See Object.GetConversation.

func (*Note) GetDirectMessage

func (n *Note) GetDirectMessage() json.RawMessage

GetDirectMessage returns the value in litepub.DirectMessage.

It returns false if the value is absent.

func (*Note) GetID

func (n *Note) GetID() string

See Object.GetID.

func (*Note) GetInReplyTo

func (n *Note) GetInReplyTo() string

See Object.GetInReplyTo.

func (*Note) GetInReplyToAtomURI

func (n *Note) GetInReplyToAtomURI() string

See Object.GetInReplyToAtomURI.

func (*Note) GetLikes

func (n *Note) GetLikes() *Collection

See Object.GetLikes.

func (*Note) GetPublished

func (n *Note) GetPublished() json.RawMessage

See Object.GetPublished.

func (*Note) GetReplies

func (n *Note) GetReplies() *Collection

See Object.GetReplies.

func (*Note) GetSensitive

func (n *Note) GetSensitive() json.RawMessage

See Object.GetSensitive.

func (*Note) GetShares

func (n *Note) GetShares() *Collection

See Object.GetShares.

func (*Note) GetSummary

func (n *Note) GetSummary() iter.Seq[*Localised]

See Object.GetSummary.

func (*Note) GetTag

func (n *Note) GetTag() iter.Seq[*Any]

See Object.GetTag.

func (*Note) GetTo

func (n *Note) GetTo() iter.Seq[string]

See Object.GetTo.

func (*Note) GetType

func (n *Note) GetType() string

See Object.GetType.

func (*Note) GetURL

func (n *Note) GetURL() string

See Object.GetURL.

func (*Note) GetUpdated

func (n *Note) GetUpdated() json.RawMessage

See Object.GetUpdated.

func (*Note) SetAtomURI

func (n *Note) SetAtomURI(uri string) *Note

See Object.SetAtomURI.

func (*Note) SetContext

func (n *Note) SetContext(id string) *Note

See Object.SetContext.

func (*Note) SetConversation

func (n *Note) SetConversation(id string) *Note

See Object.SetConversation.

func (*Note) SetDirectMessage

func (n *Note) SetDirectMessage(v json.RawMessage) *Note

SetDirectMessage sets the value in litepub.DirectMessage.

func (*Note) SetID

func (n *Note) SetID(id string) *Note

See Object.SetID.

func (*Note) SetInReplyTo

func (n *Note) SetInReplyTo(id string) *Note

See Object.SetInReplyTo.

func (*Note) SetInReplyToAtomURI

func (n *Note) SetInReplyToAtomURI(id string) *Note

See Object.SetInReplyToAtomURI.

func (*Note) SetLikes

func (n *Note) SetLikes(c Collection) *Note

See Object.SetLikes.

func (*Note) SetPublished

func (n *Note) SetPublished(v json.RawMessage) *Note

See Object.SetPublished.

func (*Note) SetReplies

func (n *Note) SetReplies(c Collection) *Note

See Object.SetReplies.

func (*Note) SetSensitive

func (n *Note) SetSensitive(v json.RawMessage) *Note

See Object.SetSensitive.

func (*Note) SetShares

func (n *Note) SetShares(c Collection) *Note

See Object.SetShares.

func (*Note) SetType

func (n *Note) SetType()

SetType sets the type to as.Note.

func (*Note) SetURL

func (n *Note) SetURL(id string) *Note

See Object.SetURL.

func (*Note) SetUpdated

func (n *Note) SetUpdated(v json.RawMessage) *Note

See Object.SetUpdated.

type Object

type Object ld.Node

Object is the ActivityStreams Object type.

func NewObject

func NewObject() *Object

NewObject initialises a new Object.

func (*Object) AddAttachment

func (o *Object) AddAttachment(atch ...Any) *Object

AddAttachment appends attachments to as.Attachment.

func (*Object) AddAttributedTo

func (o *Object) AddAttributedTo(ids ...string) *Object

AddAttributedTo appends actor IDs to as.AttributedTo.

func (*Object) AddCc

func (o *Object) AddCc(ids ...string) *Object

AddCc appends audience IDs to as.Cc.

func (*Object) AddContent

func (o *Object) AddContent(ls ...Localised) *Object

AddContent adds values to as.Content.

func (*Object) AddName

func (o *Object) AddName(ls ...Localised) *Object

AddName appends localised values to as.Name.

func (*Object) AddSummary

func (o *Object) AddSummary(ls ...Localised) *Object

AddSummary adds values to as.Summary.

func (*Object) AddTag

func (o *Object) AddTag(tag ...Any) *Object

AddTag appends a tag to as.Tag.

func (*Object) AddTo

func (o *Object) AddTo(ids ...string) *Object

AddTo appends audience IDs to as.To.

func (*Object) Build

func (o *Object) Build() Any

Build finalises the Object.

This returns Any since that's what Activity.SetObject expects.

func (*Object) GetAtomURI

func (o *Object) GetAtomURI() string

GetAtomUri returns the URI in ostatus.AtomURI.

func (*Object) GetAttachment

func (o *Object) GetAttachment() iter.Seq[*Any]

GetAttachment returns the attachments in as.Attachment.

This returns Any because is can be a Document, PropertyValue, a combination of both and more.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment.

func (*Object) GetAttributedTo

func (o *Object) GetAttributedTo() iter.Seq[string]

GetAttributedTo returns the actor IDs from as.AttributedTo.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto.

func (*Object) GetCc

func (o *Object) GetCc() iter.Seq[string]

GetCc returns the audience IDs from as.Cc.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc.

func (*Object) GetContent

func (o *Object) GetContent() iter.Seq[*Localised]

GetContent returns the localised values in as.Content.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content.

func (*Object) GetContext

func (o *Object) GetContext() string

GetContext returns the ID in as.Context.

This is not the JSON-LD ld.KeywordContext.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context.

func (*Object) GetConversation

func (o *Object) GetConversation() string

GetConversation returns the URI in ostatus.Conversation.

This is a tag URI.

func (*Object) GetID

func (o *Object) GetID() string

GetID returns the object ID from ld.Node.ID.

This is equivalent to the 'id' property in compacted form JSON or the '@id' property in expanded form.

If an object doesn't have an ID but does have other properties it is an anonymous object (a blank node). This represents something that exists but is not named or referencable.

func (*Object) GetInReplyTo

func (o *Object) GetInReplyTo() string

GetInReplyTo returns the URL in as.InReplyTo.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto.

func (*Object) GetInReplyToAtomURI

func (o *Object) GetInReplyToAtomURI() string

GetInReplyToAtomURI returns the URI in ostatus.InReplyToAtomUri.

func (*Object) GetLikes

func (o *Object) GetLikes() *Collection

GetLikes returns the Collection stored in as.Likes.

See https://www.w3.org/TR/activitypub/#likes.

func (*Object) GetName

func (o *Object) GetName() iter.Seq[*Localised]

GetName returns the localised values in as.Name.

func (*Object) GetPublished

func (o *Object) GetPublished() json.RawMessage

GetPublished retrieves the value from as.Published.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published.

func (*Object) GetReplies

func (o *Object) GetReplies() *Collection

GetReplies returns the Collection stored in as.Replies.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies.

func (*Object) GetSensitive

func (o *Object) GetSensitive() json.RawMessage

GetSensitive returns the value from as.Sensitive.

See https://swicg.github.io/miscellany/#sensitive.

func (*Object) GetShares

func (o *Object) GetShares() *Collection

GetShares returns the Collection stored in as.Shares.

See https://www.w3.org/TR/activitypub/#shares.

func (*Object) GetSummary

func (o *Object) GetSummary() iter.Seq[*Localised]

GetSummary returns the localised values in as.Summary.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary.

func (*Object) GetTag

func (o *Object) GetTag() iter.Seq[*Any]

GetTag returns the values in as.Tag.

This returns Any because it can be an Emoji, a Hashtag, combinations of the two or more.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag.

func (*Object) GetTo

func (o *Object) GetTo() iter.Seq[string]

GetTo returns the audience IDs from as.To.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to.

func (*Object) GetType

func (o *Object) GetType() string

GetType returns the first type from ld.Node.Type.

This is equivalent to the 'type' property in compacted form JSON or the '@type' property in expanded form.

It will return the empty string if the object has no type.

An object can have multiple types, but this is so uncommon on the fediverse that this method only returns the first type. You can check the size of ld.Node.Type if you'd like.

func (*Object) GetURL

func (o *Object) GetURL() string

GetURL returns the URL in as.URL.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-url.

func (*Object) GetUpdated

func (o *Object) GetUpdated() json.RawMessage

GetUpdated returns the value in as.Updated.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime.

func (*Object) SetAtomURI

func (o *Object) SetAtomURI(uri string) *Object

SetAtomUri sets the URI in ostatus.AtomURI.

func (*Object) SetContext

func (o *Object) SetContext(id string) *Object

SetContext sets the ID in as.Context.

func (*Object) SetConversation

func (o *Object) SetConversation(uri string) *Object

SetConversation sets the URI in ostatus.Conversation.

func (*Object) SetID

func (o *Object) SetID(id string) *Object

SetID sets the object ID in ld.Node.ID.

func (*Object) SetInReplyTo

func (o *Object) SetInReplyTo(url string) *Object

SetInReplyTo sets the URL in as.InReplyTo.

func (*Object) SetInReplyToAtomURI

func (o *Object) SetInReplyToAtomURI(uri string) *Object

SetInReplyToAtomURI sets the URI in ostatus.InReplyToAtomUri.

func (*Object) SetLikes

func (o *Object) SetLikes(c Collection) *Object

SetLikes sets the Collection in as.Likes.

func (*Object) SetPublished

func (o *Object) SetPublished(value json.RawMessage) *Object

SetPublished sets the value in as.Published.

func (*Object) SetReplies

func (o *Object) SetReplies(c Collection) *Object

SetReplies sets the Collection in as.Replies.

func (*Object) SetSensitive

func (o *Object) SetSensitive(v json.RawMessage) *Object

SetSensitive sets the value in as.Sensitive.

func (*Object) SetShares

func (o *Object) SetShares(c Collection) *Object

SetShares sets the Collection in as.Shares.

func (*Object) SetType

func (o *Object) SetType(t string) *Object

SetType sets the type in ld.Node.Type.

func (*Object) SetURL

func (o *Object) SetURL(url string) *Object

SetURL sets the URL in as.URL.

func (*Object) SetUpdated

func (o *Object) SetUpdated(v json.RawMessage) *Object

SetUpdated sets the value in as.Updated.

type Organisation

type Organisation = Actor

type Organization

type Organization = Organisation

type Page

type Page Object

Page is the ActivityStreams Page type.

func NewPage

func NewPage() *Page

NewPage initialises a new Page.

func (*Page) Build

func (p *Page) Build() Any

Build finalises the Page.

This returns Any since that's what Activity.SetObject expects.

type Person

type Person = Actor

type Place

type Place Object

Place is the ActivityStreams Place type.

func NewPlace

func NewPlace() *Place

NewPlace initialises a new Place.

func (*Place) Build

func (p *Place) Build() Place

Build finalises the Place.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor is used to process incoming messages and prepare outgoing messages.

Your application only needs a single processor instance.

func NewProcessor

func NewProcessor(
	logger *slog.Logger,
) *Processor

NewProcessor initialised a new Processor suitable for dealing with ActivityStreams messages.

It uses loader.Builtin to retrieve contexts and does not retrieve them over the network.

func (*Processor) Marshal

func (p *Processor) Marshal(
	compactionContext json.RawMessage,
	activity Activity,
) (json.RawMessage, error)

Marshal takes an Activity and returns JSON-LD in compacted document form.

This is the shape of JSON you want to exchange with other servers and clients.

The compaction context is a JSON document representing the JSON-LD context that should be used for compaction.

Example
package main

import (
	"encoding/json"
	"fmt"
	"log/slog"

	"code.dny.dev/pana"

	as "code.dny.dev/pana/vocab/w3/activitystreams"
)

func main() {
	proc := pana.NewProcessor(slog.New(slog.DiscardHandler))

	activity := pana.NewActivity().
		SetID("https://example.com/id/1").
		AddTo(as.PublicCollection).
		SetObject(
			pana.NewNote().
				AddContent(
					pana.NewLocalised().
						SetValue([]byte(`"We spell color wrong."`)).
						SetLanguage("en-us").
						Build(),
				).
				AddContent(
					pana.NewLocalised().
						SetValue([]byte(`"Omelette du fromage."`)).
						SetLanguage("fr-FR").
						Build(),
					pana.NewLocalised().
						SetValue([]byte(`"Ona li toki."`)).
						Build(),
				).
				Build()).
		SetType(as.TypeCreate).
		Build()

	compacted, err := proc.Marshal(
		json.RawMessage(`{"@context":"https://www.w3.org/ns/activitystreams"}`),
		activity,
	)

	if err != nil {
		panic(err)
	}

	var res any
	_ = json.Unmarshal(compacted, &res)
	ind, _ := json.MarshalIndent(res, "", "  ")
	fmt.Println(string(ind))
}
Output:

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "id": "https://example.com/id/1",
  "object": {
    "content": "Ona li toki.",
    "contentMap": {
      "en-us": "We spell color wrong.",
      "fr-FR": "Omelette du fromage."
    },
    "type": "Note"
  },
  "to": "https://www.w3.org/ns/activitystreams#Public",
  "type": "Create"
}

func (*Processor) RegisterContextPath

func (p *Processor) RegisterContextPath(
	path string,
	doc json.RawMessage,
) error

RegisterContextPath adds or overrides a context document for the specified remote path in the loader.

Paths are always matches as URL suffixes.

func (*Processor) RegisterContextURL

func (p *Processor) RegisterContextURL(
	url string,
	doc json.RawMessage,
) error

RegisterContextURL adds or overrides a context document for the specified remote context URL in the loader.

func (*Processor) Unmarshal

func (p *Processor) Unmarshal(
	document json.RawMessage,
) (*Activity, error)

Unmarshal takes a JSON document and returns an Activity that represents it using JSON-LD expanded document form.

In JSON-LD the result of expanding a document is always a list. But in the case of ActivityPub we only ever send out a single document at a time, so it returns Activity. If the result happens to have more than one object an error is raised so it doesn't go unnoticed.

Example
package main

import (
	"fmt"
	"iter"
	"log/slog"
	"maps"
	"slices"

	"code.dny.dev/pana"
	"code.dny.dev/pana/vocab/mastodon"

	as "code.dny.dev/pana/vocab/w3/activitystreams"
)

func main() {
	// small helper for stable iteration order of properties
	var listProperties = func(in map[string]struct{}) []string {
		s := slices.Collect(maps.Keys(in))
		slices.Sort(s)
		return s
	}

	var getSingle = func(in iter.Seq[*pana.Localised]) string {
		for val := range in {
			return string(val.Value)
		}
		return ""
	}

	msg := []byte(`{
	"@context": [
        "https://www.w3.org/ns/activitystreams",
		{
			"Emoji": "toot:Emoji",
			"Hashtag": "as:Hashtag",
			"atomUri": "ostatus:atomUri",
			"blurhash": "toot:blurhash",
			"focalPoint": {
				"@id": "toot:focalPoint",
				"@container": "@list"
			},
			"ostatus": "http://ostatus.org#",
			"toot": "http://joinmastodon.org/ns#",
			"sensitive": "as:sensitive"
		}
    ],
    "actor": "https://example.com/actor/wcgkaaorsn",
    "cc": "https://www.w3.org/ns/activitystreams#Public",
    "id": "https://example.com/id/bikfmutagl",
    "object": {
		"atomUri": "https://example.com/atomUri/qbfujvxbeo",
        "attachment": {
			"blurhash": "pkbjlvkjjb",
			"focalPoint": [
				0.7,
				-0.7
			],
			"height": 600,
			"mediaType": "image/jpeg",
			"name": "banana",
			"type": "Document",
			"url": "https://example.com/url/odybnszymk",
			"width": 800
        },
        "attributedTo": "https://example.com/attributedTo/ytoxvxmalh",
        "content": "eating a banana",
        "id": "https://example.com/id/bfcqgpkwjv",
        "published": "2020-10-01T16:00:00Z",
        "replies": {
            "first": {
                "id": "https://example.com/id/htpqbwrroa",
                "next": "https://example.com/next/dsqoqssppw",
                "partOf": "https://example.com/partOf/bjkaungqre",
                "type": "CollectionPage"
            },
            "id": "https://example.com/id/edjlqpbspm",
            "type": "Collection"
        },
        "sensitive": true,
        "summary": "food, eye contact",
        "tag": [
            {
                "icon": {
                    "mediaType": "image/jpeg",
                    "type": "Image",
                    "url": "https://example.com/url/kkurwzofjc"
                },
                "id": "https://example.com/id/xadgmrnzdk",
                "name": "bananadance",
                "type": "Emoji",
                "updated": "2020-10-01T16:00:00Z"
            },
            {
                "href": "https://example.com/href/qzqgetcjfv",
                "name": "#food",
                "type": "Hashtag"
            }
        ],
        "to": "https://www.w3.org/ns/activitystreams#Public",
        "type": "Note",
        "url": "https://example.com/url/lpsbcbqdnm"
    },
    "published": "2020-10-01T16:00:00Z",
    "to": "https://www.w3.org/ns/activitystreams#Public",
    "type": "Create"
}`)
	proc := pana.NewProcessor(slog.New(slog.DiscardHandler))
	activity, err := proc.Unmarshal(msg)
	if err != nil {
		panic(err)
	}

	fmt.Println("#----- Activity -----#")
	// what type of Activity did we just get?
	fmt.Println("type:", activity.GetType())

	// what properties are set on the Activity?
	for _, property := range listProperties(pana.Properties(activity)) {
		fmt.Println("property:", property)
	}

	fmt.Println("\n#----- Object -----#")
	// what's our object?
	obj := activity.GetObject()

	// do we have a real object or a reference?
	fmt.Println("object is a reference:", pana.IsReference(obj))

	// what's the object type?
	fmt.Println("object type:", obj.GetType())

	// what are the properties on the object?
	for _, property := range listProperties(pana.Properties(obj)) {
		fmt.Println("property:", property)
	}

	// time to convert it
	note := (*pana.Note)(obj) // Note is a more limited pana.Object with only the getters and setters for microblog posts.

	fmt.Println("\n#----- Object attachments -----#")
	for atch := range note.GetAttachment() {
		switch atch.GetType() {
		case as.TypeDocument:
			doc := (*pana.Document)(atch)
			fmt.Println("height:", string(doc.GetHeight()))
			fmt.Println("width:", string(doc.GetWidth()))
			fmt.Println("URL:", doc.GetURL())
		default:
			panic("unknown attachment type")
		}
	}

	fmt.Println("\n#----- Object tags -----#")
	// lets get all the tags
	for tag := range note.GetTag() {
		switch tag.GetType() {
		case as.TypeHashtag:
			ht := (*pana.Hashtag)(tag)
			fmt.Println("hashtag name:", getSingle(ht.GetName()))
			fmt.Println("hashtag IRI:", ht.GetHref())
		case mastodon.TypeEmoji:
			emo := (*pana.Emoji)(tag)
			fmt.Println("emoji name:", getSingle(emo.GetName()))
			fmt.Println("emoj URL:", emo.GetIcon().GetURL())
		default:
			panic("unsupported tag type")
		}
	}

}
Output:

#----- Activity -----#
type: https://www.w3.org/ns/activitystreams#Create
property: https://www.w3.org/ns/activitystreams#actor
property: https://www.w3.org/ns/activitystreams#cc
property: https://www.w3.org/ns/activitystreams#object
property: https://www.w3.org/ns/activitystreams#published
property: https://www.w3.org/ns/activitystreams#to
property: id
property: type

#----- Object -----#
object is a reference: false
object type: https://www.w3.org/ns/activitystreams#Note
property: http://ostatus.org#atomUri
property: https://www.w3.org/ns/activitystreams#attachment
property: https://www.w3.org/ns/activitystreams#attributedTo
property: https://www.w3.org/ns/activitystreams#content
property: https://www.w3.org/ns/activitystreams#published
property: https://www.w3.org/ns/activitystreams#replies
property: https://www.w3.org/ns/activitystreams#sensitive
property: https://www.w3.org/ns/activitystreams#summary
property: https://www.w3.org/ns/activitystreams#tag
property: https://www.w3.org/ns/activitystreams#to
property: https://www.w3.org/ns/activitystreams#url
property: id
property: type

#----- Object attachments -----#
height: 600
width: 800
URL: https://example.com/url/odybnszymk

#----- Object tags -----#
emoji name: "bananadance"
emoj URL: https://example.com/url/kkurwzofjc
hashtag name: "#food"
hashtag IRI: https://example.com/href/qzqgetcjfv

type Profile

type Profile Object

Profile is the ActivityStreams Profile type.

func NewProfile

func NewProfile() *Profile

NewProfile initialises a new Profile.

func (*Profile) Build

func (p *Profile) Build() Any

Build finalises the Profile.

This returns Any since that's what Activity.SetObject expects.

type PublicKey

type PublicKey ld.Node

PublicKey is the W3ID Security v1 Public Key.

func NewPublicKey

func NewPublicKey() *PublicKey

NewPublicKey initialises a new PublicKey.

func (*PublicKey) Build

func (pk *PublicKey) Build() PublicKey

Build finalises the PublicKey.

func (*PublicKey) GetID

func (pk *PublicKey) GetID() string

See Object.GetID.

func (*PublicKey) GetOwner

func (pk *PublicKey) GetOwner() string

GetOwner returns the ID in secv1.Owner.

func (*PublicKey) GetPublicKeyPEM

func (pk *PublicKey) GetPublicKeyPEM() json.RawMessage

GetPublicKeyPEM returns the value in secv1.PublicKeyPem.

func (*PublicKey) SetID

func (pk *PublicKey) SetID(id string) *PublicKey

See Object.SetID.

func (*PublicKey) SetOwner

func (pk *PublicKey) SetOwner(id string) *PublicKey

SetOwner sets the ID in secv1.Owner.

func (*PublicKey) SetPublicKeyPEM

func (pk *PublicKey) SetPublicKeyPEM(v json.RawMessage) *PublicKey

SetPublicKeyPEM sets the value in secv1.PublicKeyPem.

type Question

type Question IntransitiveActivity

Question is the ActivityStreams Question object.

func NewQuestion

func NewQuestion() *Question

NewQuestion initialises a new Question.

func (*Question) AddAnyOf

func (q *Question) AddAnyOf(chs ...Choice) *Question

AddAnyOf appends Choice to as.AnyOf.

func (*Question) AddName

func (q *Question) AddName(ls ...Localised) *Question

See Object.AddName.

func (*Question) AddOneOf

func (q *Question) AddOneOf(chs ...Choice) *Question

AddOneOf appends Choice to as.OneOf.

func (*Question) Build

func (q *Question) Build() Any

Build finalises the Question.

This returns Any since that's what Activity.SetObject expects.

func (*Question) GetAnyOf

func (q *Question) GetAnyOf() iter.Seq[Choice]

GetAnyOf gets the Choice in as.AnyOf.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-oneof.

func (*Question) GetClosed

func (q *Question) GetClosed() json.RawMessage

GetClosed returns the value in as.Closed.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-closed.

func (*Question) GetEndTime

func (q *Question) GetEndTime() json.RawMessage

GetEndTime returns the value in as.EndTime.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime.

func (*Question) GetName

func (q *Question) GetName() iter.Seq[*Localised]

See Object.GetName.

func (*Question) GetOneOf

func (q *Question) GetOneOf() iter.Seq[Choice]

GetOneOf gets the Choice in as.OneOf.

See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-oneof.

func (*Question) GetSensitive

func (q *Question) GetSensitive() json.RawMessage

See Object.GetSensitive.

func (*Question) GetType

func (q *Question) GetType() string

See Object.GetType.

func (*Question) GetUpdated

func (q *Question) GetUpdated() json.RawMessage

See Object.GetUpdated.

func (*Question) GetVotersCount

func (q *Question) GetVotersCount() json.RawMessage

GetVotersCount returns the value in mastodon.VotersCount.

See https://docs.joinmastodon.org/spec/activitypub/#toot.

func (*Question) IsMultipleChoice

func (q *Question) IsMultipleChoice() bool

IsMultipleChoice checks if this is a multiple-choice question.

func (*Question) SetClosed

func (q *Question) SetClosed(v json.RawMessage) *Question

SetClosed sets the value in as.Closed.

func (*Question) SetEndTime

func (q *Question) SetEndTime(v json.RawMessage) *Question

SetEndTime sets the value in as.EndTime.

func (*Question) SetSensitive

func (q *Question) SetSensitive(v json.RawMessage) *Question

See Object.SetSensitive.

func (*Question) SetType

func (q *Question) SetType()

SetType sets the type to as.TypeQuestion.

func (*Question) SetUpdated

func (q *Question) SetUpdated(v json.RawMessage) *Question

See Object.SetUpdated.

func (*Question) SetVotersCount

func (q *Question) SetVotersCount(v json.RawMessage) *Question

SetVotersCount sets the value in mastodon.VotersCount.

type Relationship

type Relationship Object

Relationship is the ActivityStreams Relationship type.

func NewRelationship

func NewRelationship() *Relationship

NewRelationship initialises a new Relationship.

func (*Relationship) Build

func (r *Relationship) Build() Relationship

Build finalises the Relationship.

type Remove

type Remove = Activity

func NewRemove

func NewRemove() *Remove

NewRemove initialises a new Remove activity with as.TypeRemove.

type Service

type Service = Actor

type Tombstone

type Tombstone Object

Tombstone is the ActivityStreams Tombstone type.

func NewTombstone

func NewTombstone() *Tombstone

NewTombstone initialises a new Tombstone.

func (*Tombstone) Build

func (t *Tombstone) Build() Tombstone

Build finalises the Tombstone.

type Undo

type Undo = Activity

func NewUndo

func NewUndo() *Undo

NewUndo initialises a new Undo activity with as.TypeUndo.

type Update

type Update = Activity

func NewUpdate

func NewUpdate() *Update

NewUpdate initialises a new Update activity with as.TypeUpdate.

type Video

type Video = Audio

Video is the ActivityStreams Video type.

It is the same as Audio.

func NewVideo

func NewVideo() *Video

NewVideo initialises a new Video.

Directories

Path Synopsis
internal
Package vocab provides context documents and Go consts for all the terms defined in each context.
Package vocab provides context documents and Go consts for all the terms defined in each context.
dublincore
Package dublincore contains packages for JSON-LD contexts under purl.org/dc.
Package dublincore contains packages for JSON-LD contexts under purl.org/dc.
dublincore/terms
Package terms contains terms for the Dublin Core Terms namespace.
Package terms contains terms for the Dublin Core Terms namespace.
fedibird
Package fedibird contains terms for the Fedibird namespace.
Package fedibird contains terms for the Fedibird namespace.
gotosocial
Package gotosocial contains terms for the GoToSocial namespace.
Package gotosocial contains terms for the GoToSocial namespace.
litepub
Package litepub contains terms for the Litepub namespace.
Package litepub contains terms for the Litepub namespace.
mastodon
Package mastodon contains terms for the toot namespace.
Package mastodon contains terms for the toot namespace.
misskey
Package misskey contains terms for the Misskey namespace.
Package misskey contains terms for the Misskey namespace.
ostatus
Package ostatus contains terms for the Ostatus.org namespace.
Package ostatus contains terms for the Ostatus.org namespace.
schema
Package schema contains terms for the Schema.org namespace.
Package schema contains terms for the Schema.org namespace.
w3
Package w3 contains packages for JSON-LD contexts under w3.org/.
Package w3 contains packages for JSON-LD contexts under w3.org/.
w3/activitystreams
Package activitystreams contains terms for the ActivityStreams namespace.
Package activitystreams contains terms for the ActivityStreams namespace.
w3/ldp
Package ldp contains terms for the Linked Data Platform namespace.
Package ldp contains terms for the Linked Data Platform namespace.
w3/rdf/schema
Package schema contains terms for the RDF Schema namespace.
Package schema contains terms for the RDF Schema namespace.
w3id
Package w3id contains packages for JSON-LD contexts under w3id.org/.
Package w3id contains packages for JSON-LD contexts under w3id.org/.
w3id/credentialsv1
Package credv1 contains terms for the W3ID Credentials namespace.
Package credv1 contains terms for the W3ID Credentials namespace.
w3id/identityv1
Package identityv1 contains terms for the W3ID Identity namespace.
Package identityv1 contains terms for the W3ID Identity namespace.
w3id/payswarmv1
Package payswarmv1 contains terms for the W3ID Payswarm namespace.
Package payswarmv1 contains terms for the W3ID Payswarm namespace.
w3id/permissionsv1
Package permsv1 contains terms for the W3ID Permissions namespace.
Package permsv1 contains terms for the W3ID Permissions namespace.
w3id/securityv1
Package secv1 contains terms for the W3ID Security namespace.
Package secv1 contains terms for the W3ID Security namespace.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL