Made the ActivityPub named collections be aliases for OrderedCollection

This commit is contained in:
Marius Orcsik 2019-12-03 20:22:47 +01:00
parent b3a4fef49a
commit 882dcd90be
No known key found for this signature in database
GPG key ID: 77618B618F79EB72
14 changed files with 11 additions and 762 deletions

View file

@ -5,70 +5,5 @@ type (
FollowersCollection = Followers FollowersCollection = Followers
// Followers is a Collection type // Followers is a Collection type
Followers Collection Followers = Collection
) )
// FollowersNew initializes a new Followers
func FollowersNew() *Followers {
id := ObjectID("followers")
i := Followers{ID: id, Type: CollectionType}
i.Name = NaturalLanguageValuesNew()
i.Content = NaturalLanguageValuesNew()
i.Summary = NaturalLanguageValuesNew()
i.TotalItems = 0
return &i
}
// Append adds an element to an Followers
func (f *Followers) Append(ob Item) error {
f.Items = append(f.Items, ob)
f.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to Followers
func (f Followers) GetID() ObjectID {
return f.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Followers object
func (f Followers) GetLink() IRI {
return IRI(f.ID)
}
// GetType returns the Followers's type
func (f Followers) GetType() ActivityVocabularyType {
return f.Type
}
// IsLink returns false for an Followers object
func (f Followers) IsLink() bool {
return false
}
// IsObject returns true for a Followers object
func (f Followers) IsObject() bool {
return true
}
// UnmarshalJSON
func (f *Followers) UnmarshalJSON(data []byte) error {
if ItemTyperFunc == nil {
ItemTyperFunc = JSONGetItemByType
}
c := Collection(*f)
err := c.UnmarshalJSON(data)
*f = Followers(c)
return err
}
// Collection returns the underlying Collection type
func (f Followers) Collection() CollectionInterface {
c := Collection(f)
return &c
}

View file

@ -2,38 +2,6 @@ package activitypub
import "testing" import "testing"
func TestFollowers_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowers_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowersNew(t *testing.T) { func TestFollowersNew(t *testing.T) {
t.Skipf("TODO") t.Skipf("TODO")
} }

View file

@ -7,7 +7,7 @@ type (
FollowingCollection = Following FollowingCollection = Following
// Following is a type alias for a simple Collection // Following is a type alias for a simple Collection
Following Collection Following = Collection
) )
// FollowingNew initializes a new Following // FollowingNew initializes a new Following
@ -23,54 +23,3 @@ func FollowingNew() *Following {
return &i return &i
} }
// Append adds an element to an Following
func (f *Following) Append(ob Item) error {
f.Items = append(f.Items, ob)
f.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to Following
func (f Following) GetID() ObjectID {
return f.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Following object
func (f Following) GetLink() IRI {
return IRI(f.ID)
}
// GetType returns the Following's type
func (f Following) GetType() ActivityVocabularyType {
return f.Type
}
// IsLink returns false for an Following object
func (f Following) IsLink() bool {
return false
}
// IsObject returns true for a Following object
func (f Following) IsObject() bool {
return true
}
// UnmarshalJSON
func (f *Following) UnmarshalJSON(data []byte) error {
if ItemTyperFunc == nil {
ItemTyperFunc = JSONGetItemByType
}
c := Collection(*f)
err := c.UnmarshalJSON(data)
*f = Following(c)
return err
}
// Collection returns the underlying Collection type
func (f Following) Collection() CollectionInterface {
c := Collection(f)
return &c
}

View file

@ -2,38 +2,6 @@ package activitypub
import "testing" import "testing"
func TestFollowing_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowing_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}
func TestFollowingNew(t *testing.T) { func TestFollowingNew(t *testing.T) {
t.Skipf("TODO") t.Skipf("TODO")
} }

View file

@ -9,7 +9,7 @@ type (
InboxStream = Inbox InboxStream = Inbox
// Inbox is a type alias for an Ordered Collection // Inbox is a type alias for an Ordered Collection
Inbox OrderedCollection Inbox = OrderedCollection
) )
// InboxNew initializes a new Inbox // InboxNew initializes a new Inbox
@ -24,54 +24,3 @@ func InboxNew() *OrderedCollection {
return &i return &i
} }
// Append adds an element to an Inbox
func (i *Inbox) Append(ob Item) error {
i.OrderedItems = append(i.OrderedItems, ob)
i.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to Inbox
func (i Inbox) GetID() ObjectID {
return i.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Inbox object
func (i Inbox) GetLink() IRI {
return IRI(i.ID)
}
// GetType returns the Inbox's type
func (i Inbox) GetType() ActivityVocabularyType {
return i.Type
}
// IsLink returns false for an Inbox object
func (i Inbox) IsLink() bool {
return false
}
// IsObject returns true for a Inbox object
func (i Inbox) IsObject() bool {
return true
}
// UnmarshalJSON
func (i *Inbox) UnmarshalJSON(data []byte) error {
if ItemTyperFunc == nil {
ItemTyperFunc = JSONGetItemByType
}
c := OrderedCollection(*i)
err := c.UnmarshalJSON(data)
*i = Inbox(c)
return err
}
// Collection returns the underlying Collection type
func (i Inbox) Collection() CollectionInterface {
c := OrderedCollection(i)
return &c
}

View file

@ -1,7 +1,6 @@
package activitypub package activitypub
import ( import (
"reflect"
"testing" "testing"
) )
@ -25,83 +24,3 @@ func TestInboxNew(t *testing.T) {
t.Errorf("%T should be initialized with 0 TotalItems", i) t.Errorf("%T should be initialized with 0 TotalItems", i)
} }
} }
func TestInboxStream_GetID(t *testing.T) {
o := InboxStream{}
if o.GetID() != "" {
t.Errorf("%T should be initialized with empty %T", o, o.GetID())
}
id := ObjectID("test_out_stream")
o.ID = id
if o.GetID() != id {
t.Errorf("%T should have %T as %q", o, id, id)
}
}
func TestInboxStream_GetType(t *testing.T) {
o := InboxStream{}
if o.GetType() != "" {
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)
}
}
func TestInboxStream_Append(t *testing.T) {
o := InboxStream{}
val := Object{ID: ObjectID("grrr")}
o.Append(val)
if o.TotalItems != 1 {
t.Errorf("%T should have exactly an element, found %d", o, o.TotalItems)
}
if !reflect.DeepEqual(o.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID)
}
}
func TestInbox_Append(t *testing.T) {
i := InboxNew()
val := Object{ID: ObjectID("grrr")}
i.Append(val)
if i.TotalItems != 0 {
t.Errorf("%T should have exactly an element, found %d", i, i.TotalItems)
}
if !reflect.DeepEqual(i.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", i, i.OrderedItems, val.ID)
}
}
func TestInbox_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestInbox_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}

View file

@ -5,10 +5,10 @@ type (
// added as a side effect. The liked collection MUST be either an OrderedCollection or // added as a side effect. The liked collection MUST be either an OrderedCollection or
// a Collection and MAY be filtered on privileges of an authenticated user or as // a Collection and MAY be filtered on privileges of an authenticated user or as
// appropriate when no authentication is given. // appropriate when no authentication is given.
LikedCollection Liked LikedCollection = Liked
// Liked is a type alias for an Ordered Collection // Liked is a type alias for an Ordered Collection
Liked OrderedCollection Liked = OrderedCollection
) )
// LikedCollection initializes a new Outbox // LikedCollection initializes a new Outbox
@ -23,79 +23,3 @@ func LikedNew() *OrderedCollection {
return &l return &l
} }
// Append adds an element to an LikedCollection
func (l *LikedCollection) Append(o 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 {
l.OrderedItems = append(l.OrderedItems, ob)
l.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to the LikedCollection
func (l LikedCollection) GetID() ObjectID {
return l.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current LikedCollection object
func (l LikedCollection) GetLink() IRI {
return IRI(l.ID)
}
// GetType returns the LikedCollection's type
func (l LikedCollection) GetType() ActivityVocabularyType {
return l.Type
}
// IsLink returns false for an LikedCollection object
func (l LikedCollection) IsLink() bool {
return false
}
// IsObject returns true for a LikedCollection object
func (l LikedCollection) IsObject() bool {
return true
}
// GetID returns the ObjectID corresponding to the Liked
func (l Liked) GetID() ObjectID {
return l.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Liked object
func (l Liked) GetLink() IRI {
return IRI(l.ID)
}
// GetType returns the Liked's type
func (l Liked) GetType() ActivityVocabularyType {
return l.Type
}
// IsLink returns false for an Liked object
func (l Liked) IsLink() bool {
return false
}
// IsObject returns true for a Liked object
func (l Liked) IsObject() bool {
return true
}
// Collection returns the underlying Collection type
func (l Liked) Collection() CollectionInterface {
c := OrderedCollection(l)
return &c
}
// Collection returns the underlying Collection type
func (l LikedCollection) Collection() CollectionInterface {
c := OrderedCollection(l)
return &c
}

View file

@ -1,7 +1,6 @@
package activitypub package activitypub
import ( import (
"reflect"
"testing" "testing"
) )
@ -25,96 +24,3 @@ func TestLikedNew(t *testing.T) {
t.Errorf("%T should be initialized with 0 TotalItems", l) t.Errorf("%T should be initialized with 0 TotalItems", l)
} }
} }
func TestLikedCollection_GetID(t *testing.T) {
l := LikedCollection{}
if l.GetID() != "" {
t.Errorf("%T should be initialized with empty %T", l, l.GetID())
}
id := ObjectID("test_out_stream")
l.ID = id
if l.GetID() != id {
t.Errorf("%T should have %T as %q", l, id, id)
}
}
func TestLikedCollection_GetType(t *testing.T) {
l := LikedCollection{}
if l.GetType() != "" {
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)
}
}
func TestLikedCollection_Append(t *testing.T) {
l := LikedCollection{}
val := Object{ID: ObjectID("grrr")}
l.Append(val)
if l.TotalItems != 1 {
t.Errorf("%T should have exactly an element, found %d", l, l.TotalItems)
}
if !reflect.DeepEqual(l.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", l, l.OrderedItems, val.ID)
}
}
func TestLiked_Append(t *testing.T) {
l := LikedNew()
val := Object{ID: ObjectID("grrr")}
l.Append(val)
if l.TotalItems != 0 {
t.Errorf("%T should have exactly an element, found %d", l, l.TotalItems)
}
if !reflect.DeepEqual(l.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", l, l.OrderedItems, val.ID)
}
}
func TestLiked_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestLiked_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestLiked_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLiked_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestLiked_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLiked_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestLikedCollection_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestLikedCollection_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikedCollection_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikedCollection_IsObject(t *testing.T) {
t.Skipf("TODO")
}

View file

@ -5,10 +5,10 @@ type (
// added as a side effect. The likes collection MUST be either an OrderedCollection or a Collection // added as a side effect. The likes collection MUST be either an OrderedCollection or a Collection
// and MAY be filtered on privileges of an authenticated user or as appropriate when // and MAY be filtered on privileges of an authenticated user or as appropriate when
// no authentication is given. // no authentication is given.
LikesCollection Likes LikesCollection = Likes
// Likes is a type alias for an Ordered Collection // Likes is a type alias for an Ordered Collection
Likes OrderedCollection Likes = OrderedCollection
) )
// LikesCollection initializes a new Outbox // LikesCollection initializes a new Outbox
@ -23,79 +23,3 @@ func LikesNew() *Likes {
return &l return &l
} }
// Append adds an element to an LikesCollection
func (l *LikesCollection) Append(o 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 {
l.OrderedItems = append(l.OrderedItems, ob)
l.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to the LikesCollection
func (l LikesCollection) GetID() ObjectID {
return l.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current LikesCollection object
func (l LikesCollection) GetLink() IRI {
return IRI(l.ID)
}
// GetType returns the LikesCollection's type
func (l LikesCollection) GetType() ActivityVocabularyType {
return l.Type
}
// IsLink returns false for an LikesCollection object
func (l LikesCollection) IsLink() bool {
return false
}
// IsObject returns true for a LikesCollection object
func (l LikesCollection) IsObject() bool {
return true
}
// GetID returns the ObjectID corresponding to the Likes
func (l Likes) GetID() ObjectID {
return l.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Likes object
func (l Likes) GetLink() IRI {
return IRI(l.ID)
}
// GetType returns the Likes's type
func (l Likes) GetType() ActivityVocabularyType {
return l.Type
}
// IsLink returns false for an Likes object
func (l Likes) IsLink() bool {
return false
}
// IsObject returns true for a Likes object
func (l Likes) IsObject() bool {
return true
}
// Collection returns the underlying Collection type
func (l Likes) Collection() CollectionInterface {
c := OrderedCollection(l)
return &c
}
// Collection returns the underlying Collection type
func (l LikesCollection) Collection() CollectionInterface {
c := OrderedCollection(l)
return &c
}

View file

@ -2,62 +2,6 @@ package activitypub
import "testing" import "testing"
func TestLikes_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikes_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesCollection_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestLikesNew(t *testing.T) { func TestLikesNew(t *testing.T) {
t.Skipf("TODO") t.Skipf("TODO")
} }

View file

@ -7,66 +7,18 @@ type (
OutboxStream = Outbox OutboxStream = Outbox
// Outbox is a type alias for an Ordered Collection // Outbox is a type alias for an Ordered Collection
Outbox OrderedCollection Outbox = OrderedCollection
) )
// OutboxNew initializes a new Outbox // OutboxNew initializes a new Outbox
func OutboxNew() *Outbox { func OutboxNew() *Outbox {
id := ObjectID("outbox") id := ObjectID("outbox")
i := Outbox{ID: id, Type: CollectionType} i := Outbox{ID: id, Type: OrderedCollectionType}
i.Name = NaturalLanguageValuesNew() i.Name = NaturalLanguageValuesNew()
i.Content = NaturalLanguageValuesNew() i.Content = NaturalLanguageValuesNew()
i.TotalItems = 0 i.TotalItems = 0
i.OrderedItems = make(ItemCollection, 0)
return &i return &i
} }
// Append adds an element to an Outbox
func (o *Outbox) Append(ob Item) error {
o.OrderedItems = append(o.OrderedItems, ob)
o.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to Outbox
func (o Outbox) GetID() ObjectID {
return o.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Outbox object
func (o Outbox) GetLink() IRI {
return IRI(o.ID)
}
// GetType returns the Outbox's type
func (o Outbox) GetType() ActivityVocabularyType {
return o.Type
}
// IsLink returns false for an Outbox object
func (o Outbox) IsLink() bool {
return false
}
// IsObject returns true for a Outbox object
func (o Outbox) IsObject() bool {
return true
}
// UnmarshalJSON
func (o *Outbox) UnmarshalJSON(data []byte) error {
c := OrderedCollection(*o)
err := c.UnmarshalJSON(data)
*o = Outbox(c)
return err
}
// Collection returns the underlying Collection type
func (o Outbox) Collection() CollectionInterface {
c := OrderedCollection(o)
return &c
}

View file

@ -57,9 +57,6 @@ func TestOutboxStream_Append(t *testing.T) {
val := Object{ID: ObjectID("grrr")} val := Object{ID: ObjectID("grrr")}
o.Append(val) o.Append(val)
if o.TotalItems != 1 {
t.Errorf("%T should have exactly an element, found %d", o, o.TotalItems)
}
if !reflect.DeepEqual(o.OrderedItems[0], val) { if !reflect.DeepEqual(o.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID) t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID)
} }
@ -71,9 +68,6 @@ func TestOutbox_Append(t *testing.T) {
val := Object{ID: ObjectID("grrr")} val := Object{ID: ObjectID("grrr")}
o.Append(val) o.Append(val)
if o.TotalItems != 1 {
t.Errorf("%T should have exactly an element, found %d", o, o.TotalItems)
}
if !reflect.DeepEqual(o.OrderedItems[0], val) { if !reflect.DeepEqual(o.OrderedItems[0], val) {
t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID) t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID)
} }

View file

@ -8,7 +8,7 @@ type (
SharesCollection = Shares SharesCollection = Shares
// Shares is a type alias for an Ordered Collection // Shares is a type alias for an Ordered Collection
Shares OrderedCollection Shares = OrderedCollection
) )
// SharesNew initializes a new Shares // SharesNew initializes a new Shares
@ -23,54 +23,3 @@ func SharesNew() *Shares {
return &i return &i
} }
// Append adds an element to an Shares
func (o *Shares) Append(ob Item) error {
o.OrderedItems = append(o.OrderedItems, ob)
o.TotalItems++
return nil
}
// GetID returns the ObjectID corresponding to Shares
func (o Shares) GetID() ObjectID {
return o.Collection().GetID()
}
// GetLink returns the IRI corresponding to the current Shares object
func (o Shares) GetLink() IRI {
return IRI(o.ID)
}
// GetType returns the Shares's type
func (o Shares) GetType() ActivityVocabularyType {
return o.Type
}
// IsLink returns false for an Shares object
func (o Shares) IsLink() bool {
return false
}
// IsObject returns true for a Shares object
func (o Shares) IsObject() bool {
return true
}
// UnmarshalJSON
func (o *Shares) UnmarshalJSON(data []byte) error {
if ItemTyperFunc == nil {
ItemTyperFunc = JSONGetItemByType
}
c := OrderedCollection(*o)
err := c.UnmarshalJSON(data)
*o = Shares(c)
return err
}
// Collection returns the underlying Collection type
func (o Shares) Collection() CollectionInterface {
c := OrderedCollection(o)
return &c
}

View file

@ -2,38 +2,6 @@ package activitypub
import "testing" import "testing"
func TestShares_Append(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_Collection(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_GetID(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_GetLink(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_GetType(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_IsLink(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_IsObject(t *testing.T) {
t.Skipf("TODO")
}
func TestShares_UnmarshalJSON(t *testing.T) {
t.Skipf("TODO")
}
func TestSharesNew(t *testing.T) { func TestSharesNew(t *testing.T) {
t.Skipf("TODO") t.Skipf("TODO")
} }