Changes
34 changed files (+490/-478)
-
-
@@ -1,85 +1,89 @@package activitypub import "time" import ( "time" as "github.com/mariusor/activitypub.go/activitystreams" ) // CreateActivity is the type for a create activity message type CreateActivity struct { Activity *Create `jsonld:"activity"` Published time.Time `jsonld:"published"` To ItemCollection `jsonld:"to,omitempty,collapsible"` CC ItemCollection `jsonld:"cc,omitempty,collapsible"` Activity *as.Create `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } func loadActorWithInboxObject(a Item, o Item) Item { func loadActorWithInboxObject(a as.Item, o as.Item) as.Item { typ := a.GetType() switch typ { case ApplicationType: var app Application app, _ = a.(Application) var inbox *Inbox case as.ApplicationType: var app as.Application app, _ = a.(as.Application) var inbox *as.OrderedCollection if app.Inbox == nil { inbox = InboxNew() } else { inbox = app.Inbox.(*Inbox) inbox = app.Inbox.(*as.OrderedCollection) } inbox.Append(o) app.Inbox = inbox return app case GroupType: var grp Group grp, _ = a.(Group) var inbox *Inbox case as.GroupType: var grp as.Group grp, _ = a.(as.Group) var inbox *as.OrderedCollection if grp.Inbox == nil { inbox = InboxNew() } else { inbox = grp.Inbox.(*Inbox) inbox = grp.Inbox.(*as.OrderedCollection) } inbox.Append(o) grp.Inbox = inbox return grp case OrganizationType: var org Organization org, _ = a.(Organization) var inbox *Inbox case as.OrganizationType: var org as.Organization org, _ = a.(as.Organization) var inbox *as.OrderedCollection if org.Inbox == nil { inbox = InboxNew() } else { inbox = org.Inbox.(*Inbox) inbox = org.Inbox.(*as.OrderedCollection) } inbox.Append(o) org.Inbox = inbox return org case PersonType: var pers Person pers, _ = a.(Person) var inbox *Inbox case as.PersonType: var pers as.Person pers, _ = a.(as.Person) var inbox *as.OrderedCollection if pers.Inbox == nil { inbox = InboxNew() } else { inbox = pers.Inbox.(*Inbox) inbox = pers.Inbox.(*as.OrderedCollection) } inbox.Append(o) pers.Inbox = inbox return pers case ServiceType: var serv Service serv, _ = a.(Service) var inbox *Inbox case as.ServiceType: var serv as.Service serv, _ = a.(as.Service) var inbox *as.OrderedCollection if serv.Inbox == nil { inbox = InboxNew() } else { inbox = serv.Inbox.(*Inbox) inbox = serv.Inbox.(*as.OrderedCollection) } inbox.Append(o) serv.Inbox = inbox return serv default: actor, _ := a.(Actor) var inbox *Inbox actor, _ := a.(as.Actor) var inbox *as.OrderedCollection if actor.Inbox == nil { inbox = InboxNew() } else { inbox = actor.Inbox.(*Inbox) inbox = actor.Inbox.(*as.OrderedCollection) } inbox.Append(o) actor.Inbox = inbox
-
@@ -88,8 +92,8 @@ func loadActorWithInboxObject(a Item, o Item) Item {} // CreateActivityNew initializes a new CreateActivity message func CreateActivityNew(id ObjectID, a Item, o Item) CreateActivity { act := CreateNew(id, o) func CreateActivityNew(id as.ObjectID, a as.Item, o as.Item) CreateActivity { act := as.CreateNew(id, o) if a != nil { if a.IsObject() {
-
@@ -109,13 +113,3 @@ func CreateActivityNew(id ObjectID, a Item, o Item) CreateActivity {return c } // UnmarshalJSON func (c *Create) UnmarshalJSON(data []byte) error { a := Activity(*c) err := a.UnmarshalJSON(data) *c = Create(a) return err }
-
-
-
@@ -1,13 +1,14 @@package activitypub import ( as "github.com/mariusor/activitypub.go/activitystreams" "reflect" "testing" "time" ) func TestCreateActivityNew(t *testing.T) { var testValue = ObjectID("test") var testValue = as.ObjectID("test") var now time.Time c := CreateActivityNew(testValue, nil, nil)
-
@@ -15,8 +16,8 @@ func TestCreateActivityNew(t *testing.T) {if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, CreateType) if c.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.CreateType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now)
-
@@ -24,17 +25,18 @@ func TestCreateActivityNew(t *testing.T) {} func TestCreateActivityNewWithApplication(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ApplicationNew("some::app::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := CreateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -46,7 +48,7 @@ func TestCreateActivityNewWithApplication(t *testing.T) {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, Actor(*a)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -57,7 +59,7 @@ func TestCreateActivityNewWithApplication(t *testing.T) {if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(Application).Inbox.(*Inbox) in := c1.Activity.Actor.(as.Application).Inbox.(*as.OrderedCollection) if in.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), in.TotalItems) }
-
@@ -73,17 +75,18 @@ func TestCreateActivityNewWithApplication(t *testing.T) {} func TestCreateActivityNewWithGroup(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) g := GroupNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := CreateActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -95,7 +98,7 @@ func TestCreateActivityNewWithGroup(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*g)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -109,17 +112,18 @@ func TestCreateActivityNewWithGroup(t *testing.T) {} func TestCreateActivityNewWithOrganization(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) o := OrganizationNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" o := as.OrganizationNew("users") c1 := CreateActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -131,7 +135,7 @@ func TestCreateActivityNewWithOrganization(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*o)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -145,17 +149,18 @@ func TestCreateActivityNewWithOrganization(t *testing.T) {} func TestCreateActivityNewWithPerson(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) b := PersonNew("bob") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := CreateActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -167,7 +172,7 @@ func TestCreateActivityNewWithPerson(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*b)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -181,17 +186,18 @@ func TestCreateActivityNewWithPerson(t *testing.T) {} func TestCreateActivityNewWithService(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) s := ServiceNew("::zz::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := CreateActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -203,7 +209,7 @@ func TestCreateActivityNewWithService(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*s)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -217,17 +223,18 @@ func TestCreateActivityNewWithService(t *testing.T) {} func TestCreateActivityNewWithActor(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ActorNew("bob", ActorType) testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := CreateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, CreateType) if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
-
-
@@ -1,23 +1,26 @@package activitypub import "fmt" import ( "fmt" as "github.com/mariusor/activitypub.go/activitystreams" ) type ( // FollowersCollection is a collection of followers FollowersCollection Followers // Followers is a Collection type Followers Collection Followers as.Collection ) // FollowersNew initializes a new Followers func FollowersNew() *Followers { id := ObjectID("followers") id := as.ObjectID("followers") i := Followers{ID: id, Type: OrderedCollectionType} i.Name = NaturalLanguageValueNew() i.Content = NaturalLanguageValueNew() i.Summary = NaturalLanguageValueNew() i := Followers{ID: id, Type: as.OrderedCollectionType} i.Name = as.NaturalLanguageValueNew() i.Content = as.NaturalLanguageValueNew() i.Summary = as.NaturalLanguageValueNew() i.TotalItems = 0
-
@@ -25,7 +28,7 @@ func FollowersNew() *Followers {} // Append adds an element to an FollowersCollection func (i *FollowersCollection) Append(o Item) error { func (i *FollowersCollection) Append(o as.Item) error { if i == nil { return fmt.Errorf("nil ") }
-
@@ -35,19 +38,19 @@ func (i *FollowersCollection) Append(o Item) error {} // Append adds an element to an Followers func (i *Followers) Append(ob Item) error { func (i *Followers) Append(ob as.Item) error { i.Items = append(i.Items, ob) i.TotalItems++ return nil } // GetID returns the ObjectID corresponding to FollowersCollection func (i FollowersCollection) GetID() *ObjectID { func (i FollowersCollection) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the FollowersCollection's type func (i FollowersCollection) GetType() ActivityVocabularyType { func (i FollowersCollection) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -62,12 +65,12 @@ func (i FollowersCollection) IsObject() bool {} // GetID returns the ObjectID corresponding to Followers func (i Followers) GetID() *ObjectID { func (i Followers) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the Followers's type func (i Followers) GetType() ActivityVocabularyType { func (i Followers) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -83,7 +86,7 @@ func (i Followers) IsObject() bool {// UnmarshalJSON func (i *FollowersCollection) UnmarshalJSON(data []byte) error { c := Collection(*i) c := as.Collection(*i) err := c.UnmarshalJSON(data) *i = FollowersCollection(c)
-
@@ -93,7 +96,7 @@ func (i *FollowersCollection) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (i *Followers) UnmarshalJSON(data []byte) error { c := Collection(*i) c := as.Collection(*i) err := c.UnmarshalJSON(data) *i = Followers(c)
-
@@ -102,13 +105,13 @@ func (i *Followers) UnmarshalJSON(data []byte) error {} // Collection returns the underlying Collection type func (i Followers) Collection() CollectionInterface { c := Collection(i) func (i Followers) Collection() as.CollectionInterface { c := as.Collection(i) return &c } // Collection returns the underlying Collection type func (i FollowersCollection) Collection() CollectionInterface { c := Collection(i) func (i FollowersCollection) Collection() as.CollectionInterface { c := as.Collection(i) return &c }
-
-
-
@@ -1,6 +1,9 @@package activitypub import "fmt" import ( "fmt" as "github.com/mariusor/activitypub.go/activitystreams" ) type ( // FollowingCollection is a list of everybody that the actor has followed, added as a side effect.
-
@@ -9,17 +12,17 @@ type (FollowingCollection Following // Following is a type alias for a simple Collection Following Collection Following as.Collection ) // FollowingNew initializes a new Following func FollowingNew() *Following { id := ObjectID("following") id := as.ObjectID("following") i := Following{ID: id, Type: OrderedCollectionType} i.Name = NaturalLanguageValueNew() i.Content = NaturalLanguageValueNew() i.Summary = NaturalLanguageValueNew() i := Following{ID: id, Type: as.OrderedCollectionType} i.Name = as.NaturalLanguageValueNew() i.Content = as.NaturalLanguageValueNew() i.Summary = as.NaturalLanguageValueNew() i.TotalItems = 0
-
@@ -27,7 +30,7 @@ func FollowingNew() *Following {} // Append adds an element to an FollowingCollection func (i *FollowingCollection) Append(o Item) error { func (i *FollowingCollection) Append(o as.Item) error { if i == nil { return fmt.Errorf("nil ") }
-
@@ -37,19 +40,19 @@ func (i *FollowingCollection) Append(o Item) error {} // Append adds an element to an Following func (i *Following) Append(ob Item) error { func (i *Following) Append(ob as.Item) error { i.Items = append(i.Items, ob) i.TotalItems++ return nil } // GetID returns the ObjectID corresponding to FollowingCollection func (i FollowingCollection) GetID() *ObjectID { func (i FollowingCollection) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the FollowingCollection's type func (i FollowingCollection) GetType() ActivityVocabularyType { func (i FollowingCollection) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -64,12 +67,12 @@ func (i FollowingCollection) IsObject() bool {} // GetID returns the ObjectID corresponding to Following func (i Following) GetID() *ObjectID { func (i Following) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the Following's type func (i Following) GetType() ActivityVocabularyType { func (i Following) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -85,7 +88,7 @@ func (i Following) IsObject() bool {// UnmarshalJSON func (i *FollowingCollection) UnmarshalJSON(data []byte) error { c := Collection(*i) c := as.Collection(*i) err := c.UnmarshalJSON(data) *i = FollowingCollection(c)
-
@@ -95,7 +98,7 @@ func (i *FollowingCollection) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (i *Following) UnmarshalJSON(data []byte) error { c := Collection(*i) c := as.Collection(*i) err := c.UnmarshalJSON(data) *i = Following(c)
-
@@ -104,13 +107,13 @@ func (i *Following) UnmarshalJSON(data []byte) error {} // Collection returns the underlying Collection type func (i Following) Collection() CollectionInterface { c := Collection(i) func (i Following) Collection() as.CollectionInterface { c := as.Collection(i) return &c } // Collection returns the underlying Collection type func (i FollowingCollection) Collection() CollectionInterface { c := Collection(i) func (i FollowingCollection) Collection() as.CollectionInterface { c := as.Collection(i) return &c }
-
-
-
@@ -1,6 +1,10 @@package activitypub import "fmt" import ( "fmt" as "github.com/mariusor/activitypub.go/activitystreams" ) type ( // InboxStream contains all activities received by the actor.
-
@@ -11,17 +15,16 @@ type (InboxStream Inbox // Inbox is a type alias for an Ordered Collection Inbox OrderedCollection Inbox as.OrderedCollection ) // InboxNew initializes a new Inbox func InboxNew() *Inbox { id := ObjectID("inbox") func InboxNew() *as.OrderedCollection { id := as.ObjectID("inbox") i := Inbox{ID: id, Type: OrderedCollectionType} i.Name = NaturalLanguageValueNew() i.Content = NaturalLanguageValueNew() i.Summary = NaturalLanguageValueNew() i := as.OrderedCollection{ID: id, Type: as.OrderedCollectionType} i.Name = as.NaturalLanguageValueNew() i.Content = as.NaturalLanguageValueNew() i.TotalItems = 0
-
@@ -29,7 +32,7 @@ func InboxNew() *Inbox {} // Append adds an element to an InboxStream func (i *InboxStream) Append(o Item) error { func (i *InboxStream) Append(o as.Item) error { if i == nil { return fmt.Errorf("nil ") }
-
@@ -39,19 +42,19 @@ func (i *InboxStream) Append(o Item) error {} // Append adds an element to an Inbox func (i *Inbox) Append(ob Item) error { func (i *Inbox) Append(ob as.Item) error { i.OrderedItems = append(i.OrderedItems, ob) i.TotalItems++ return nil } // GetID returns the ObjectID corresponding to InboxStream func (i InboxStream) GetID() *ObjectID { func (i InboxStream) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the InboxStream's type func (i InboxStream) GetType() ActivityVocabularyType { func (i InboxStream) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -66,12 +69,12 @@ func (i InboxStream) IsObject() bool {} // GetID returns the ObjectID corresponding to Inbox func (i Inbox) GetID() *ObjectID { func (i Inbox) GetID() *as.ObjectID { return i.Collection().GetID() } // GetType returns the Inbox's type func (i Inbox) GetType() ActivityVocabularyType { func (i Inbox) GetType() as.ActivityVocabularyType { return i.Type }
-
@@ -87,7 +90,7 @@ func (i Inbox) IsObject() bool {// UnmarshalJSON func (i *InboxStream) UnmarshalJSON(data []byte) error { c := OrderedCollection(*i) c := as.OrderedCollection(*i) err := c.UnmarshalJSON(data) *i = InboxStream(c)
-
@@ -97,7 +100,7 @@ func (i *InboxStream) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (i *Inbox) UnmarshalJSON(data []byte) error { c := OrderedCollection(*i) c := as.OrderedCollection(*i) err := c.UnmarshalJSON(data) *i = Inbox(c)
-
@@ -106,13 +109,13 @@ func (i *Inbox) UnmarshalJSON(data []byte) error {} // Collection returns the underlying Collection type func (i Inbox) Collection() CollectionInterface { c := OrderedCollection(i) func (i Inbox) Collection() as.CollectionInterface { c := as.OrderedCollection(i) return &c } // Collection returns the underlying Collection type func (i InboxStream) Collection() CollectionInterface { c := OrderedCollection(i) func (i InboxStream) Collection() as.CollectionInterface { c := as.OrderedCollection(i) return &c }
-
-
-
@@ -1,6 +1,7 @@package activitypub import ( as "github.com/mariusor/activitypub.go/activitystreams" "reflect" "testing" )
-
@@ -8,7 +9,7 @@ import (func TestInboxNew(t *testing.T) { i := InboxNew() id := ObjectID("inbox") id := as.ObjectID("inbox") if i.ID != id { t.Errorf("%T should be initialized with %q as %T", i, id, id) }
-
@@ -31,7 +32,7 @@ func TestInboxStream_GetID(t *testing.T) {if *o.GetID() != "" { t.Errorf("%T should be initialized with empty %T", o, o.GetID()) } id := ObjectID("test_out_stream") id := as.ObjectID("test_out_stream") o.ID = id if *o.GetID() != id { t.Errorf("%T should have %T as %q", o, id, id)
-
@@ -45,16 +46,16 @@ func TestInboxStream_GetType(t *testing.T) {t.Errorf("%T should be initialized with empty %T", o, o.GetType()) } o.Type = OrderedCollectionType if o.GetType() != OrderedCollectionType { t.Errorf("%T should have %T as %q", o, o.GetType(), OrderedCollectionType) o.Type = as.OrderedCollectionType if o.GetType() != as.OrderedCollectionType { t.Errorf("%T should have %T as %q", o, o.GetType(), as.OrderedCollectionType) } } func TestInboxStream_Append(t *testing.T) { o := InboxStream{} val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} o.Append(val) if o.TotalItems != 1 {
-
@@ -67,7 +68,7 @@ func TestInboxStream_Append(t *testing.T) {func TestInbox_Append(t *testing.T) { i := InboxNew() val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} i.Append(val) if i.TotalItems != 1 {
-
-
-
@@ -1,93 +1,96 @@package activitypub import "time" import ( as "github.com/mariusor/activitypub.go/activitystreams" "time" ) // LikeActivity is the type for a create activity message type LikeActivity struct { Activity *Like `jsonld:"activity"` Published time.Time `jsonld:"published"` To ItemCollection `jsonld:"to,omitempty,collapsible"` CC ItemCollection `jsonld:"cc,omitempty,collapsible"` Activity *as.Like `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } // DislikeActivity is the type for a create activity message type DislikeActivity struct { Activity *Dislike `jsonld:"activity"` Published time.Time `jsonld:"published"` To ItemCollection `jsonld:"to,omitempty,collapsible"` CC ItemCollection `jsonld:"cc,omitempty,collapsible"` Activity *as.Dislike `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } func loadActorWithLikedObject(a Item, o Item) Item { func loadActorWithLikedObject(a as.Item, o as.Item) as.Item { typ := a.GetType() switch typ { case ApplicationType: var app Application app, _ = a.(Application) var liked *Liked case as.ApplicationType: var app as.Application app, _ = a.(as.Application) var liked *as.OrderedCollection if app.Liked == nil { liked = LikedNew() } else { liked = app.Liked.(*Liked) liked = app.Liked.(*as.OrderedCollection) } liked.Append(o) app.Liked = liked return app case GroupType: var grp Group grp, _ = a.(Group) var liked *Liked case as.GroupType: var grp as.Group grp, _ = a.(as.Group) var liked *as.OrderedCollection if grp.Liked == nil { liked = LikedNew() } else { liked = grp.Liked.(*Liked) liked = grp.Liked.(*as.OrderedCollection) } liked.Append(o) grp.Liked = liked return grp case OrganizationType: var org Organization org, _ = a.(Organization) var liked *Liked case as.OrganizationType: var org as.Organization org, _ = a.(as.Organization) var liked *as.OrderedCollection if org.Liked == nil { liked = LikedNew() } else { liked = org.Liked.(*Liked) liked = org.Liked.(*as.OrderedCollection) } liked.Append(o) org.Liked = liked return org case PersonType: var pers Person pers, _ = a.(Person) var liked *Liked case as.PersonType: var pers as.Person pers, _ = a.(as.Person) var liked *as.OrderedCollection if pers.Liked == nil { liked = LikedNew() } else { liked = pers.Liked.(*Liked) liked = pers.Liked.(*as.OrderedCollection) } liked.Append(o) pers.Liked = liked return pers case ServiceType: var serv Service serv, _ = a.(Service) var liked *Liked case as.ServiceType: var serv as.Service serv, _ = a.(as.Service) var liked *as.OrderedCollection if serv.Liked == nil { liked = LikedNew() } else { liked = serv.Liked.(*Liked) liked = serv.Liked.(*as.OrderedCollection) } liked.Append(o) serv.Liked = liked return serv default: actor, _ := a.(Actor) var liked *Liked actor, _ := a.(as.Actor) var liked *as.OrderedCollection if actor.Liked == nil { liked = LikedNew() } else { liked = actor.Liked.(*Liked) liked = actor.Liked.(*as.OrderedCollection) } liked.Append(o) actor.Liked = liked
-
@@ -96,8 +99,8 @@ func loadActorWithLikedObject(a Item, o Item) Item {} // LikeActivityNew initializes a new LikeActivity message func LikeActivityNew(id ObjectID, a Item, o Item) LikeActivity { act := LikeNew(id, o) func LikeActivityNew(id as.ObjectID, a as.Item, o as.Item) LikeActivity { act := as.LikeNew(id, o) if a != nil { if a.IsObject() {
-
@@ -119,8 +122,8 @@ func LikeActivityNew(id ObjectID, a Item, o Item) LikeActivity {} // DislikeActivityNew initializes a new LikeActivity message func DislikeActivityNew(id ObjectID, a Item, o Item) DislikeActivity { act := DislikeNew(id, o) func DislikeActivityNew(id as.ObjectID, a as.Item, o as.Item) DislikeActivity { act := as.DislikeNew(id, o) if a != nil { if a.IsObject() {
-
@@ -140,23 +143,3 @@ func DislikeActivityNew(id ObjectID, a Item, o Item) DislikeActivity {return d } // UnmarshalJSON func (l *Like) UnmarshalJSON(data []byte) error { a := Activity(*l) err := a.UnmarshalJSON(data) *l = Like(a) return err } // UnmarshalJSON func (d *Dislike) UnmarshalJSON(data []byte) error { a := Activity(*d) err := a.UnmarshalJSON(data) *d = Dislike(a) return err }
-
-
-
@@ -1,13 +1,14 @@package activitypub import ( as "github.com/mariusor/activitypub.go/activitystreams" "reflect" "testing" "time" ) func TestLikeActivityNew(t *testing.T) { var testValue = ObjectID("test") var testValue = as.ObjectID("test") var now time.Time c := LikeActivityNew(testValue, nil, nil)
-
@@ -15,8 +16,8 @@ func TestLikeActivityNew(t *testing.T) {if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, LikeType) if c.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.LikeType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now)
-
@@ -24,17 +25,18 @@ func TestLikeActivityNew(t *testing.T) {} func TestLikeActivityNewWithApplication(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ApplicationNew("some::app::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := LikeActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -46,7 +48,7 @@ func TestLikeActivityNewWithApplication(t *testing.T) {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, Actor(*a)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -57,7 +59,7 @@ func TestLikeActivityNewWithApplication(t *testing.T) {if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(Application).Liked.(*Liked) in := c1.Activity.Actor.(as.Application).Liked.(*as.OrderedCollection) if in.TotalItems != 1 { t.Errorf("Liked collection of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), in.TotalItems) }
-
@@ -73,17 +75,18 @@ func TestLikeActivityNewWithApplication(t *testing.T) {} func TestLikeActivityNewWithGroup(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) g := GroupNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := LikeActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -95,7 +98,7 @@ func TestLikeActivityNewWithGroup(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*g)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -109,17 +112,17 @@ func TestLikeActivityNewWithGroup(t *testing.T) {} func TestLikeActivityNewWithOrganization(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) o := OrganizationNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) o := as.OrganizationNew("users") c1 := LikeActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -131,7 +134,7 @@ func TestLikeActivityNewWithOrganization(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*o)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -145,17 +148,18 @@ func TestLikeActivityNewWithOrganization(t *testing.T) {} func TestLikeActivityNewWithPerson(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) b := PersonNew("bob") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := LikeActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -167,7 +171,7 @@ func TestLikeActivityNewWithPerson(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*b)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -181,17 +185,18 @@ func TestLikeActivityNewWithPerson(t *testing.T) {} func TestLikeActivityNewWithService(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) s := ServiceNew("::zz::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := LikeActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -203,7 +208,7 @@ func TestLikeActivityNewWithService(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*s)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -217,17 +222,18 @@ func TestLikeActivityNewWithService(t *testing.T) {} func TestLikeActivityNewWithActor(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ActorNew("bob", ActorType) testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := LikeActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, LikeType) if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
-
-
@@ -1,5 +1,7 @@package activitypub import as "github.com/mariusor/activitypub.go/activitystreams" type ( // LikedCollection is a list of every object from all of the actor's Like activities, // added as a side effect. The liked collection MUST be either an OrderedCollection or
-
@@ -8,17 +10,16 @@ type (LikedCollection Liked // Liked is a type alias for an Ordered Collection Liked OrderedCollection Liked as.OrderedCollection ) // LikedCollection initializes a new Outbox func LikedNew() *Liked { id := ObjectID("liked") func LikedNew() *as.OrderedCollection { id := as.ObjectID("liked") l := Liked{ID: id, Type: OrderedCollectionType} l.Name = NaturalLanguageValueNew() l.Content = NaturalLanguageValueNew() l.Summary = NaturalLanguageValueNew() l := as.OrderedCollection{ID: id, Type: as.OrderedCollectionType} l.Name = as.NaturalLanguageValueNew() l.Content = as.NaturalLanguageValueNew() l.TotalItems = 0
-
@@ -26,26 +27,26 @@ func LikedNew() *Liked {} // Append adds an element to an LikedCollection func (l *LikedCollection) Append(o Item) error { func (l *LikedCollection) Append(o as.Item) error { l.OrderedItems = append(l.OrderedItems, o) l.TotalItems++ return nil } // Append adds an element to an Outbox func (l *Liked) Append(ob Item) error { func (l *Liked) Append(ob as.Item) error { l.OrderedItems = append(l.OrderedItems, ob) l.TotalItems++ return nil } // GetID returns the ObjectID corresponding to the LikedCollection func (l LikedCollection) GetID() *ObjectID { func (l LikedCollection) GetID() *as.ObjectID { return l.Collection().GetID() } // GetType returns the LikedCollection's type func (l LikedCollection) GetType() ActivityVocabularyType { func (l LikedCollection) GetType() as.ActivityVocabularyType { return l.Type }
-
@@ -60,12 +61,12 @@ func (l LikedCollection) IsObject() bool {} // GetID returns the ObjectID corresponding to the Liked func (l Liked) GetID() *ObjectID { func (l Liked) GetID() *as.ObjectID { return l.Collection().GetID() } // GetType returns the Liked's type func (l Liked) GetType() ActivityVocabularyType { func (l Liked) GetType() as.ActivityVocabularyType { return l.Type }
-
@@ -80,13 +81,13 @@ func (l Liked) IsObject() bool {} // Collection returns the underlying Collection type func (l Liked) Collection() CollectionInterface { c := OrderedCollection(l) func (l Liked) Collection() as.CollectionInterface { c := as.OrderedCollection(l) return &c } // Collection returns the underlying Collection type func (l LikedCollection) Collection() CollectionInterface { c := OrderedCollection(l) func (l LikedCollection) Collection() as.CollectionInterface { c := as.OrderedCollection(l) return &c }
-
-
-
@@ -1,6 +1,7 @@package activitypub import ( as "github.com/mariusor/activitypub.go/activitystreams" "reflect" "testing" )
-
@@ -8,7 +9,7 @@ import (func TestLikedNew(t *testing.T) { l := LikedNew() id := ObjectID("liked") id := as.ObjectID("liked") if l.ID != id { t.Errorf("%T should be initialized with %q as %T", l, id, id) }
-
@@ -31,7 +32,7 @@ func TestLikedCollection_GetID(t *testing.T) {if *l.GetID() != "" { t.Errorf("%T should be initialized with empty %T", l, l.GetID()) } id := ObjectID("test_out_stream") id := as.ObjectID("test_out_stream") l.ID = id if *l.GetID() != id { t.Errorf("%T should have %T as %q", l, id, id)
-
@@ -45,16 +46,16 @@ func TestLikedCollection_GetType(t *testing.T) {t.Errorf("%T should be initialized with empty %T", l, l.GetType()) } l.Type = OrderedCollectionType if l.GetType() != OrderedCollectionType { t.Errorf("%T should have %T as %q", l, l.GetType(), OrderedCollectionType) l.Type = as.OrderedCollectionType if l.GetType() != as.OrderedCollectionType { t.Errorf("%T should have %T as %q", l, l.GetType(), as.OrderedCollectionType) } } func TestLikedCollection_Append(t *testing.T) { l := LikedCollection{} val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} l.Append(val) if l.TotalItems != 1 {
-
@@ -68,7 +69,7 @@ func TestLikedCollection_Append(t *testing.T) {func TestLiked_Append(t *testing.T) { l := LikedNew() val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} l.Append(val) if l.TotalItems != 1 {
-
-
-
@@ -1,5 +1,7 @@package activitypub import as "github.com/mariusor/activitypub.go/activitystreams" type ( // LikesCollection is a list of all Like activities with this object as the object property, // added as a side effect. The likes collection MUST be either an OrderedCollection or a Collection
-
@@ -8,17 +10,16 @@ type (LikesCollection Likes // Likes is a type alias for an Ordered Collection Likes OrderedCollection Likes as.OrderedCollection ) // LikesCollection initializes a new Outbox func LikesNew() *Likes { id := ObjectID("likes") id := as.ObjectID("likes") l := Likes{ID: id, Type: OrderedCollectionType} l.Name = NaturalLanguageValueNew() l.Content = NaturalLanguageValueNew() l.Summary = NaturalLanguageValueNew() l := Likes{ID: id, Type: as.OrderedCollectionType} l.Name = as.NaturalLanguageValueNew() l.Content = as.NaturalLanguageValueNew() l.TotalItems = 0
-
@@ -26,26 +27,26 @@ func LikesNew() *Likes {} // Append adds an element to an LikesCollection func (l *LikesCollection) Append(o Item) error { func (l *LikesCollection) Append(o as.Item) error { l.OrderedItems = append(l.OrderedItems, o) l.TotalItems++ return nil } // Append adds an element to an Outbox func (l *Likes) Append(ob Item) error { func (l *Likes) Append(ob as.Item) error { l.OrderedItems = append(l.OrderedItems, ob) l.TotalItems++ return nil } // GetID returns the ObjectID corresponding to the LikesCollection func (l LikesCollection) GetID() *ObjectID { func (l LikesCollection) GetID() *as.ObjectID { return l.Collection().GetID() } // GetType returns the LikesCollection's type func (l LikesCollection) GetType() ActivityVocabularyType { func (l LikesCollection) GetType() as.ActivityVocabularyType { return l.Type }
-
@@ -60,12 +61,12 @@ func (l LikesCollection) IsObject() bool {} // GetID returns the ObjectID corresponding to the Likes func (l Likes) GetID() *ObjectID { func (l Likes) GetID() *as.ObjectID { return l.Collection().GetID() } // GetType returns the Likes's type func (l Likes) GetType() ActivityVocabularyType { func (l Likes) GetType() as.ActivityVocabularyType { return l.Type }
-
@@ -80,13 +81,13 @@ func (l Likes) IsObject() bool {} // Collection returns the underlying Collection type func (l Likes) Collection() CollectionInterface { c := OrderedCollection(l) func (l Likes) Collection() as.CollectionInterface { c := as.OrderedCollection(l) return &c } // Collection returns the underlying Collection type func (l LikesCollection) Collection() CollectionInterface { c := OrderedCollection(l) func (l LikesCollection) Collection() as.CollectionInterface { c := as.OrderedCollection(l) return &c }
-
-
-
@@ -1,5 +1,7 @@package activitypub import as "github.com/mariusor/activitypub.go/activitystreams" type ( // OutboxStream contains activities the user has published, // subject to the ability of the requestor to retrieve the activity (that is,
-
@@ -7,17 +9,16 @@ type (OutboxStream Outbox // Outbox is a type alias for an Ordered Collection Outbox OrderedCollection Outbox as.OrderedCollection ) // OutboxNew initializes a new Outbox func OutboxNew() *Outbox { id := ObjectID("outbox") id := as.ObjectID("outbox") i := Outbox{ID: id, Type: OrderedCollectionType} i.Name = NaturalLanguageValueNew() i.Content = NaturalLanguageValueNew() i.Summary = NaturalLanguageValueNew() i := Outbox{ID: id, Type: as.OrderedCollectionType} i.Name = as.NaturalLanguageValueNew() i.Content = as.NaturalLanguageValueNew() i.TotalItems = 0
-
@@ -25,26 +26,26 @@ func OutboxNew() *Outbox {} // Append adds an element to an OutboxStream func (o *OutboxStream) Append(ob Item) error { func (o *OutboxStream) Append(ob as.Item) error { o.OrderedItems = append(o.OrderedItems, ob) o.TotalItems++ return nil } // Append adds an element to an Outbox func (o *Outbox) Append(ob Item) error { func (o *Outbox) Append(ob as.Item) error { o.OrderedItems = append(o.OrderedItems, ob) o.TotalItems++ return nil } // GetID returns the ObjectID corresponding to the OutboxStream func (o OutboxStream) GetID() *ObjectID { func (o OutboxStream) GetID() *as.ObjectID { return o.Collection().GetID() } // GetType returns the OutboxStream's type func (o OutboxStream) GetType() ActivityVocabularyType { func (o OutboxStream) GetType() as.ActivityVocabularyType { return o.Type }
-
@@ -59,12 +60,12 @@ func (o OutboxStream) IsObject() bool {} // GetID returns the ObjectID corresponding to Outbox func (o Outbox) GetID() *ObjectID { func (o Outbox) GetID() *as.ObjectID { return o.Collection().GetID() } // GetType returns the Outbox's type func (o Outbox) GetType() ActivityVocabularyType { func (o Outbox) GetType() as.ActivityVocabularyType { return o.Type }
-
@@ -80,7 +81,7 @@ func (o Outbox) IsObject() bool {// UnmarshalJSON func (o *OutboxStream) UnmarshalJSON(data []byte) error { c := OrderedCollection(*o) c := as.OrderedCollection(*o) err := c.UnmarshalJSON(data) *o = OutboxStream(c)
-
@@ -90,7 +91,7 @@ func (o *OutboxStream) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (o *Outbox) UnmarshalJSON(data []byte) error { c := OrderedCollection(*o) c := as.OrderedCollection(*o) err := c.UnmarshalJSON(data) *o = Outbox(c)
-
@@ -99,13 +100,13 @@ func (o *Outbox) UnmarshalJSON(data []byte) error {} // Collection returns the underlying Collection type func (o Outbox) Collection() CollectionInterface { c := OrderedCollection(o) func (o Outbox) Collection() as.CollectionInterface { c := as.OrderedCollection(o) return &c } // Collection returns the underlying Collection type func (o OutboxStream) Collection() CollectionInterface { c := OrderedCollection(o) func (o OutboxStream) Collection() as.CollectionInterface { c := as.OrderedCollection(o) return &c }
-
-
-
@@ -3,12 +3,14 @@ package activitypubimport ( "reflect" "testing" as "github.com/mariusor/activitypub.go/activitystreams" ) func TestOutboxNew(t *testing.T) { o := OutboxNew() id := ObjectID("outbox") id := as.ObjectID("outbox") if o.ID != id { t.Errorf("%T should be initialized with %q as %T", o, id, id) }
-
@@ -31,7 +33,7 @@ func TestOutboxStream_GetID(t *testing.T) {if *o.GetID() != "" { t.Errorf("%T should be initialized with empty %T", o, o.GetID()) } id := ObjectID("test_out_stream") id := as.ObjectID("test_out_stream") o.ID = id if *o.GetID() != id { t.Errorf("%T should have %T as %q", o, id, id)
-
@@ -45,16 +47,16 @@ func TestOutboxStream_GetType(t *testing.T) {t.Errorf("%T should be initialized with empty %T", o, o.GetType()) } o.Type = OrderedCollectionType if o.GetType() != OrderedCollectionType { t.Errorf("%T should have %T as %q", o, o.GetType(), OrderedCollectionType) o.Type = as.OrderedCollectionType if o.GetType() != as.OrderedCollectionType { t.Errorf("%T should have %T as %q", o, o.GetType(), as.OrderedCollectionType) } } func TestOutboxStream_Append(t *testing.T) { o := OutboxStream{} val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} o.Append(val) if o.TotalItems != 1 {
-
@@ -68,7 +70,7 @@ func TestOutboxStream_Append(t *testing.T) {func TestOutbox_Append(t *testing.T) { o := OutboxNew() val := Object{ID: ObjectID("grrr")} val := as.Object{ID: as.ObjectID("grrr")} o.Append(val) if o.TotalItems != 1 {
-
-
-
@@ -1,5 +1,7 @@package activitypub import as "github.com/mariusor/activitypub.go/activitystreams" type ( // SharesCollection is a list of all Announce activities with this object as the object property, // added as a side effect. The shares collection MUST be either an OrderedCollection or a Collection
-
@@ -8,5 +10,5 @@ type (SharesCollection Shares // Shares is a type alias for an Ordered Collection Shares OrderedCollection Shares as.OrderedCollection )
-
-
-
@@ -1,18 +1,21 @@package activitypub import "time" import ( as "github.com/mariusor/activitypub.go/activitystreams" "time" ) // UpdateActivity is the type for a Update activity message type UpdateActivity struct { Activity *Update `jsonld:"activity"` Published time.Time `jsonld:"published"` To ItemCollection `jsonld:"to,omitempty,collapsible"` CC ItemCollection `jsonld:"cc,omitempty,collapsible"` Activity *as.Update `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } // UpdateActivityNew initializes a new UpdateActivity message func UpdateActivityNew(id ObjectID, a Item, o Item) UpdateActivity { act := UpdateNew(id, o) func UpdateActivityNew(id as.ObjectID, a as.Item, o as.Item) UpdateActivity { act := as.UpdateNew(id, o) if a != nil { if a.IsObject() {
-
@@ -32,13 +35,3 @@ func UpdateActivityNew(id ObjectID, a Item, o Item) UpdateActivity {return c } // UnmarshalJSON func (u *Update) UnmarshalJSON(data []byte) error { a := Activity(*u) err := a.UnmarshalJSON(data) *u = Update(a) return err }
-
-
-
@@ -1,13 +1,14 @@package activitypub import ( as "github.com/mariusor/activitypub.go/activitystreams" "reflect" "testing" "time" ) func TestUpdateActivityNew(t *testing.T) { var testValue = ObjectID("test") var testValue = as.ObjectID("test") var now time.Time c := UpdateActivityNew(testValue, nil, nil)
-
@@ -15,8 +16,8 @@ func TestUpdateActivityNew(t *testing.T) {if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, UpdateType) if c.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.UpdateType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now)
-
@@ -24,17 +25,18 @@ func TestUpdateActivityNew(t *testing.T) {} func TestUpdateActivityNewWithApplication(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ApplicationNew("some::app::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := UpdateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -46,7 +48,7 @@ func TestUpdateActivityNewWithApplication(t *testing.T) {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, Actor(*a)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -57,7 +59,7 @@ func TestUpdateActivityNewWithApplication(t *testing.T) {if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(Application).Inbox.(*Inbox) in := c1.Activity.Actor.(as.Application).Inbox.(*as.OrderedCollection) if in.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), in.TotalItems) }
-
@@ -73,17 +75,18 @@ func TestUpdateActivityNewWithApplication(t *testing.T) {} func TestUpdateActivityNewWithGroup(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) g := GroupNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := UpdateActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -95,7 +98,7 @@ func TestUpdateActivityNewWithGroup(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*g)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -109,17 +112,18 @@ func TestUpdateActivityNewWithGroup(t *testing.T) {} func TestUpdateActivityNewWithOrganization(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) o := OrganizationNew("users") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" o := as.OrganizationNew("users") c1 := UpdateActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -131,7 +135,7 @@ func TestUpdateActivityNewWithOrganization(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*o)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -145,17 +149,18 @@ func TestUpdateActivityNewWithOrganization(t *testing.T) {} func TestUpdateActivityNewWithPerson(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) b := PersonNew("bob") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := UpdateActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -167,7 +172,7 @@ func TestUpdateActivityNewWithPerson(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*b)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -181,17 +186,18 @@ func TestUpdateActivityNewWithPerson(t *testing.T) {} func TestUpdateActivityNewWithService(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) s := ServiceNew("::zz::") testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := UpdateActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
@@ -203,7 +209,7 @@ func TestUpdateActivityNewWithService(t *testing.T) {t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*s)) t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID)
-
@@ -217,17 +223,18 @@ func TestUpdateActivityNewWithService(t *testing.T) {} func TestUpdateActivityNewWithActor(t *testing.T) { testValue := ObjectID("my:note") n := ObjectNew("my:note", NoteType) a := ActorNew("bob", ActorType) testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := UpdateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, UpdateType) if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now)
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "time"
-
@@ -695,7 +695,6 @@ func QuestionNew(id ObjectID) *Question {q := Question{ID: id, Type: QuestionType} q.Name = NaturalLanguageValueNew() q.Content = NaturalLanguageValueNew() q.Summary = NaturalLanguageValueNew() return &q }
-
@@ -717,7 +716,6 @@ func ActivityNew(id ObjectID, typ ActivityVocabularyType, ob Item) *Activity {a := Activity{ID: id, Type: typ} a.Name = NaturalLanguageValueNew() a.Content = NaturalLanguageValueNew() a.Summary = NaturalLanguageValueNew() a.Object = ob
-
@@ -732,7 +730,6 @@ func IntransitiveActivityNew(id ObjectID, typ ActivityVocabularyType) *Intransiti := IntransitiveActivity{ID: id, Type: typ} i.Name = NaturalLanguageValueNew() i.Content = NaturalLanguageValueNew() i.Summary = NaturalLanguageValueNew() return &i }
-
@@ -1422,3 +1419,43 @@ func (a *Activity) UnmarshalJSON(data []byte) error {} return nil } // UnmarshalJSON func (l *Like) UnmarshalJSON(data []byte) error { a := Activity(*l) err := a.UnmarshalJSON(data) *l = Like(a) return err } // UnmarshalJSON func (d *Dislike) UnmarshalJSON(data []byte) error { a := Activity(*d) err := a.UnmarshalJSON(data) *d = Dislike(a) return err } // UnmarshalJSON func (u *Update) UnmarshalJSON(data []byte) error { a := Activity(*u) err := a.UnmarshalJSON(data) *u = Update(a) return err } // UnmarshalJSON func (c *Create) UnmarshalJSON(data []byte) error { a := Activity(*c) err := a.UnmarshalJSON(data) *c = Create(a) return err }
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import "testing"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "time"
-
@@ -203,9 +203,9 @@ func ActorNew(id ObjectID, typ ActivityVocabularyType) *Actor {a.Name = NaturalLanguageValueNew() a.Content = NaturalLanguageValueNew() a.Summary = NaturalLanguageValueNew() in := InboxNew() out := OutboxNew() liked := LikedNew() in := OrderedCollectionNew(ObjectID("test-inbox")) out := OrderedCollectionNew(ObjectID("test-outbox")) liked := OrderedCollectionNew(ObjectID("test-liked")) a.Inbox = in a.Outbox = out
-
@@ -387,10 +387,10 @@ func (a *Actor) UnmarshalJSON(data []byte) error {a.URL = u } o := OutboxStream{} o := OrderedCollectionNew(ObjectID("test-outbox")) if v, _, _, err := jsonparser.Get(data, "outbox"); err == nil { if o.UnmarshalJSON(v) == nil { a.Outbox = &o a.Outbox = o } }
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "reflect"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "time"
-
@@ -261,7 +261,6 @@ func OrderedCollectionNew(id ObjectID) *OrderedCollection {o := OrderedCollection{ID: id, Type: OrderedCollectionType} o.Name = NaturalLanguageValueNew() o.Content = NaturalLanguageValueNew() o.Summary = NaturalLanguageValueNew() return &o }
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "reflect"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams // ItemCollection is an array of items type ItemCollection []Item
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams var validLinkTypes = [...]ActivityVocabularyType{ MentionType,
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "reflect"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "fmt"
-
@@ -10,9 +10,7 @@ func getAPObjectByType(typ ActivityVocabularyType) (Item, error) {switch typ { case ObjectType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case LinkType: ret = &Link{} o := ret.(*Link)
-
@@ -38,52 +36,32 @@ func getAPObjectByType(typ ActivityVocabularyType) (Item, error) {o := ret.(*Link) o.Type = typ case ArticleType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case AudioType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case DocumentType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case EventType: o := Object{} o.Type = typ case ImageType: ret = &Object{} ret = ObjectNew(typ) o := ret.(*Object) o.Type = typ case NoteType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case PageType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case PlaceType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case ProfileType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case RelationshipType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case TombstoneType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case VideoType: ret = &Object{} o := ret.(*Object) o.Type = typ ret = ObjectNew(typ) case MentionType: ret = &Mention{} o := ret.(*Mention)
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "encoding/json"
-
@@ -364,14 +364,13 @@ func ValidObjectType(typ ActivityVocabularyType) bool {} // ObjectNew initializes a new Object func ObjectNew(id ObjectID, typ ActivityVocabularyType) *Object { func ObjectNew(typ ActivityVocabularyType) *Object { if !(ValidObjectType(typ)) { typ = ObjectType } o := Object{ID: id, Type: typ} o := Object{Type: typ} o.Name = NaturalLanguageValueNew() o.Content = NaturalLanguageValueNew() o.Summary = NaturalLanguageValueNew() return &o }
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "reflect"
-
@@ -9,7 +9,8 @@ func TestObjectNew(t *testing.T) {var testValue = ObjectID("test") var testType = ArticleType o := ObjectNew(testValue, testType) o := ObjectNew(testType) o.ID = testValue if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue)
-
@@ -18,7 +19,8 @@ func TestObjectNew(t *testing.T) {t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, testType) } n := ObjectNew(testValue, "") n := ObjectNew("") n.ID = testValue if n.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", n.ID, testValue) }
-
@@ -120,22 +122,26 @@ func TestNaturalLanguageValue_MarshalJSON(t *testing.T) {} func TestObject_IsLink(t *testing.T) { o := ObjectNew("test", ObjectType) o := ObjectNew(ObjectType) o.ID = "test" if o.IsLink() { t.Errorf("%#v should not be a valid link", o.Type) } m := ObjectNew("test", AcceptType) m := ObjectNew(AcceptType) m.ID = "test" if m.IsLink() { t.Errorf("%#v should not be a valid link", m.Type) } } func TestObject_IsObject(t *testing.T) { o := ObjectNew("test", ObjectType) o := ObjectNew(ObjectType) o.ID = "test" if !o.IsObject() { t.Errorf("%#v should be a valid object", o.Type) } m := ObjectNew("test", AcceptType) m := ObjectNew(AcceptType) m.ID = "test" if !m.IsObject() { t.Errorf("%#v should be a valid object", m.Type) }
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "encoding"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import ( "strings"
-
-
-
@@ -1,4 +1,4 @@package activitypub package activitystreams import "testing"
-
-
-
@@ -3,7 +3,7 @@ package testsimport ( "testing" a "github.com/mariusor/activitypub.go/activitypub" a "github.com/mariusor/activitypub.go/activitystreams" j "github.com/mariusor/activitypub.go/jsonld" "strings"
-
-
-
@@ -4,7 +4,7 @@ package testsimport ( "fmt" a "github.com/mariusor/activitypub.go/activitypub" a "github.com/mariusor/activitypub.go/activitystreams" "testing" )
-
@@ -142,9 +142,10 @@ S2S Server: Deduplication of recipient listt.Log(desc) to := a.PersonNew("bob") o := a.ObjectNew("something", a.ArticleType) o := a.ObjectNew(a.ArticleType) cc := a.PersonNew("alice") o.ID = "something" c := a.CreateNew("create", o) c.To.Append(to) c.CC.Append(cc)
-
@@ -199,9 +200,10 @@ Activity being notified aboutp := a.PersonNew("main actor") to := a.PersonNew("bob") o := a.ObjectNew("something", a.ArticleType) o := a.ObjectNew(a.ArticleType) cc := a.PersonNew("alice") o.ID = "something" c := a.CreateNew("create", o) c.Actor = a.Actor(*p)
-
-
-
@@ -5,12 +5,14 @@ import ("fmt" "io" "os" "path/filepath" "reflect" "testing" "time" "unsafe" a "github.com/mariusor/activitypub.go/activitypub" ap "github.com/mariusor/activitypub.go/activitypub" a "github.com/mariusor/activitypub.go/activitystreams" j "github.com/mariusor/activitypub.go/jsonld" )
-
@@ -19,7 +21,6 @@ const dir = "./mocks"var stopOnFailure = false type testPair struct { path string expected bool blank interface{} result interface{}
-
@@ -188,13 +189,11 @@ var zLoc, _ = time.LoadLocation("UTC")var allTests = tests{ "empty": testPair{ path: "./mocks/empty.json", expected: true, blank: &a.Object{}, result: &a.Object{}, }, "link_simple": testPair{ path: "./mocks/link_simple.json", expected: true, blank: &a.Link{}, result: &a.Link{
-
@@ -208,7 +207,6 @@ var allTests = tests{}, }, "object_with_url": testPair{ path: "./mocks/object_with_url.json", expected: true, blank: &a.Object{}, result: &a.Object{
-
@@ -216,7 +214,6 @@ var allTests = tests{}, }, "object_simple": testPair{ path: "./mocks/object_simple.json", expected: true, blank: &a.Object{}, result: &a.Object{
-
@@ -228,7 +225,6 @@ var allTests = tests{}, }, "object_with_replies": testPair{ path: "./mocks/object_with_replies.json", expected: true, blank: &a.Object{}, result: &a.Object{
-
@@ -249,7 +245,6 @@ var allTests = tests{}, }, "activity_simple": testPair{ path: "./mocks/activity_simple.json", expected: true, blank: &a.Activity{}, result: &a.Activity{
-
@@ -257,33 +252,24 @@ var allTests = tests{Summary: a.NaturalLanguageValue{{a.NilLangRef, "Sally did something to a note"}}, Actor: &a.Person{ Type: a.PersonType, Name: a.NaturalLanguageValue{{ a.NilLangRef, "Sally", }}, Name: a.NaturalLanguageValue{{a.NilLangRef, "Sally"}}, }, Object: &a.Object{ Type: a.NoteType, Name: a.NaturalLanguageValue{{ a.NilLangRef, "A Note", }}, Name: a.NaturalLanguageValue{{a.NilLangRef, "A Note"}}, }, }, }, "person_with_outbox": testPair{ path: "./mocks/person_with_outbox.json", expected: true, blank: &a.Person{}, result: &a.Person{ ID: a.ObjectID("http://example.com/accounts/ana"), Type: a.PersonType, Name: a.NaturalLanguageValue{{ a.NilLangRef, "ana", }}, PreferredUsername: a.NaturalLanguageValue{{ a.NilLangRef, "Ana", }}, URL: a.URI("http://example.com/accounts/ana"), Outbox: &a.OutboxStream{ ID: a.ObjectID("http://example.com/accounts/ana"), Type: a.PersonType, Name: a.NaturalLanguageValue{{a.NilLangRef, "ana"}}, PreferredUsername: a.NaturalLanguageValue{{a.NilLangRef, "Ana"}}, URL: a.URI("http://example.com/accounts/ana"), Outbox: &a.OrderedCollection{ ID: a.ObjectID("http://example.com/accounts/ana/outbox"), Type: a.OrderedCollectionType, URL: a.URI("http://example.com/outbox"),
-
@@ -291,7 +277,6 @@ var allTests = tests{}, }, "ordered_collection": testPair{ path: "./mocks/ordered_collection.json", expected: true, blank: &a.OrderedCollection{}, result: &a.OrderedCollection{
-
@@ -315,7 +300,6 @@ var allTests = tests{}, }, "natural_language_values": { path: "./mocks/natural_language_values.json", expected: true, blank: &a.NaturalLanguageValue{}, result: &a.NaturalLanguageValue{
-
@@ -329,7 +313,6 @@ var allTests = tests{}, }, "activity_create_simple": { path: "./mocks/activity_create_simple.json", expected: true, blank: &a.Create{}, result: &a.Create{
-
@@ -345,10 +328,9 @@ var allTests = tests{}, }, "like_activity_with_iri_actor": { path: "./mocks/like_activity_with_iri_actor.json", expected: true, blank: &a.LikeActivity{}, result: &a.LikeActivity{ blank: &ap.LikeActivity{}, result: &ap.LikeActivity{ Activity: &a.Like{ Type: a.LikeType, Actor: a.IRI("https://littr.git/api/accounts/24d4b96f"),
-
@@ -390,9 +372,10 @@ func Test_ActivityPubUnmarshall(t *testing.T) {for k, pair := range allTests { var data []byte data, err = getFileContents(pair.path) path := filepath.Join(dir, fmt.Sprintf("%s.json", k)) data, err = getFileContents(path) if err != nil { f("Error: %s for %s", err, pair.path) f("Error: %s for %s", err, path) continue } object := pair.blank
-
@@ -427,7 +410,7 @@ func Test_ActivityPubUnmarshall(t *testing.T) {f("\n%s\n should %sequal to expected\n%s", oj, expLbl, tj) } if err == nil { fmt.Printf(" --- %s: %s\n %s\n", "PASS", k, pair.path) fmt.Printf(" --- %s: %s\n %s\n", "PASS", k, path) } } }
-