Factored out the objects' common properties

This commit is contained in:
Marius Orcsik 2018-11-23 15:22:56 +01:00
parent 1955b6af31
commit 269c06fbb2
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A
12 changed files with 66 additions and 509 deletions

View file

@ -17,7 +17,7 @@ type (
func FollowersNew() *Followers {
id := as.ObjectID("followers")
i := Followers{ID: id, Type: as.OrderedCollectionType}
i := Followers{Parent: as.Parent{ID: id, Type: as.CollectionType}}
i.Name = as.NaturalLanguageValueNew()
i.Content = as.NaturalLanguageValueNew()
i.Summary = as.NaturalLanguageValueNew()

View file

@ -19,7 +19,7 @@ type (
func FollowingNew() *Following {
id := as.ObjectID("following")
i := Following{ID: id, Type: as.OrderedCollectionType}
i := Following{Parent: as.Parent{ID: id, Type: as.CollectionType}}
i.Name = as.NaturalLanguageValueNew()
i.Content = as.NaturalLanguageValueNew()
i.Summary = as.NaturalLanguageValueNew()

View file

@ -22,7 +22,7 @@ type (
func InboxNew() *as.OrderedCollection {
id := as.ObjectID("inbox")
i := as.OrderedCollection{ID: id, Type: as.OrderedCollectionType}
i := as.OrderedCollection{Parent: as.Parent{ID: id, Type: as.CollectionType}}
i.Name = as.NaturalLanguageValueNew()
i.Content = as.NaturalLanguageValueNew()

View file

@ -17,7 +17,7 @@ type (
func LikedNew() *as.OrderedCollection {
id := as.ObjectID("liked")
l := as.OrderedCollection{ID: id, Type: as.OrderedCollectionType}
l := as.OrderedCollection{Parent: as.Parent{ID: id, Type: as.CollectionType}}
l.Name = as.NaturalLanguageValueNew()
l.Content = as.NaturalLanguageValueNew()

View file

@ -17,7 +17,7 @@ type (
func LikesNew() *Likes {
id := as.ObjectID("likes")
l := Likes{ID: id, Type: as.OrderedCollectionType}
l := Likes{Parent: as.Parent{ID: id, Type: as.CollectionType}}
l.Name = as.NaturalLanguageValueNew()
l.Content = as.NaturalLanguageValueNew()

View file

@ -16,7 +16,7 @@ type (
func OutboxNew() *Outbox {
id := as.ObjectID("outbox")
i := Outbox{ID: id, Type: as.OrderedCollectionType}
i := Outbox{Parent: as.Parent{ID: id, Type: as.CollectionType}}
i.Name = as.NaturalLanguageValueNew()
i.Content = as.NaturalLanguageValueNew()

View file

@ -17,7 +17,7 @@ type (
func SharesNew() *Shares {
id := as.ObjectID("Shares")
i := Shares{ID: id, Type: as.OrderedCollectionType}
i := Shares{Parent: as.Parent{ID: id, Type: as.CollectionType}}
i.Name = as.NaturalLanguageValueNew()
i.Content = as.NaturalLanguageValueNew()

View file

@ -157,83 +157,7 @@ var validActivityTypes = [...]ActivityVocabularyType{
// It is important to note that the Activity type itself does not carry any specific semantics
// about the kind of action being taken.
type Activity struct {
// ID providesthe globally unique identifier for an Activity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Type identifies the Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// Name a simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Attachment identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// AttributedTo identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Audience identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// Content the content or textual representation of the Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Context identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// EndTime the date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Generator identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Icon indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Image indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// InReplyTo indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Location indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Preview identifies an entity that providesa preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// Published the date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Replies identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// StartTime the date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// Summary a natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// Tag One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag ItemCollection `jsonld:"tag,omitempty"`
// Updated the date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// URL identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// To identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Bto identifies an Activity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// CC identifies an Activity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// BCC identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// Duration When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// Actor describes one or more entities that either performed or are expected to perform the activity.
// Any single activity can have multiple actors. The actor may be specified using an indirect Link.
Actor Item `jsonld:"actor,omitempty"`
@ -262,83 +186,7 @@ type Activity struct {
// IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions.
// The object property is therefore inappropriate for these activities.
type IntransitiveActivity struct {
// ID providesthe globally unique identifier for an Activity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Type identifies the Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// Name a simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Attachment identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// AttributedTo identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Audience identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// Content the content or textual representation of the Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Context identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// EndTime the date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Generator identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Icon indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Image indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// InReplyTo indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Location indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Preview identifies an entity that providesa preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// Published the date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Replies identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// StartTime the date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// Summary a natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// Tag One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag Item `jsonld:"tag,omitempty"`
// Updated the date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// URL identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// To identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Bto identifies an Activity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// CC identifies an Activity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// BCC identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// Duration When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// Actor describes one or more entities that either performed or are expected to perform the activity.
// Any single activity can have multiple actors. The actor may be specified using an indirect Link.
Actor Actor `jsonld:"actor,omitempty"`
@ -831,7 +679,7 @@ func ActivityNew(id ObjectID, typ ActivityVocabularyType, ob Item) *Activity {
if !ValidActivityType(typ) {
typ = ActivityType
}
a := Activity{ID: id, Type: typ}
a := Activity{Parent: Parent{ID: id, Type: typ}}
a.Name = NaturalLanguageValueNew()
a.Content = NaturalLanguageValueNew()
@ -845,7 +693,7 @@ func IntransitiveActivityNew(id ObjectID, typ ActivityVocabularyType) *Intransit
if !ValidIntransitiveActivityType(typ) {
typ = IntransitiveActivityType
}
i := IntransitiveActivity{ID: id, Type: typ}
i := IntransitiveActivity{Parent: Parent{ID: id, Type: typ}}
i.Name = NaturalLanguageValueNew()
i.Content = NaturalLanguageValueNew()

View file

@ -1,8 +1,6 @@
package activitystreams
import (
"time"
"github.com/buger/jsonparser"
)
@ -60,83 +58,7 @@ type WillAct interface {
// Actors are retrieved like any other Object in ActivityPub.
// Like other ActivityStreams objects, actors have an id, which is a URI.
type Actor struct {
// Provides the globally unique identifier for an Activity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Identifies the Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// A simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// Identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// The content or textual representation of the Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// The date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// Indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Identifies an entity that provides a preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// The date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// The date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// A natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag ItemCollection `jsonld:"tag,omitempty"`
// The date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// Identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// Identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Identifies an Activity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// Identifies an Activity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// Identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor;
// see 5.2 Inbox.
Inbox Item `jsonld:"inbox,omitempty"`
@ -199,7 +121,7 @@ func ActorNew(id ObjectID, typ ActivityVocabularyType) *Actor {
typ = ActorType
}
a := Actor{ID: id, Type: typ}
a := Actor{Parent: Parent{ID: id, Type: typ}}
a.Name = NaturalLanguageValueNew()
a.Content = NaturalLanguageValueNew()
a.Summary = NaturalLanguageValueNew()

View file

@ -1,8 +1,6 @@
package activitystreams
import (
"time"
"github.com/buger/jsonparser"
)
@ -21,83 +19,7 @@ type CollectionInterface interface {
// Collection is a subtype of Activity Pub Object that represents ordered or unordered sets of Activity Pub Object or Link instances.
type Collection struct {
// Provides the globally unique identifier for an Activity Pub Activity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Identifies the Activity Pub Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// A simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// Identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// The content or textual representation of the Activity Pub Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// The date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// Indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Identifies an entity that provides a preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// The date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// The date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// A natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag ItemCollection `jsonld:"tag,omitempty"`
// The date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// Identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// Identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Identifies an Activity Pub Activity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// Identifies an Activity Pub Activity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// Identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// In a paged Collection, indicates the page that contains the most recently updated member items.
Current ObjectOrLink `jsonld:"current,omitempty"`
// In a paged Collection, indicates the furthest preceeding page of items in the collection.
@ -114,83 +36,7 @@ type Collection struct {
// OrderedCollection is a subtype of Collection in which members of the logical
// collection are assumed to always be strictly ordered.
type OrderedCollection struct {
// Provides the globally unique identifier for an Activity Pub Activity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Identifies the Activity Pub Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// A simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// Identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// The content or textual representation of the Activity Pub Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// The date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// Indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Identifies an entity that provides a preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// The date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// The date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// A natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag Item `jsonld:"tag,omitempty"`
// The date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// Identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// Identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Identifies an Activity Pub Activity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// Identifies an Activity Pub Activity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// Identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// When the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// In a paged Collection, indicates the page that contains the most recently updated member items.
Current ObjectOrLink `jsonld:"current,omitempty"`
// In a paged Collection, indicates the furthest preceeding page of items in the collection.
@ -257,7 +103,7 @@ func ValidCollectionType(typ ActivityVocabularyType) bool {
// CollectionNew initializes a new Collection
func CollectionNew(id ObjectID) *Collection {
c := Collection{ID: id, Type: CollectionType}
c := Collection{Parent: Parent{ID: id, Type: CollectionType}}
c.Name = NaturalLanguageValueNew()
c.Content = NaturalLanguageValueNew()
c.Summary = NaturalLanguageValueNew()
@ -266,7 +112,7 @@ func CollectionNew(id ObjectID) *Collection {
// OrderedCollectionNew initializes a new OrderedCollection
func OrderedCollectionNew(id ObjectID) *OrderedCollection {
o := OrderedCollection{ID: id, Type: OrderedCollectionType}
o := OrderedCollection{Parent: Parent{ID: id, Type: OrderedCollectionType}}
o.Name = NaturalLanguageValueNew()
o.Content = NaturalLanguageValueNew()

View file

@ -254,10 +254,7 @@ func (n *NaturalLanguageValue) UnmarshalText(data []byte) error {
return nil
}
// Describes an object of any kind.
// The Activity Pub Object type serves as the base type for most of the other kinds of objects defined in the Activity Vocabulary,
// including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection.
type Object struct {
type object struct {
// ID provides the globally unique identifier for anActivity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Type identifies the Activity Pub Object or Link type. Multiple values may be specified.
@ -341,6 +338,11 @@ type Object struct {
}
type (
Parent = object
// Describes an object of any kind.
// The Activity Pub Object type serves as the base type for most of the other kinds of objects defined in the Activity Vocabulary,
// including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection.
Object = object
// Article represents any kind of multi-paragraph written work.
Article Object
// Audio represents an audio document of any kind.
@ -361,7 +363,7 @@ type (
// Place represents a logical or physical location. See 5.3 Representing Places for additional information.
type Place struct {
Object
Parent
// Accuracy indicates the accuracy of position coordinates on a Place objects.
// Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate".
Accuracy float32
@ -386,7 +388,7 @@ type Place struct {
// typically used to describe Actor Type objects.
// The describes property is used to reference the object being described by the profile.
type Profile struct {
Object
Parent
// Describes On a Profile object, the describes property identifies the object described by the Profile.
Describes Item `jsonld:"describes,omitempty"`
}
@ -399,86 +401,7 @@ type Profile struct {
// as a "reified statement" where subject identifies the subject, relationship identifies the predicate,
// and object identifies the object.
type Relationship struct {
// ID provides the globally unique identifier for anActivity Pub Object or Link.
ID ObjectID `jsonld:"id,omitempty"`
// Type identifies the Activity Pub Object or Link type. Multiple values may be specified.
Type ActivityVocabularyType `jsonld:"type,omitempty"`
// Name a simple, human-readable, plain-text name for the object.
// HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values.
Name NaturalLanguageValue `jsonld:"name,omitempty,collapsible"`
// Attachment identifies a resource attached or related to an object that potentially requires special handling.
// The intent is to provide a model that is at least semantically similar to attachments in email.
Attachment Item `jsonld:"attachment,omitempty"`
// AttributedTo identifies one or more entities to which this object is attributed. The attributed entities might not be Actors.
// For instance, an object might be attributed to the completion of another activity.
AttributedTo Item `jsonld:"attributedTo,omitempty"`
// Audience identifies one or more entities that represent the total population of entities
// for which the object can considered to be relevant.
Audience Item `jsonld:"audience,omitempty"`
// Content the content or textual representation of the Activity Pub Object encoded as a JSON string.
// By default, the value of content is HTML.
// The mediaType property can be used in the object to indicate a different content type.
// (The content MAY be expressed using multiple language-tagged values.)
Content NaturalLanguageValue `jsonld:"content,omitempty,collapsible"`
// Context identifies the context within which the object exists or an activity was performed.
// The notion of "context" used is intentionally vague.
// The intended function is to serve as a means of grouping objects and activities that share a
// common originating context or purpose. An example could be all activities relating to a common project or event.
Context Item `jsonld:"context,omitempty"`
// MediaType when used on an Object, identifies the MIME media type of the value of the content property.
// If not specified, the content property is assumed to contain text/html content.
MediaType MimeType `jsonld:"mediaType,omitempty"`
// EndTime the date and time describing the actual or expected ending time of the object.
// When used with an Activity object, for instance, the endTime property specifies the moment
// the activity concluded or is expected to conclude.
EndTime time.Time `jsonld:"endTime,omitempty"`
// Generator identifies the entity (e.g. an application) that generated the object.
Generator Item `jsonld:"generator,omitempty"`
// Icon indicates an entity that describes an icon for this object.
// The image should have an aspect ratio of one (horizontal) to one (vertical)
// and should be suitable for presentation at a small size.
Icon Item `jsonld:"icon,omitempty"`
// Image indicates an entity that describes an image for this object.
// Unlike the icon property, there are no aspect ratio or display size limitations assumed.
Image Item `jsonld:"image,omitempty"`
// InReplyTo indicates one or more entities for which this object is considered a response.
InReplyTo Item `jsonld:"inReplyTo,omitempty"`
// Location indicates one or more physical or logical locations associated with the object.
Location Item `jsonld:"location,omitempty"`
// Preview identifies an entity that provides a preview of this object.
Preview Item `jsonld:"preview,omitempty"`
// Published the date and time at which the object was published
Published time.Time `jsonld:"published,omitempty"`
// Replies identifies a Collection containing objects considered to be responses to this object.
Replies Item `jsonld:"replies,omitempty"`
// StartTime the date and time describing the actual or expected starting time of the object.
// When used with an Activity object, for instance, the startTime property specifies
// the moment the activity began or is scheduled to begin.
StartTime time.Time `jsonld:"startTime,omitempty"`
// Summary a natural language summarization of the object encoded as HTML.
// *Multiple language tagged summaries may be provided.)
Summary NaturalLanguageValue `jsonld:"summary,omitempty,collapsible"`
// Tag one or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub Object.
// The key difference between attachment and tag is that the former implies association by inclusion,
// while the latter implies associated by reference.
Tag ItemCollection `jsonld:"tag,omitempty"`
// Updated the date and time at which the object was updated
Updated time.Time `jsonld:"updated,omitempty"`
// URL identifies one or more links to representations of the object
URL LinkOrURI `jsonld:"url,omitempty"`
// To identifies an entity considered to be part of the public primary audience of an Activity Pub Object
To ItemCollection `jsonld:"to,omitempty"`
// Bto identifies anActivity Pub Object that is part of the private primary audience of this Activity Pub Object.
Bto ItemCollection `jsonld:"bto,omitempty"`
// CC identifies anActivity Pub Object that is part of the public secondary audience of this Activity Pub Object.
CC ItemCollection `jsonld:"cc,omitempty"`
// BCC identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object.
BCC ItemCollection `jsonld:"bcc,omitempty"`
// Duration when the object describes a time-bound resource, such as an audio or video, a meeting, etc,
// the duration property indicates the object's approximate duration.
// The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
// section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S").
Duration time.Duration `jsonld:"duration,omitempty"`
Parent
// Subject Subject On a Relationship object, the subject property identifies one of the connected individuals.
// For instance, for a Relationship object describing "John is related to Sally", subject would refer to John.
Subject Item
@ -493,7 +416,7 @@ type Relationship struct {
// It can be used in Collections to signify that there used to be an object at this position,
// but it has been deleted.
type Tombstone struct {
Object
Parent
// FormerType On a Tombstone object, the formerType property identifies the type of the object that was deleted.
FormerType Item
// Deleted On a Tombstone object, the deleted property is a timestamp for when the object was deleted.

View file

@ -267,8 +267,10 @@ var allTests = tests{
Type: a.ObjectType,
ID: a.ObjectID("http://www.test.example/object/1"),
Replies: &a.Collection{
ID: a.ObjectID("http://www.test.example/object/1/replies"),
Type: a.CollectionType,
Parent: a.Parent{
ID: a.ObjectID("http://www.test.example/object/1/replies"),
Type: a.CollectionType,
},
TotalItems: 1,
Items: a.ItemCollection{
&a.Object{
@ -284,11 +286,15 @@ var allTests = tests{
expected: true,
blank: &a.Activity{},
result: &a.Activity{
Type: a.ActivityType,
Summary: a.NaturalLanguageValue{{a.NilLangRef, "Sally did something to a note"}},
Parent: a.Parent{
Type: a.ActivityType,
Summary: a.NaturalLanguageValue{{a.NilLangRef, "Sally did something to a note"}},
},
Actor: &a.Person{
Type: a.PersonType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "Sally"}},
Parent: a.Parent{
Type: a.PersonType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "Sally"}},
},
},
Object: &a.Object{
Type: a.NoteType,
@ -300,15 +306,19 @@ var allTests = tests{
expected: true,
blank: &a.Person{},
result: &a.Person{
ID: a.ObjectID("http://example.com/accounts/ana"),
Type: a.PersonType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}},
Parent: a.Parent{
ID: a.ObjectID("http://example.com/accounts/ana"),
Type: a.PersonType,
Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}},
URL: a.IRI("http://example.com/accounts/ana"),
},
PreferredUsername: a.NaturalLanguageValue{{a.NilLangRef, "Ana"}},
URL: a.IRI("http://example.com/accounts/ana"),
Outbox: &a.OrderedCollection{
ID: a.ObjectID("http://example.com/accounts/ana/outbox"),
Type: a.OrderedCollectionType,
URL: a.IRI("http://example.com/outbox"),
Parent: a.Parent{
ID: a.ObjectID("http://example.com/accounts/ana/outbox"),
Type: a.OrderedCollectionType,
URL: a.IRI("http://example.com/outbox"),
},
},
},
},
@ -316,9 +326,11 @@ var allTests = tests{
expected: true,
blank: &a.OrderedCollection{},
result: &a.OrderedCollection{
ID: a.ObjectID("http://example.com/outbox"),
Type: a.OrderedCollectionType,
URL: a.IRI("http://example.com/outbox"),
Parent: a.Parent{
ID: a.ObjectID("http://example.com/outbox"),
Type: a.OrderedCollectionType,
URL: a.IRI("http://example.com/outbox"),
},
TotalItems: 1,
OrderedItems: a.ItemCollection{
&a.Object{
@ -344,9 +356,11 @@ var allTests = tests{
Prev: a.IRI("http://example.com/outbox?page=1"),
Current: a.IRI("http://example.com/outbox?page=2"),
OrderedCollection: a.OrderedCollection{
ID: a.ObjectID("http://example.com/outbox?page=2"),
Type: a.OrderedCollectionPageType,
URL: a.IRI("http://example.com/outbox?page=2"),
Parent: a.Parent{
ID: a.ObjectID("http://example.com/outbox?page=2"),
Type: a.OrderedCollectionPageType,
URL: a.IRI("http://example.com/outbox?page=2"),
},
TotalItems: 1,
OrderedItems: a.ItemCollection{
&a.Object{
@ -381,7 +395,9 @@ var allTests = tests{
expected: true,
blank: &a.Create{},
result: &a.Create{
Type: a.CreateType,
Parent: a.Parent{
Type: a.CreateType,
},
Actor: a.IRI("https://littr.git/api/accounts/anonymous"),
Object: &a.Object{
Type: a.NoteType,
@ -397,7 +413,9 @@ var allTests = tests{
blank: &ap.LikeActivity{},
result: &ap.LikeActivity{
Activity: &a.Like{
Type: a.LikeType,
Parent: a.Parent{
Type: a.LikeType,
},
Actor: a.IRI("https://littr.git/api/accounts/24d4b96f"),
Object: &a.Object{
ID: a.ObjectID("https://littr.git/api/accounts/ana/liked/7ca154ff"),