Changes
15 changed files (+869/-280)
-
-
@@ -1,7 +1,7 @@package activitypub import ( "encoding/json" "time" ) // Activity Types
-
@@ -68,10 +68,89 @@ var validActivityTypes = [...]ActivityVocabularyType{// Actor Types } // IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. // The object property is therefore inappropriate for these activities. type IntransitiveActivity struct { BaseObject // Activity is a subtype of GetID that describes some form of action that may happen, // is currently happening, or has already happened. // The Activity type itself serves as an abstract base type for all types of activities. // 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 { // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // 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 GetLink. Actor Actor `jsonld:"actor,omitempty"`
-
@@ -91,15 +170,6 @@ type IntransitiveActivity struct {// Identifies one or more objects used (or to be used) in the completion of an Activity. Instrument ObjectOrLink `jsonld:"instrument,omitempty"` Source Source `jsonld:"source,omitempty"` } // Activity is a subtype of GetObject that describes some form of action that may happen, // is currently happening, or has already happened. // The Activity type itself serves as an abstract base type for all types of activities. // 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 { IntransitiveActivity // When used within an Activity, describes the direct object of the activity. // For instance, in the activity "John added a movie to his wishlist", // the object of the activity is the movie added.
-
@@ -107,6 +177,107 @@ type Activity struct {Object ObjectOrLink `jsonld:"object,omitempty"` } // IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. // The object property is therefore inappropriate for these activities. type IntransitiveActivity struct { // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // 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 GetLink. Actor Actor `jsonld:"actor,omitempty"` // Describes the indirect object, or target, of the activity. // The precise meaning of the target is largely dependent on the type of action being described // but will often be the object of the English preposition "to". // For instance, in the activity "John added a movie to his wishlist", // the target of the activity is John's wishlist. An activity can have more than one target. Target ObjectOrLink `jsonld:"target,omitempty"` // Describes the result of the activity. For instance, if a particular action results in the creation // of a new resource, the result property can be used to describe that new resource. Result ObjectOrLink `jsonld:"result,omitempty"` // Describes an indirect object of the activity from which the activity is directed. // The precise meaning of the origin is the object of the English preposition "from". // For instance, in the activity "John moved an item to List B from List A", the origin of the activity is "List A". Origin ObjectOrLink `jsonld:"origin,omitempty"` // Identifies one or more objects used (or to be used) in the completion of an Activity. Instrument ObjectOrLink `jsonld:"instrument,omitempty"` Source Source `jsonld:"source,omitempty"` } type ( // Accept indicates that the actor accepts the object. The target property can be used in certain circumstances to indicate // the context into which the object has been accepted.
-
@@ -220,7 +391,102 @@ type (// Either of the anyOf and oneOf properties may be used to express possible answers, // but a Question object must not have both properties. type Question struct { IntransitiveActivity // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // 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 GetLink. Actor Actor `jsonld:"actor,omitempty"` // Describes the indirect object, or target, of the activity. // The precise meaning of the target is largely dependent on the type of action being described // but will often be the object of the English preposition "to". // For instance, in the activity "John added a movie to his wishlist", // the target of the activity is John's wishlist. An activity can have more than one target. Target ObjectOrLink `jsonld:"target,omitempty"` // Describes the result of the activity. For instance, if a particular action results in the creation // of a new resource, the result property can be used to describe that new resource. Result ObjectOrLink `jsonld:"result,omitempty"` // Describes an indirect object of the activity from which the activity is directed. // The precise meaning of the origin is the object of the English preposition "from". // For instance, in the activity "John moved an item to List B from List A", the origin of the activity is "List A". Origin ObjectOrLink `jsonld:"origin,omitempty"` // Identifies one or more objects used (or to be used) in the completion of an Activity. Instrument ObjectOrLink `jsonld:"instrument,omitempty"` Source Source `jsonld:"source,omitempty"` // Identifies an exclusive option for a Question. Use of oneOf implies that the Question // can have only a single answer. To indicate that a Question can have multiple answers, use anyOf. OneOf ObjectOrLink `jsonld:"oneOf,omitempty"`
-
@@ -424,15 +690,17 @@ func ViewNew(id ObjectID, ob ObjectOrLink) *View {// QuestionNew initializes a Question activity func QuestionNew(id ObjectID) *Question { a := IntransitiveActivityNew(id, QuestionType) o := Question{IntransitiveActivity: *a} return &o q := Question{ID: id, Type: QuestionType} q.Name = make(NaturalLanguageValue) q.Content = make(NaturalLanguageValue) q.Summary = make(NaturalLanguageValue) return &q } // ValidActivityType is a validation function for Activity objects func ValidActivityType(_type ActivityVocabularyType) bool { func ValidActivityType(typ ActivityVocabularyType) bool { for _, v := range validActivityTypes { if v == _type { if v == typ { return true } }
-
@@ -440,14 +708,14 @@ func ValidActivityType(_type ActivityVocabularyType) bool {} // ActivityNew initializes a basic activity func ActivityNew(id ObjectID, _type ActivityVocabularyType, ob ObjectOrLink) *Activity { if !ValidActivityType(_type) { _type = ActivityType func ActivityNew(id ObjectID, typ ActivityVocabularyType, ob ObjectOrLink) *Activity { if !ValidActivityType(typ) { typ = ActivityType } o := ObjectNew(id, _type) i := IntransitiveActivity{BaseObject: o} a := Activity{IntransitiveActivity: i} a := Activity{ID: id, Type: typ} a.Name = make(NaturalLanguageValue) a.Content = make(NaturalLanguageValue) a.Summary = make(NaturalLanguageValue) a.Object = ob
-
@@ -455,13 +723,16 @@ func ActivityNew(id ObjectID, _type ActivityVocabularyType, ob ObjectOrLink) *Ac} // IntransitiveActivityNew initializes a intransitive activity func IntransitiveActivityNew(id ObjectID, _type ActivityVocabularyType) *IntransitiveActivity { if !ValidActivityType(_type) { _type = IntransitiveActivityType func IntransitiveActivityNew(id ObjectID, typ ActivityVocabularyType) *IntransitiveActivity { if !ValidActivityType(typ) { typ = IntransitiveActivityType } o := ObjectNew(id, _type) i := IntransitiveActivity{ID: id, Type: typ} i.Name = make(NaturalLanguageValue) i.Content = make(NaturalLanguageValue) i.Summary = make(NaturalLanguageValue) return &IntransitiveActivity{BaseObject: o} return &i } func (a *Activity) RecipientsDeduplication() {
-
@@ -469,44 +740,48 @@ func (a *Activity) RecipientsDeduplication() {actor.Append(a.Actor) recipientsDeduplication(&actor, &a.To, &a.Bto, &a.CC, &a.BCC) } func (i *IntransitiveActivity) RecipientsDeduplication() { var actor ObjectsArr actor.Append(i.Actor) recipientsDeduplication(&actor, &i.To, &i.Bto, &i.CC, &i.BCC) } func (b *Block) RecipientsDeduplication() { var dedupObjects ObjectsArr dedupObjects.Append(b.Actor) dedupObjects.Append(b.Object) recipientsDeduplication(&dedupObjects, &b.To, &b.Bto, &b.CC, &b.BCC) } func (i *IntransitiveActivity) GetLink() Link { return Link{} func (c *Create) RecipientsDeduplication() { var dedupObjects ObjectsArr dedupObjects.Append(c.Actor) dedupObjects.Append(c.Object) recipientsDeduplication(&dedupObjects, &c.To, &c.Bto, &c.CC, &c.BCC) } func (i *IntransitiveActivity) GetType() ActivityVocabularyType { return i.Type } func (i *IntransitiveActivity) IsLink() bool { return false } func (i *IntransitiveActivity) GetObject() BaseObject { return i.BaseObject func (i *IntransitiveActivity) GetID() ObjectID { return i.ID } func (i *IntransitiveActivity) IsObject() bool { return true } func (a *Activity) GetLink() Link { return Link{} func (a *Activity) GetType() ActivityVocabularyType { return a.Type } func (a *Activity) IsLink() bool { return false } func (a *Activity) GetObject() BaseObject { return a.IntransitiveActivity.GetObject() func (a *Activity) GetID() ObjectID { return a.ID } func (a *Activity) IsObject() bool { return true } /* func (a *Activity) UnmarshalJSON(data []byte) error { var temp map[string]json.RawMessage
-
@@ -517,3 +792,4 @@ func (a *Activity) UnmarshalJSON(data []byte) error {return nil } */
-
-
-
@@ -620,18 +620,18 @@ func TestIntransitiveActivityRecipientsDeduplication(t *testing.T) {t.Errorf("%T.BCC should have exactly 0(zero) elements, not %d", b, len(b.BCC)) } } func TestActivity_GetLink(t *testing.T) { func TestActivity_GetID(t *testing.T) { a := ActivityNew("test", ActivityType, Person{}) if a.GetLink().ID != "" { t.Errorf("%T should return an empty %T object. Received %#v", a, a.GetLink(), a.GetLink()) if a.GetID() != "test" { t.Errorf("%T should return an empty %T object. Received %#v", a, a, a) } } func TestActivity_GetObject(t *testing.T) { func TestActivity_GetIDGetType(t *testing.T) { a := ActivityNew("test", ActivityType, Person{}) if a.GetObject().ID != "test" || a.GetObject().Type != ActivityType { t.Errorf("%T should not return an empty %T object. Received %#v", a, a.GetObject(), a.GetObject()) if a.GetID() != "test" || a.GetType() != ActivityType { t.Errorf("%T should not return an empty %T object. Received %#v", a, a, a) } } func TestActivity_IsLink(t *testing.T) {
-
@@ -651,15 +651,15 @@ func TestActivity_IsObject(t *testing.T) {func TestIntransitiveActivity_GetLink(t *testing.T) { i := IntransitiveActivityNew("test", QuestionType) if i.GetLink().ID != "" { t.Errorf("%T should return an empty %T object. Received %#v", i, i.GetLink(), i.GetLink()) if i.GetID() != "test" { t.Errorf("%T should return an empty %T object. Received %#v", i, i, i) } } func TestIntransitiveActivity_GetObject(t *testing.T) { i := IntransitiveActivityNew("test", QuestionType) if i.GetObject().ID != "test" || i.GetObject().Type != QuestionType { t.Errorf("%T should not return an empty %T object. Received %#v", i, i.GetObject(), i.GetObject()) if i.GetID() != "test" || i.GetType() != QuestionType { t.Errorf("%T should not return an empty %T object. Received %#v", i, i, i) } } func TestIntransitiveActivity_IsLink(t *testing.T) {
-
-
-
@@ -1,5 +1,7 @@package activitypub import "time" // Actor Types const ( ApplicationType ActivityVocabularyType = "Application"
-
@@ -46,10 +48,86 @@ type Endpoints struct {// Actor is generally one of the ActivityStreams Actor Types, but they don't have to be. // For example, a Profile object might be used as an actor, or a type from an ActivityStreams extension. // Actors are retrieved like any other GetObject in ActivityPub. // Actors are retrieved like any other GetID in ActivityPub. // Like other ActivityStreams objects, actors have an id, which is a URI. type Actor struct { BaseObject // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox. Inbox InboxStream `jsonld:"inbox,omitempty"`
-
@@ -96,9 +174,9 @@ type () // ValidActorType validates the passed type against the valid actor types func ValidActorType(_type ActivityVocabularyType) bool { func ValidActorType(typ ActivityVocabularyType) bool { for _, v := range validActorTypes { if v == _type { if v == typ { return true } }
-
@@ -106,13 +184,15 @@ func ValidActorType(_type ActivityVocabularyType) bool {} // ActorNew initializes an Actor type actor func ActorNew(id ObjectID, _type ActivityVocabularyType) *Actor { if !ValidActorType(_type) { _type = ActorType func ActorNew(id ObjectID, typ ActivityVocabularyType) *Actor { if !ValidActorType(typ) { typ = ActorType } o := ObjectNew(id, _type) a := Actor{BaseObject: o} a := Actor{ID: id, Type: typ} a.Name = make(NaturalLanguageValue) a.Content = make(NaturalLanguageValue) a.Summary = make(NaturalLanguageValue) in := InboxNew() a.Inbox = InboxStream(*in)
-
@@ -161,37 +241,116 @@ func (a Actor) IsLink() bool {return a.Type == LinkType || ValidLinkType(a.Type) } // IsObject validates if current Actor is an GetObject // IsObject validates if current Actor is an GetID func (a Actor) IsObject() bool { return a.Type == ObjectType || ValidObjectType(a.Type) } // GetObject returns the GetObject corresponding to the Actor object func (a Actor) GetObject() BaseObject { return a.BaseObject // GetID returns the GetID corresponding to the Actor object func (a Actor) GetID() ObjectID { return a.ID } // GetLink returns the GetLink corresponding to the Actor object func (a Actor) Link() Link { return Link{} func (a Actor) GetType() ActivityVocabularyType { return a.Type } // IsLink validates if current Application is a GetLink func (a Application) IsLink() bool { return a.Type == LinkType || ValidLinkType(a.Type) } // IsObject validates if current Application is an GetID func (a Application) IsObject() bool { return a.Type == ObjectType || ValidObjectType(a.Type) } // GetID returns the GetID corresponding to the Application object func (a Application) GetID() ObjectID { return a.ID } // GetLink returns the GetLink corresponding to the Application object func (a Application) GetType() ActivityVocabularyType { return a.Type } // IsLink validates if current Group is a GetLink func (a Group) IsLink() bool { return a.Type == LinkType || ValidLinkType(a.Type) } // IsObject validates if current Group is an GetID func (a Group) IsObject() bool { return a.Type == ObjectType || ValidObjectType(a.Type) } // GetID returns the GetID corresponding to the Group object func (a Group) GetID() ObjectID { return a.ID } // GetLink returns the GetLink corresponding to the Group object func (a Group) GetType() ActivityVocabularyType { return a.Type } // IsLink validates if current Organization is a GetLink func (a Organization) IsLink() bool { return a.Type == LinkType || ValidLinkType(a.Type) } // IsObject validates if current Organization is an GetID func (a Organization) IsObject() bool { return a.Type == ObjectType || ValidObjectType(a.Type) } // GetID returns the GetID corresponding to the Organization object func (a Organization) GetID() ObjectID { return a.ID } // GetLink returns the GetLink corresponding to the Organization object func (a Organization) GetType() ActivityVocabularyType { return a.Type } // IsLink validates if current Service is a GetLink func (a Service) IsLink() bool { return a.Type == LinkType || ValidLinkType(a.Type) } // IsObject validates if current Service is an GetID func (a Service) IsObject() bool { return a.Type == ObjectType || ValidObjectType(a.Type) } // GetID returns the GetID corresponding to the Service object func (a Service) GetID() ObjectID { return a.ID } // GetLink returns the GetLink corresponding to the Service object func (a Service) GetType() ActivityVocabularyType { return a.Type } // IsLink validates if current Person is a GetLink func (p Person) IsLink() bool { return p.Type == LinkType || ValidLinkType(p.Type) } // IsObject validates if current Person is an GetObject // IsObject validates if current Person is an GetID func (p Person) IsObject() bool { return p.Type == ObjectType || ValidObjectType(p.Type) } // GetObject returns the GetObject corresponding to the Person object func (p Person) GetObject() BaseObject { return p.BaseObject // GetID returns the GetID corresponding to the Person object func (p Person) GetID() ObjectID { return p.ID } // GetLink returns the GetLink corresponding to the Person object func (p Person) Link() Link { return Link{} func (p Person) GetType() ActivityVocabularyType { return p.Type }
-
-
-
@@ -116,42 +116,29 @@ func TestActor_IsObject(t *testing.T) {func TestActor_Object(t *testing.T) { m := ActorNew("test", ActorType) if reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should not be an empty activity pub object", m.GetObject()) if reflect.DeepEqual(ObjectID(""), m.GetID()) { t.Errorf("%#v should not be an empty activity pub object", m.GetID()) } } func TestActor_Link(t *testing.T) { func TestActor_Type(t *testing.T) { m := ActorNew("test", ActorType) if !reflect.DeepEqual(Link{}, m.Link()) { t.Errorf("%#v should be an empty GetLink object", m.Link()) if m.GetType() != ActorType { t.Errorf("%#v should be an empty GetLink object", m.GetType()) } } func TestPerson_IsLink(t *testing.T) { m := PersonNew("test") if m.IsLink() { t.Errorf("%#v should not be a valid GetLink", m.Type) t.Errorf("%T should not be a valid GetLink", m) } } func TestPerson_IsObject(t *testing.T) { m := PersonNew("test") if !m.IsObject() { t.Errorf("%#v should be a valid object", m.Type) t.Errorf("%T should be a valid object", m) } } func TestPerson_Object(t *testing.T) { m := PersonNew("test") if reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should not be an empty activity pub object", m.GetObject()) } } func TestPerson_Link(t *testing.T) { m := PersonNew("test") if !reflect.DeepEqual(Link{}, m.Link()) { t.Errorf("%#v should be an empty GetLink object", m.Link()) } }
-
-
-
@@ -1,5 +1,7 @@package activitypub import "time" var validCollectionTypes = [...]ActivityVocabularyType{CollectionType, OrderedCollectionType} // Page represents a Web Page.
-
@@ -9,9 +11,85 @@ type CollectionInterface interface {Append(o ObjectOrLink) error } // Collection is a subtype of GetObject that represents ordered or unordered sets of GetObject or GetLink instances. // Collection is a subtype of GetID that represents ordered or unordered sets of GetID or GetLink instances. type Collection struct { BaseObject // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. TotalItems uint `jsonld:"totalItems,omitempty"`
-
@@ -22,7 +100,83 @@ 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 { BaseObject // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetID or GetLink 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 ObjectOrLink `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 ObjectOrLink `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 ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetID 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 ObjectOrLink `jsonld:"_"` // 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 ObjectOrLink `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 ImageOrLink `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 ImageOrLink `jsonld:"image,omitempty"` // Indicates one or more entities for which this object is considered a response. InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` // Indicates one or more physical or logical locations associated with the object. Location ObjectOrLink `jsonld:"location,omitempty"` // Identifies an entity that provides a preview of this object. Preview ObjectOrLink `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 ObjectOrLink `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 GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `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 GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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"` // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. TotalItems uint `jsonld:"totalItems,omitempty"`
-
@@ -68,9 +222,9 @@ type OrderedCollectionPage struct {} // ValidCollectionType validates against the valid collection types func ValidCollectionType(_type ActivityVocabularyType) bool { func ValidCollectionType(typ ActivityVocabularyType) bool { for _, v := range validCollectionTypes { if v == _type { if v == typ { return true } }
-
@@ -79,16 +233,21 @@ func ValidCollectionType(_type ActivityVocabularyType) bool {// CollectionNew initializes a new Collection func CollectionNew(id ObjectID) *Collection { o := ObjectNew(id, CollectionType) return &Collection{BaseObject: o} c := Collection{ID: id, Type: CollectionType} c.Name = make(NaturalLanguageValue) c.Content = make(NaturalLanguageValue) c.Summary = make(NaturalLanguageValue) return &c } // CollectionNew initializes a new Collection func OrderedCollectionNew(id ObjectID) *OrderedCollection { o := ObjectNew(id, OrderedCollectionType) o := OrderedCollection{ID: id, Type: OrderedCollectionType} o.Name = make(NaturalLanguageValue) o.Content = make(NaturalLanguageValue) o.Summary = make(NaturalLanguageValue) return &OrderedCollection{BaseObject: o} return &o } // CollectionNew initializes a new Collection
-
@@ -114,3 +273,27 @@ func (c *Collection) Append(o ObjectOrLink) error {c.TotalItems++ return nil } func (c *Collection) GetType() ActivityVocabularyType { return c.Type } func (c *Collection) IsLink() bool { return false } func (c *Collection) GetID() ObjectID { return c.ID } func (c *Collection) IsObject() bool { return true } func (c *OrderedCollection) GetType() ActivityVocabularyType { return c.Type } func (c *OrderedCollection) IsLink() bool { return false } func (c *OrderedCollection) GetID() ObjectID { return c.ID } func (c *OrderedCollection) IsObject() bool { return true }
-
-
-
@@ -62,15 +62,15 @@ func TestValidCollectionType(t *testing.T) {func Test_OrderedCollection_Append(t *testing.T) { id := ObjectID("test") val := BaseObject{ID: ObjectID("grrr")} val := Object{ID: ObjectID("grrr")} c := OrderedCollectionNew(id) c.Append(val) if c.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an GetObject", c.GetObject().ID) t.Errorf("Inbox collection of %q should have exactly an GetID", c.GetID()) } if !reflect.DeepEqual(c.OrderedItems[0].GetObject(), val) { if !reflect.DeepEqual(c.OrderedItems[0], val) { t.Errorf("First item in Inbox is does not match %q", val.ID) } }
-
@@ -78,15 +78,15 @@ func Test_OrderedCollection_Append(t *testing.T) {func Test_Collection_Append(t *testing.T) { id := ObjectID("test") val := BaseObject{ID: ObjectID("grrr")} val := Object{ID: ObjectID("grrr")} c := CollectionNew(id) c.Append(val) if c.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an GetObject", c.GetObject().ID) t.Errorf("Inbox collection of %q should have exactly an GetID", c.GetID()) } if !reflect.DeepEqual(c.Items[0].GetObject(), val) { if !reflect.DeepEqual(c.Items[0], val) { t.Errorf("First item in Inbox is does not match %q", val.ID) } }
-
-
-
@@ -16,7 +16,7 @@ func CreateActivityNew(id ObjectID, a ObjectOrLink, o ObjectOrLink) CreateActiviok := false if a != nil { typ := a.GetObject().Type typ := a.GetType() if typ == ApplicationType { var app Application app, ok = a.(Application)
-
-
-
@@ -39,31 +39,31 @@ func TestCreateActivityNewWithApplication(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != a.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, a.ID) if c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), a.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), a.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), a.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), a.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), a.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*a)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*a)) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } if c1.Activity.Actor.Inbox.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an GetObject", c1.Activity.Actor.GetObject().ID) t.Errorf("Inbox collection of %q should have exactly an GetID", c1.Activity.Actor.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor.Inbox.OrderedItems[0].GetObject(), n.GetObject()) { t.Errorf("First item in Inbox is does not match %q", n.GetObject().ID) if !reflect.DeepEqual(c1.Activity.Actor.Inbox.OrderedItems[0].GetID(), n.GetID()) { t.Errorf("First item in Inbox is does not match %q", n.GetID()) } }
-
@@ -83,25 +83,25 @@ func TestCreateActivityNewWithGroup(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != g.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, g.ID) if c1.Activity.Actor.GetID() != g.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), g.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), g.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), g.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), g.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*g)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*g)) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
@@ -121,25 +121,25 @@ func TestCreateActivityNewWithOrganization(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != o.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, o.ID) if c1.Activity.Actor.GetID() != o.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), o.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), o.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), o.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), o.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*o)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*o)) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
@@ -159,25 +159,25 @@ func TestCreateActivityNewWithPerson(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != b.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, b.ID) if c1.Activity.Actor.GetID() != b.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), b.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), b.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), b.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), b.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*b)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*b)) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
@@ -197,25 +197,25 @@ func TestCreateActivityNewWithService(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != s.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, s.ID) if c1.Activity.Actor.GetID() != s.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), s.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), s.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), s.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), s.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*s)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*s)) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
@@ -235,24 +235,24 @@ func TestCreateActivityNewWithActor(t *testing.T) {if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if c1.Activity.Actor.GetObject().ID != a.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetObject().ID, a.ID) if c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", c1.Activity.Actor.GetID(), a.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetObject(), a.GetObject()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetObject(), a.GetObject()) if !reflect.DeepEqual(c1.Activity.Actor.GetID(), a.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), a.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, *a) } */ if c1.Activity.Object.GetObject().ID != n.ID { t.Errorf("GetObject %q different than expected %q", c1.Activity.Object.GetObject().ID, n.ID) if c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetObject(), n.GetObject()) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object.GetObject(), n.GetObject()) if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetObject %#v different than expected %#v", c1.Activity.Object, n) t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
-
-
@@ -15,9 +15,12 @@ type (// InboxNew initializes a new Inbox func InboxNew() *Inbox { id := ObjectID("inbox") o := ObjectNew(id, OrderedCollectionType) i := Inbox{BaseObject: o} i := Inbox{ID: id, Type: OrderedCollectionType} i.Name = make(NaturalLanguageValue) i.Content = make(NaturalLanguageValue) i.Summary = make(NaturalLanguageValue) i.TotalItems = 0 return &i
-
-
-
@@ -44,9 +44,9 @@ type Link struct {type Mention Link // ValidLinkType validates a type against the valid link types func ValidLinkType(_type ActivityVocabularyType) bool { func ValidLinkType(typ ActivityVocabularyType) bool { for _, v := range validLinkTypes { if v == _type { if v == typ { return true } }
-
@@ -54,11 +54,11 @@ func ValidLinkType(_type ActivityVocabularyType) bool {} // LinkNew initializes a new GetLink func LinkNew(id ObjectID, _type ActivityVocabularyType) *Link { if !ValidLinkType(_type) { _type = LinkType func LinkNew(id ObjectID, typ ActivityVocabularyType) *Link { if !ValidLinkType(typ) { typ = LinkType } return &Link{ID: id, Type: _type} return &Link{ID: id, Type: typ} } // MentionNew initializes a new Mention
-
@@ -71,19 +71,19 @@ func (l Link) IsLink() bool {return l.Type == LinkType || ValidLinkType(l.Type) } // IsObject validates if current GetLink is an GetObject // IsObject validates if current GetLink is an GetID func (l Link) IsObject() bool { return l.Type == ObjectType || ValidObjectType(l.Type) } // GetObject returns the GetObject corresponding to the Mention object func (l Link) GetObject() BaseObject { return BaseObject{} // GetID returns the GetID corresponding to the Mention object func (l Link) GetID() ObjectID { return l.ID } // GetLink returns the GetLink corresponding to the Mention object func (l Link) GetLink() Link { return l func (l Link) GetType() ActivityVocabularyType { return l.Type } // IsLink validates if current Mention is a GetLink
-
@@ -91,17 +91,17 @@ func (m Mention) IsLink() bool {return m.Type == MentionType || ValidLinkType(m.Type) } // IsObject validates if current Mention is an GetObject // IsObject validates if current Mention is an GetID func (m Mention) IsObject() bool { return m.Type == ObjectType || ValidObjectType(m.Type) } // GetObject returns the GetObject corresponding to the Mention object func (m Mention) GetObject() BaseObject { return BaseObject{} // GetID returns the GetID corresponding to the Mention object func (m Mention) GetID() ObjectID { return m.ID } // GetLink returns the GetLink corresponding to the Mention object func (m Mention) GetLink() Link { return Link(m) func (m Mention) GetType() ActivityVocabularyType { return m.Type }
-
-
-
@@ -73,14 +73,7 @@ func TestMention_IsObject(t *testing.T) {func TestMention_Object(t *testing.T) { m := MentionNew("test") if !reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should be an empty object", m.GetObject()) if !reflect.DeepEqual(ObjectID("test"), m.GetID()) { t.Errorf("%#v should be an empty object", m.GetID()) } } func TestMention_Link(t *testing.T) { m := MentionNew("test") if !reflect.DeepEqual(Link(*m), m.GetLink()) { t.Errorf("%#v should be a GetLink object", m.GetLink()) } } }
-
-
-
@@ -32,7 +32,7 @@ const (CollectionType ActivityVocabularyType = "Collection" OrderedCollectionType ActivityVocabularyType = "OrderedCollection" // Activity Pub GetObject Types // Activity Pub GetID Types ArticleType ActivityVocabularyType = "Article" AudioType ActivityVocabularyType = "Audio" DocumentType ActivityVocabularyType = "Document"
-
@@ -83,19 +83,17 @@ var validObjectTypes = [...]ActivityVocabularyType{type ( // ActivityVocabularyType is the data type for an Activity type object ActivityVocabularyType string // ActivityObject is a subtype of GetObject that describes some form of action that may happen, // ActivityObject is a subtype of GetID that describes some form of action that may happen, // is currently happening, or has already happened ActivityObject interface{} // ObjectOrLink describes an object of any kind. ObjectOrLink interface { IsLink() bool IsObject() bool GetObject() BaseObject GetLink() Link GetID() ObjectID GetType() ActivityVocabularyType } // ObjectsArr is a named type for matching an ObjectOrLink slice type to Collection interface ObjectsArr []ObjectOrLink // LinkOrURI is an interface that GetObject and GetLink structs implement, and at the same time // LinkOrURI is an interface that GetID and GetLink structs implement, and at the same time // they are kept disjointed LinkOrURI interface{} // ImageOrLink is an interface that Image and GetLink structs implement
-
@@ -108,14 +106,14 @@ type (NaturalLanguageValue map[LangRef]string ) // IsLink validates if current Activity Pub GetObject is a GetLink func (o BaseObject) IsLink() bool { return ValidLinkType(o.Type) // IsLink validates if current Activity Pub GetID is a GetLink func (o Object) IsLink() bool { return false } // IsObject validates if current Activity Pub GetObject is an GetObject func (o BaseObject) IsObject() bool { return ValidObjectType(o.Type) // IsObject validates if current Activity Pub GetID is an GetID func (o Object) IsObject() bool { return true } // MarshalJSON serializes the NaturalLanguageValue into JSON
-
@@ -175,12 +173,12 @@ func (n *NaturalLanguageValue) UnmarshalJSON(data []byte) error {} // Describes an object of any kind. // The Activity Pub GetObject type serves as the base type for most of the other kinds of objects defined in the Activity Vocabulary, // The Activity Pub GetID 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 BaseObject struct { // Provides the globally unique identifier for an Activity Pub GetObject or GetLink. type Object struct { // Provides the globally unique identifier for an Activity Pub GetID or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetObject or GetLink type. Multiple values may be specified. // Identifies the Activity Pub GetID or GetLink 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.
-
@@ -194,7 +192,7 @@ type BaseObject struct {// Identifies one or more entities that represent the total population of entities // for which the object can considered to be relevant. Audience ObjectOrLink `jsonld:"audience,omitempty"` // The content or textual representation of the Activity Pub GetObject encoded as a JSON string. // The content or textual representation of the Activity Pub GetID 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.)
-
@@ -234,7 +232,7 @@ type BaseObject struct {// 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 GetObject. // One or more "tags" that have been associated with an objects. A tag can be any kind of Activity Pub GetID. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. Tag ObjectOrLink `jsonld:"tag,omitempty"`
-
@@ -242,13 +240,13 @@ type BaseObject struct {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 GetObject // Identifies an entity considered to be part of the public primary audience of an Activity Pub GetID To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub GetObject that is part of the private primary audience of this Activity Pub GetObject. // Identifies an Activity Pub GetID that is part of the private primary audience of this Activity Pub GetID. Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub GetObject that is part of the public secondary audience of this Activity Pub GetObject. // Identifies an Activity Pub GetID that is part of the public secondary audience of this Activity Pub GetID. CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetObject. // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub GetID. BCC ObjectsArr `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.
-
@@ -268,9 +266,9 @@ type Source struct {} // ValidGenericType validates the type against the valid generic object types func ValidGenericType(_type ActivityVocabularyType) bool { func ValidGenericType(typ ActivityVocabularyType) bool { for _, v := range validGenericObjectTypes { if v == _type { if v == typ { return true } }
-
@@ -278,35 +276,35 @@ func ValidGenericType(_type ActivityVocabularyType) bool {} // ValidObjectType validates the type against the valid object types func ValidObjectType(_type ActivityVocabularyType) bool { func ValidObjectType(typ ActivityVocabularyType) bool { for _, v := range validObjectTypes { if v == _type { if v == typ { return true } } return ValidActivityType(_type) || ValidActorType(_type) || ValidCollectionType(_type) || ValidGenericType(_type) return ValidActivityType(typ) || ValidActorType(typ) || ValidCollectionType(typ) || ValidGenericType(typ) } // ObjectNew initializes a new GetObject func ObjectNew(id ObjectID, _type ActivityVocabularyType) BaseObject { if !(ValidObjectType(_type)) { _type = ObjectType // ObjectNew initializes a new GetID func ObjectNew(id ObjectID, typ ActivityVocabularyType) *Object { if !(ValidObjectType(typ)) { typ = ObjectType } o := BaseObject{ID: id, Type: _type} o := Object{ID: id, Type: typ} o.Name = make(NaturalLanguageValue) o.Content = make(NaturalLanguageValue) o.Summary = make(NaturalLanguageValue) return o return &o } // GetObject returns the GetObject corresponding to the GetObject object func (o BaseObject) GetObject() BaseObject { return o // GetID returns the GetID corresponding to the GetID object func (o Object) GetID() ObjectID{ return o.ID } // GetLink returns the GetLink corresponding to the GetObject object func (o BaseObject) GetLink() Link { return Link{} // GetLink returns the GetLink corresponding to the GetID object func (o Object) GetType() ActivityVocabularyType { return o.Type } // Append facilitates adding elements to ObjectOrLink arrays
-
@@ -322,7 +320,7 @@ func (c *ObjectsArr) Append(o ObjectOrLink) error {return nil } // recipientsDeduplication normalizes the received recipient lists // recipientsDeduplication normalizes the received arguments lists func recipientsDeduplication(recArgs ...*ObjectsArr) error { recIds := make([]ObjectID, 0)
-
@@ -335,14 +333,14 @@ func recipientsDeduplication(recArgs ...*ObjectsArr) error {for i, rec := range *recList { save := true for _, id := range recIds { if rec.GetObject().ID == id { if rec.GetID() == id { // mark the element for removal toRemove = append(toRemove, i) save = false } } if save { recIds = append(recIds, rec.GetObject().ID) recIds = append(recIds, rec.GetID()) } }
-
-
-
@@ -127,17 +127,11 @@ func TestObject_IsObject(t *testing.T) {} } func TestObject_Link(t *testing.T) { o := ObjectNew("test", ObjectType) if !reflect.DeepEqual(Link{}, o.GetLink()) { t.Errorf("%#v should be an empty GetLink object", o.GetLink()) } } func TestObjectsArr_Append(t *testing.T) { d := make(ObjectsArr, 0) val := BaseObject{ID: ObjectID("grrr")} val := Object{ID: ObjectID("grrr")} d.Append(val)
-
-
-
@@ -26,66 +26,66 @@ S2S Server: Activities requiring the object propertyadd := activitypub.AddNew("https://localhost/myactivity", obj, nil) if add.Object == nil { t.Errorf("Missing GetObject in Add activity %#v", add.Object) t.Errorf("Missing GetID in Add activity %#v", add.Object) } if add.Object != obj { t.Errorf("Add.GetObject different than what we initialized %#v %#v", add.Object, obj) t.Errorf("Add.GetID different than what we initialized %#v %#v", add.Object, obj) } block := activitypub.BlockNew("https://localhost/myactivity", obj) if block.Object == nil { t.Errorf("Missing GetObject in Add activity %#v", block.Object) t.Errorf("Missing GetID in Add activity %#v", block.Object) } if block.Object != obj { t.Errorf("Block.GetObject different than what we initialized %#v %#v", block.Object, obj) t.Errorf("Block.GetID different than what we initialized %#v %#v", block.Object, obj) } create := activitypub.CreateNew("https://localhost/myactivity", obj) if create.Object == nil { t.Errorf("Missing GetObject in Add activity %#v", create.Object) t.Errorf("Missing GetID in Add activity %#v", create.Object) } if create.Object != obj { t.Errorf("Create.GetObject different than what we initialized %#v %#v", create.Object, obj) t.Errorf("Create.GetID different than what we initialized %#v %#v", create.Object, obj) } delete := activitypub.DeleteNew("https://localhost/myactivity", obj) if delete.Object == nil { t.Errorf("Missing GetObject in Delete activity %#v", delete.Object) t.Errorf("Missing GetID in Delete activity %#v", delete.Object) } if delete.Object != obj { t.Errorf("Delete.GetObject different than what we initialized %#v %#v", delete.Object, obj) t.Errorf("Delete.GetID different than what we initialized %#v %#v", delete.Object, obj) } follow := activitypub.FollowNew("https://localhost/myactivity", obj) if follow.Object == nil { t.Errorf("Missing GetObject in Follow activity %#v", follow.Object) t.Errorf("Missing GetID in Follow activity %#v", follow.Object) } if follow.Object != obj { t.Errorf("Follow.GetObject different than what we initialized %#v %#v", follow.Object, obj) t.Errorf("Follow.GetID different than what we initialized %#v %#v", follow.Object, obj) } like := activitypub.LikeNew("https://localhost/myactivity", obj) if like.Object == nil { t.Errorf("Missing GetObject in Like activity %#v", like.Object) t.Errorf("Missing GetID in Like activity %#v", like.Object) } if like.Object != obj { t.Errorf("Like.GetObject different than what we initialized %#v %#v", add.Object, obj) t.Errorf("Like.GetID different than what we initialized %#v %#v", add.Object, obj) } update := activitypub.UpdateNew("https://localhost/myactivity", obj) if update.Object == nil { t.Errorf("Missing GetObject in Update activity %#v", update.Object) t.Errorf("Missing GetID in Update activity %#v", update.Object) } if update.Object != obj { t.Errorf("Update.GetObject different than what we initialized %#v %#v", update.Object, obj) t.Errorf("Update.GetID different than what we initialized %#v %#v", update.Object, obj) } undo := activitypub.UndoNew("https://localhost/myactivity", obj) if undo.Object == nil { t.Errorf("Missing GetObject in Undo activity %#v", undo.Object) t.Errorf("Missing GetID in Undo activity %#v", undo.Object) } if undo.Object != obj { t.Errorf("Undo.GetObject different than what we initialized %#v %#v", undo.Object, obj) t.Errorf("Undo.GetID different than what we initialized %#v %#v", undo.Object, obj) } }
-
@@ -155,11 +155,11 @@ S2S Server: Deduplication of recipient listcheckDedup := func(list activitypub.ObjectsArr, recIds *[]activitypub.ObjectID) error { for _, rec := range list { for _, id := range *recIds { if rec.GetObject().ID == id { if rec.GetID() == id { return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id) } } *recIds = append(*recIds, rec.GetObject().ID) *recIds = append(*recIds, rec.GetID()) } return nil }
-
@@ -216,8 +216,8 @@ Activity being notified aboutcheckActor := func(list activitypub.ObjectsArr, actor activitypub.Actor) error { for _, rec := range list { if rec.GetObject().ID == actor.GetObject().ID { return fmt.Errorf("%T[%s] Actor of activity should not be in the recipients list", rec, actor.GetObject().ID) if rec.GetID() == actor.GetID() { return fmt.Errorf("%T[%s] Actor of activity should not be in the recipients list", rec, actor.GetID()) } } return nil
-
@@ -268,8 +268,8 @@ S2S Server: Do-not-deliver considerationscheckActor := func(list activitypub.ObjectsArr, ob activitypub.ObjectOrLink) error { for _, rec := range list { if rec.GetObject().ID == ob.GetObject().ID { return fmt.Errorf("%T[%s] of activity should not be in the recipients list", rec, ob.GetObject().ID) if rec.GetID() == ob.GetID() { return fmt.Errorf("%T[%s] of activity should not be in the recipients list", rec, ob.GetID()) } } return nil
-
-
-
@@ -29,8 +29,8 @@ var allTests = tests{"empty": testPair{ path: "./mocks/empty.json", expected: true, blank: &a.BaseObject{}, result: &a.BaseObject{}, blank: &a.Object{}, result: &a.Object{}, }, "link_simple": testPair{ path: "./mocks/link_simple.json",
-
@@ -49,8 +49,8 @@ var allTests = tests{"object_simple": testPair{ path: "./mocks/object_simple.json", expected: true, blank: &a.BaseObject{}, result: &a.BaseObject{ blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Name: a.NaturalLanguageValue{
-
@@ -63,12 +63,8 @@ var allTests = tests{expected: true, blank: &a.Activity{}, result: &a.Activity{ IntransitiveActivity: a.IntransitiveActivity{ BaseObject: a.BaseObject{ Type: a.ActivityType, Summary: a.NaturalLanguageValue{a.LangRef("-"): "Sally did something to a note"}, }, }, Type: a.ActivityType, Summary: a.NaturalLanguageValue{a.LangRef("-"): "Sally did something to a note"}, }, }, }
-