Changes
12 changed files (+165/-39)
-
-
@@ -1,5 +1,9 @@package activitypub import ( "encoding/json" ) // Activity Types const ( AcceptType ActivityVocabularyType = "Accept"
-
@@ -67,7 +71,7 @@ var validActivityTypes = [...]ActivityVocabularyType{// IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. // The object property is therefore inappropriate for these activities. type IntransitiveActivity struct { Object BaseObject // 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"`
-
@@ -95,7 +99,7 @@ type IntransitiveActivity struct {// 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 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.
-
@@ -216,7 +220,7 @@ 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 IntransitiveActivity // 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"`
-
@@ -421,7 +425,7 @@ 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} o := Question{IntransitiveActivity: *a} return &o }
-
@@ -441,9 +445,10 @@ func ActivityNew(id ObjectID, _type ActivityVocabularyType, ob ObjectOrLink) *Ac_type = ActivityType } o := ObjectNew(id, _type) i := IntransitiveActivity{Object: o} i := IntransitiveActivity{BaseObject: o} a := Activity{IntransitiveActivity: i} a := Activity{IntransitiveActivity: &i} a.Object = ob return &a
-
@@ -456,7 +461,7 @@ func IntransitiveActivityNew(id ObjectID, _type ActivityVocabularyType) *Intrans} o := ObjectNew(id, _type) return &IntransitiveActivity{Object: o} return &IntransitiveActivity{BaseObject: o} } func (a *Activity) RecipientsDeduplication() {
-
@@ -477,3 +482,38 @@ func (b *Block) RecipientsDeduplication() {dedupObjects.Append(b.Object) recipientsDeduplication(&dedupObjects, &b.To, &b.Bto, &b.CC, &b.BCC) } func (i *IntransitiveActivity) GetLink() Link { return Link{} } func (i *IntransitiveActivity) IsLink() bool { return false } func (i *IntransitiveActivity) GetObject() BaseObject { return i.BaseObject } func (i *IntransitiveActivity) IsObject() bool { return true } func (a *Activity) GetLink() Link { return Link{} } func (a *Activity) IsLink() bool { return false } func (a *Activity) GetObject() BaseObject { return a.IntransitiveActivity.GetObject() } func (a *Activity) IsObject() bool { return true } func (a *Activity) UnmarshalJSON(data []byte) error { var temp map[string]json.RawMessage err := json.Unmarshal(data, &temp) if err != nil { return err } return nil }
-
-
-
@@ -620,3 +620,68 @@ 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) { 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()) } } func TestActivity_GetObject(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()) } } func TestActivity_IsLink(t *testing.T) { a := ActivityNew("test", ActivityType, Person{}) if a.IsLink() { t.Errorf("%T should not respond true to IsLink", a) } } func TestActivity_IsObject(t *testing.T) { a := ActivityNew("test", ActivityType, Person{}) if !a.IsObject() { t.Errorf("%T should respond true to IsObject", a) } } 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()) } } 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()) } } func TestIntransitiveActivity_IsLink(t *testing.T) { i := IntransitiveActivityNew("test", QuestionType) if i.IsLink() { t.Errorf("%T should not respond true to IsLink", i) } } func TestIntransitiveActivity_IsObject(t *testing.T) { i := IntransitiveActivityNew("test", ActivityType) if !i.IsObject() { t.Errorf("%T should respond true to IsObject", i) } } func TestActivity_RecipientsDeduplication(t *testing.T) { t.Skip("See TestDeduplication") } func TestIntransitiveActivity_RecipientsDeduplication(t *testing.T) { t.Skip("See TestDeduplication") } func TestBlock_RecipientsDeduplication(t *testing.T) { t.Skip("See TestDeduplication") }
-
-
-
@@ -49,7 +49,7 @@ type Endpoints struct {// Actors are retrieved like any other GetObject in ActivityPub. // Like other ActivityStreams objects, actors have an id, which is a URI. type Actor struct { Object BaseObject // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox. Inbox InboxStream `jsonld:"inbox,omitempty"`
-
@@ -111,7 +111,7 @@ func ActorNew(id ObjectID, _type ActivityVocabularyType) *Actor {_type = ActorType } o := ObjectNew(id, _type) a := Actor{Object: o} a := Actor{BaseObject: o} in := InboxNew()
-
@@ -167,8 +167,8 @@ func (a Actor) IsObject() bool {} // GetObject returns the GetObject corresponding to the Actor object func (a Actor) GetObject() Object { return a.Object func (a Actor) GetObject() BaseObject { return a.BaseObject } // GetLink returns the GetLink corresponding to the Actor object
-
@@ -187,8 +187,8 @@ func (p Person) IsObject() bool {} // GetObject returns the GetObject corresponding to the Person object func (p Person) GetObject() Object { return p.Object func (p Person) GetObject() BaseObject { return p.BaseObject } // GetLink returns the GetLink corresponding to the Person object
-
-
-
@@ -116,7 +116,7 @@ func TestActor_IsObject(t *testing.T) {func TestActor_Object(t *testing.T) { m := ActorNew("test", ActorType) if reflect.DeepEqual(Object{}, m.GetObject()) { if reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should not be an empty activity pub object", m.GetObject()) } }
-
@@ -144,7 +144,7 @@ func TestPerson_IsObject(t *testing.T) {func TestPerson_Object(t *testing.T) { m := PersonNew("test") if reflect.DeepEqual(Object{}, m.GetObject()) { if reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should not be an empty activity pub object", m.GetObject()) } }
-
-
-
@@ -11,7 +11,7 @@ type CollectionInterface interface {// Collection is a subtype of GetObject that represents ordered or unordered sets of GetObject or GetLink instances. type Collection struct { Object BaseObject // 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 +22,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 { Object BaseObject // 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"`
-
@@ -81,14 +81,14 @@ func ValidCollectionType(_type ActivityVocabularyType) bool {func CollectionNew(id ObjectID) *Collection { o := ObjectNew(id, CollectionType) return &Collection{Object: o} return &Collection{BaseObject: o} } // CollectionNew initializes a new Collection func OrderedCollectionNew(id ObjectID) *OrderedCollection { o := ObjectNew(id, OrderedCollectionType) return &OrderedCollection{Object: o} return &OrderedCollection{BaseObject: o} } // CollectionNew initializes a new Collection
-
-
-
@@ -62,7 +62,7 @@ func TestValidCollectionType(t *testing.T) {func Test_OrderedCollection_Append(t *testing.T) { id := ObjectID("test") val := Object{ID: ObjectID("grrr")} val := BaseObject{ID: ObjectID("grrr")} c := OrderedCollectionNew(id) c.Append(val)
-
@@ -78,7 +78,7 @@ func Test_OrderedCollection_Append(t *testing.T) {func Test_Collection_Append(t *testing.T) { id := ObjectID("test") val := Object{ID: ObjectID("grrr")} val := BaseObject{ID: ObjectID("grrr")} c := CollectionNew(id) c.Append(val)
-
-
-
@@ -17,7 +17,7 @@ func InboxNew() *Inbox {id := ObjectID("inbox") o := ObjectNew(id, OrderedCollectionType) i := Inbox{Object: o} i := Inbox{BaseObject: o} i.TotalItems = 0 return &i
-
-
-
@@ -77,8 +77,8 @@ func (l Link) IsObject() bool {} // GetObject returns the GetObject corresponding to the Mention object func (l Link) GetObject() Object { return Object{} func (l Link) GetObject() BaseObject { return BaseObject{} } // GetLink returns the GetLink corresponding to the Mention object
-
@@ -97,8 +97,8 @@ func (m Mention) IsObject() bool {} // GetObject returns the GetObject corresponding to the Mention object func (m Mention) GetObject() Object { return Object{} func (m Mention) GetObject() BaseObject { return BaseObject{} } // GetLink returns the GetLink corresponding to the Mention object
-
-
-
@@ -73,7 +73,7 @@ func TestMention_IsObject(t *testing.T) {func TestMention_Object(t *testing.T) { m := MentionNew("test") if !reflect.DeepEqual(Object{}, m.GetObject()) { if !reflect.DeepEqual(BaseObject{}, m.GetObject()) { t.Errorf("%#v should be an empty object", m.GetObject()) } }
-
-
-
@@ -2,6 +2,7 @@ package activitypubimport ( "encoding/json" "fmt" "sort" "time" )
-
@@ -22,8 +23,8 @@ type ObjectID stringconst ( // ActivityBaseURI the basic URI for the activity streams namespaces ActivityBaseURI URI = URI("https://www.w3.org/ns/activitystreams#") ObjectType ActivityVocabularyType = "ActivityPubObject" ActivityBaseURI = URI("https://www.w3.org/ns/activitystreams#") ObjectType ActivityVocabularyType = "Object" LinkType ActivityVocabularyType = "Link" ActivityType ActivityVocabularyType = "Activity" IntransitiveActivityType ActivityVocabularyType = "IntransitiveActivity"
-
@@ -89,7 +90,7 @@ type (ObjectOrLink interface { IsLink() bool IsObject() bool GetObject() Object GetObject() BaseObject GetLink() Link } // ObjectsArr is a named type for matching an ObjectOrLink slice type to Collection interface
-
@@ -108,12 +109,12 @@ type () // IsLink validates if current Activity Pub GetObject is a GetLink func (o Object) IsLink() bool { func (o BaseObject) IsLink() bool { return ValidLinkType(o.Type) } // IsObject validates if current Activity Pub GetObject is an GetObject func (o Object) IsObject() bool { func (o BaseObject) IsObject() bool { return ValidObjectType(o.Type) }
-
@@ -151,13 +152,32 @@ func (l *LangRef) UnmarshalJSON(data []byte) error {// UnmarshalJSON tries to load the NaturalLanguage array from the incoming json value func (n *NaturalLanguageValue) UnmarshalJSON(data []byte) error { if data[0] == '"' { // a quoted string - loading it to c.URL if data[len(data)-1] != '"' { return fmt.Errorf("invalid string value when unmarshalling %T value", n) } n.Append(LangRef("-"), string(data[1:len(data)-1])) } if data[0] == '{' { // an object - trying to load it to the struct if data[len(data)-1] != '}' { return fmt.Errorf("invalid object value when unmarshalling %T value", n) } } if data[0] == '[' { // an object - trying to load it to the struct if data[len(data)-1] != ']' { return fmt.Errorf("invalid object value when unmarshalling %T value", n) } } return nil } // 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, // including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection. type Object struct { type BaseObject struct { // Provides the globally unique identifier for an Activity Pub GetObject or GetLink. ID ObjectID `jsonld:"id,omitempty"` // Identifies the Activity Pub GetObject or GetLink type. Multiple values may be specified.
-
@@ -268,11 +288,11 @@ func ValidObjectType(_type ActivityVocabularyType) bool {} // ObjectNew initializes a new GetObject func ObjectNew(id ObjectID, _type ActivityVocabularyType) Object { func ObjectNew(id ObjectID, _type ActivityVocabularyType) BaseObject { if !(ValidObjectType(_type)) { _type = ObjectType } o := Object{ID: id, Type: _type} o := BaseObject{ID: id, Type: _type} o.Name = make(NaturalLanguageValue) o.Content = make(NaturalLanguageValue) o.Summary = make(NaturalLanguageValue)
-
@@ -280,12 +300,12 @@ func ObjectNew(id ObjectID, _type ActivityVocabularyType) Object {} // GetObject returns the GetObject corresponding to the GetObject object func (o Object) GetObject() Object { func (o BaseObject) GetObject() BaseObject { return o } // GetLink returns the GetLink corresponding to the GetObject object func (o Object) GetLink() Link { func (o BaseObject) GetLink() Link { return Link{} }
-
-
-
@@ -137,7 +137,7 @@ func TestObject_Link(t *testing.T) {func TestObjectsArr_Append(t *testing.T) { d := make(ObjectsArr, 0) val := Object{ID: ObjectID("grrr")} val := BaseObject{ID: ObjectID("grrr")} d.Append(val)
-
-
-
@@ -47,9 +47,10 @@ Server: Fetching the inboxt.Skip(desc) } // /* func Test_(t *testing.T) { desc := ` ` t.Skip(desc) } */
-