From cf3741d6bb3fdabda03c0ba9c81d36f2a9587a96 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Thu, 19 Dec 2019 13:30:18 +0100 Subject: [PATCH] Removed the files with aliases for collections --- collection.go | 30 ++++++++++ collection_test.go | 7 +++ followers.go | 9 --- followers_test.go | 7 --- following.go | 25 --------- following_test.go | 7 --- inbox.go | 26 --------- inbox_test.go | 26 --------- liked.go | 25 --------- liked_test.go | 26 --------- likes.go | 25 --------- likes_test.go | 7 --- ordered_collection.go | 112 +++++++++++++++++++++++++++++++++++++ ordered_collection_test.go | 71 +++++++++++++++++++++++ outbox.go | 24 -------- outbox_test.go | 102 --------------------------------- shares.go | 25 --------- shares_test.go | 7 --- 18 files changed, 220 insertions(+), 341 deletions(-) delete mode 100644 followers.go delete mode 100644 followers_test.go delete mode 100644 following.go delete mode 100644 following_test.go delete mode 100644 inbox.go delete mode 100644 inbox_test.go delete mode 100644 liked.go delete mode 100644 liked_test.go delete mode 100644 likes.go delete mode 100644 likes_test.go delete mode 100644 outbox.go delete mode 100644 outbox_test.go delete mode 100644 shares.go delete mode 100644 shares_test.go diff --git a/collection.go b/collection.go index 7580e68..4b64d57 100644 --- a/collection.go +++ b/collection.go @@ -131,6 +131,22 @@ type Collection struct { Items ItemCollection `jsonld:"items,omitempty"` } +type ( + // FollowersCollection is a collection of followers + FollowersCollection = Followers + + // Followers is a Collection type + Followers = Collection + + // FollowingCollection is a list of everybody that the actor has followed, added as a side effect. + // The following collection MUST be either an OrderedCollection or a Collection and MAY + // be filtered on privileges of an authenticated user or as appropriate when no authentication is given. + FollowingCollection = Following + + // Following is a type alias for a simple Collection + Following = Collection +) + // CollectionNew initializes a new Collection func CollectionNew(id ID) *Collection { c := Collection{ID: id, Type: CollectionType} @@ -293,3 +309,17 @@ func ToCollection(it Item) (*Collection, error) { } return nil, errors.New("unable to convert to collection") } + +// FollowingNew initializes a new Following +func FollowingNew() *Following { + id := ID("following") + + i := Following{ID: id, Type: CollectionType} + i.Name = NaturalLanguageValuesNew() + i.Content = NaturalLanguageValuesNew() + i.Summary = NaturalLanguageValuesNew() + + i.TotalItems = 0 + + return &i +} diff --git a/collection_test.go b/collection_test.go index 59a5f6f..d611576 100644 --- a/collection_test.go +++ b/collection_test.go @@ -174,3 +174,10 @@ func TestCollection_IsCollection(t *testing.T) { t.Skipf("TODO") } +func TestFollowersNew(t *testing.T) { + t.Skipf("TODO") +} + +func TestFollowingNew(t *testing.T) { + t.Skipf("TODO") +} diff --git a/followers.go b/followers.go deleted file mode 100644 index 425c37b..0000000 --- a/followers.go +++ /dev/null @@ -1,9 +0,0 @@ -package activitypub - -type ( - // FollowersCollection is a collection of followers - FollowersCollection = Followers - - // Followers is a Collection type - Followers = Collection -) diff --git a/followers_test.go b/followers_test.go deleted file mode 100644 index faeee6c..0000000 --- a/followers_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package activitypub - -import "testing" - -func TestFollowersNew(t *testing.T) { - t.Skipf("TODO") -} diff --git a/following.go b/following.go deleted file mode 100644 index 82c1d7a..0000000 --- a/following.go +++ /dev/null @@ -1,25 +0,0 @@ -package activitypub - -type ( - // FollowingCollection is a list of everybody that the actor has followed, added as a side effect. - // The following collection MUST be either an OrderedCollection or a Collection and MAY - // be filtered on privileges of an authenticated user or as appropriate when no authentication is given. - FollowingCollection = Following - - // Following is a type alias for a simple Collection - Following = Collection -) - -// FollowingNew initializes a new Following -func FollowingNew() *Following { - id := ID("following") - - i := Following{ID: id, Type: CollectionType} - i.Name = NaturalLanguageValuesNew() - i.Content = NaturalLanguageValuesNew() - i.Summary = NaturalLanguageValuesNew() - - i.TotalItems = 0 - - return &i -} diff --git a/following_test.go b/following_test.go deleted file mode 100644 index 55a333c..0000000 --- a/following_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package activitypub - -import "testing" - -func TestFollowingNew(t *testing.T) { - t.Skipf("TODO") -} diff --git a/inbox.go b/inbox.go deleted file mode 100644 index 70e481e..0000000 --- a/inbox.go +++ /dev/null @@ -1,26 +0,0 @@ -package activitypub - -type ( - // InboxStream contains all activities received by the actor. - // The server SHOULD filter content according to the requester's permission. - // In general, the owner of an inbox is likely to be able to access all of their inbox contents. - // Depending on access control, some other content may be public, whereas other content may - // require authentication for non-owner users, if they can access the inbox at all. - InboxStream = Inbox - - // Inbox is a type alias for an Ordered Collection - Inbox = OrderedCollection -) - -// InboxNew initializes a new Inbox -func InboxNew() *OrderedCollection { - id := ID("inbox") - - i := OrderedCollection{ID: id, Type: CollectionType} - i.Name = NaturalLanguageValuesNew() - i.Content = NaturalLanguageValuesNew() - - i.TotalItems = 0 - - return &i -} diff --git a/inbox_test.go b/inbox_test.go deleted file mode 100644 index 5257260..0000000 --- a/inbox_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package activitypub - -import ( - "testing" -) - -func TestInboxNew(t *testing.T) { - i := InboxNew() - - id := ID("inbox") - if i.ID != id { - t.Errorf("%T should be initialized with %q as %T", i, id, id) - } - if len(i.Name) != 0 { - t.Errorf("%T should be initialized with 0 length Name", i) - } - if len(i.Content) != 0 { - t.Errorf("%T should be initialized with 0 length Content", i) - } - if len(i.Summary) != 0 { - t.Errorf("%T should be initialized with 0 length Summary", i) - } - if i.TotalItems != 0 { - t.Errorf("%T should be initialized with 0 TotalItems", i) - } -} diff --git a/liked.go b/liked.go deleted file mode 100644 index dab8fa9..0000000 --- a/liked.go +++ /dev/null @@ -1,25 +0,0 @@ -package activitypub - -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 - // a Collection and MAY be filtered on privileges of an authenticated user or as - // appropriate when no authentication is given. - LikedCollection = Liked - - // Liked is a type alias for an Ordered Collection - Liked = OrderedCollection -) - -// LikedCollection initializes a new Outbox -func LikedNew() *OrderedCollection { - id := ID("liked") - - l := OrderedCollection{ID: id, Type: CollectionType} - l.Name = NaturalLanguageValuesNew() - l.Content = NaturalLanguageValuesNew() - - l.TotalItems = 0 - - return &l -} diff --git a/liked_test.go b/liked_test.go deleted file mode 100644 index 313b0a3..0000000 --- a/liked_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package activitypub - -import ( - "testing" -) - -func TestLikedNew(t *testing.T) { - l := LikedNew() - - id := ID("liked") - if l.ID != id { - t.Errorf("%T should be initialized with %q as %T", l, id, id) - } - if len(l.Name) != 0 { - t.Errorf("%T should be initialized with 0 length Name", l) - } - if len(l.Content) != 0 { - t.Errorf("%T should be initialized with 0 length Content", l) - } - if len(l.Summary) != 0 { - t.Errorf("%T should be initialized with 0 length Summary", l) - } - if l.TotalItems != 0 { - t.Errorf("%T should be initialized with 0 TotalItems", l) - } -} diff --git a/likes.go b/likes.go deleted file mode 100644 index 0baa141..0000000 --- a/likes.go +++ /dev/null @@ -1,25 +0,0 @@ -package activitypub - -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 - // and MAY be filtered on privileges of an authenticated user or as appropriate when - // no authentication is given. - LikesCollection = Likes - - // Likes is a type alias for an Ordered Collection - Likes = OrderedCollection -) - -// LikesCollection initializes a new Outbox -func LikesNew() *Likes { - id := ID("likes") - - l := Likes{ID: id, Type: CollectionType} - l.Name = NaturalLanguageValuesNew() - l.Content = NaturalLanguageValuesNew() - - l.TotalItems = 0 - - return &l -} diff --git a/likes_test.go b/likes_test.go deleted file mode 100644 index d030dc8..0000000 --- a/likes_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package activitypub - -import "testing" - -func TestLikesNew(t *testing.T) { - t.Skipf("TODO") -} diff --git a/ordered_collection.go b/ordered_collection.go index 615e3dc..9faceb1 100644 --- a/ordered_collection.go +++ b/ordered_collection.go @@ -114,6 +114,53 @@ type OrderedCollection struct { OrderedItems ItemCollection `jsonld:"orderedItems,omitempty"` } +type ( + // InboxStream contains all activities received by the actor. + // The server SHOULD filter content according to the requester's permission. + // In general, the owner of an inbox is likely to be able to access all of their inbox contents. + // Depending on access control, some other content may be public, whereas other content may + // require authentication for non-owner users, if they can access the inbox at all. + InboxStream = Inbox + + // Inbox is a type alias for an Ordered Collection + Inbox = OrderedCollection + + // 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 + // a Collection and MAY be filtered on privileges of an authenticated user or as + // appropriate when no authentication is given. + LikedCollection = Liked + + // Liked is a type alias for an Ordered Collection + Liked = OrderedCollection + + // 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 + // and MAY be filtered on privileges of an authenticated user or as appropriate when + // no authentication is given. + LikesCollection = Likes + + // Likes is a type alias for an Ordered Collection + Likes = OrderedCollection + + // OutboxStream contains activities the user has published, + // subject to the ability of the requestor to retrieve the activity (that is, + // the contents of the outbox are filtered by the permissions of the person reading it). + OutboxStream = Outbox + + // Outbox is a type alias for an Ordered Collection + Outbox = OrderedCollection + + // 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 + // and MAY be filtered on privileges of an authenticated user or as appropriate when no authentication + // is given. + SharesCollection = Shares + + // Shares is a type alias for an Ordered Collection + Shares = OrderedCollection +) + // GetType returns the OrderedCollection's type func (o OrderedCollection) GetType() ActivityVocabularyType { return o.Type @@ -306,3 +353,68 @@ func copyOrderedCollectionToPage(c *OrderedCollection, p *OrderedCollectionPage) p.PartOf = c.GetLink() return nil } + +// InboxNew initializes a new Inbox +func InboxNew() *OrderedCollection { + id := ID("inbox") + + i := OrderedCollection{ID: id, Type: CollectionType} + i.Name = NaturalLanguageValuesNew() + i.Content = NaturalLanguageValuesNew() + + i.TotalItems = 0 + + return &i +} + +// LikedCollection initializes a new Outbox +func LikedNew() *OrderedCollection { + id := ID("liked") + + l := OrderedCollection{ID: id, Type: CollectionType} + l.Name = NaturalLanguageValuesNew() + l.Content = NaturalLanguageValuesNew() + + l.TotalItems = 0 + + return &l +} + +// LikesCollection initializes a new Outbox +func LikesNew() *Likes { + id := ID("likes") + + l := Likes{ID: id, Type: CollectionType} + l.Name = NaturalLanguageValuesNew() + l.Content = NaturalLanguageValuesNew() + + l.TotalItems = 0 + + return &l +} + +// OutboxNew initializes a new Outbox +func OutboxNew() *Outbox { + id := ID("outbox") + + i := Outbox{ID: id, Type: OrderedCollectionType} + i.Name = NaturalLanguageValuesNew() + i.Content = NaturalLanguageValuesNew() + i.TotalItems = 0 + i.OrderedItems = make(ItemCollection, 0) + + return &i +} + +// SharesNew initializes a new Shares +func SharesNew() *Shares { + id := ID("Shares") + + i := Shares{ID: id, Type: CollectionType} + i.Name = NaturalLanguageValuesNew() + i.Content = NaturalLanguageValuesNew() + + i.TotalItems = 0 + + return &i +} diff --git a/ordered_collection_test.go b/ordered_collection_test.go index bc61b27..8f3135c 100644 --- a/ordered_collection_test.go +++ b/ordered_collection_test.go @@ -215,3 +215,74 @@ func TestToOrderedCollection(t *testing.T) { func TestOrderedCollection_Contains(t *testing.T) { t.Skipf("TODO") } + +func TestInboxNew(t *testing.T) { + i := InboxNew() + + id := ID("inbox") + if i.ID != id { + t.Errorf("%T should be initialized with %q as %T", i, id, id) + } + if len(i.Name) != 0 { + t.Errorf("%T should be initialized with 0 length Name", i) + } + if len(i.Content) != 0 { + t.Errorf("%T should be initialized with 0 length Content", i) + } + if len(i.Summary) != 0 { + t.Errorf("%T should be initialized with 0 length Summary", i) + } + if i.TotalItems != 0 { + t.Errorf("%T should be initialized with 0 TotalItems", i) + } +} + +func TestLikedNew(t *testing.T) { + l := LikedNew() + + id := ID("liked") + if l.ID != id { + t.Errorf("%T should be initialized with %q as %T", l, id, id) + } + if len(l.Name) != 0 { + t.Errorf("%T should be initialized with 0 length Name", l) + } + if len(l.Content) != 0 { + t.Errorf("%T should be initialized with 0 length Content", l) + } + if len(l.Summary) != 0 { + t.Errorf("%T should be initialized with 0 length Summary", l) + } + if l.TotalItems != 0 { + t.Errorf("%T should be initialized with 0 TotalItems", l) + } +} + +func TestLikesNew(t *testing.T) { + t.Skipf("TODO") +} + +func TestOutboxNew(t *testing.T) { + o := OutboxNew() + + id := ID("outbox") + if o.ID != id { + t.Errorf("%T should be initialized with %q as %T", o, id, id) + } + if len(o.Name) != 0 { + t.Errorf("%T should be initialized with 0 length Name", o) + } + if len(o.Content) != 0 { + t.Errorf("%T should be initialized with 0 length Content", o) + } + if len(o.Summary) != 0 { + t.Errorf("%T should be initialized with 0 length Summary", o) + } + if o.TotalItems != 0 { + t.Errorf("%T should be initialized with 0 TotalItems", o) + } +} + +func TestSharesNew(t *testing.T) { + t.Skipf("TODO") +} diff --git a/outbox.go b/outbox.go deleted file mode 100644 index 4de90a3..0000000 --- a/outbox.go +++ /dev/null @@ -1,24 +0,0 @@ -package activitypub - -type ( - // OutboxStream contains activities the user has published, - // subject to the ability of the requestor to retrieve the activity (that is, - // the contents of the outbox are filtered by the permissions of the person reading it). - OutboxStream = Outbox - - // Outbox is a type alias for an Ordered Collection - Outbox = OrderedCollection -) - -// OutboxNew initializes a new Outbox -func OutboxNew() *Outbox { - id := ID("outbox") - - i := Outbox{ID: id, Type: OrderedCollectionType} - i.Name = NaturalLanguageValuesNew() - i.Content = NaturalLanguageValuesNew() - i.TotalItems = 0 - i.OrderedItems = make(ItemCollection, 0) - - return &i -} diff --git a/outbox_test.go b/outbox_test.go deleted file mode 100644 index 32a93fa..0000000 --- a/outbox_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package activitypub - -import ( - "reflect" - "testing" -) - -func TestOutboxNew(t *testing.T) { - o := OutboxNew() - - id := ID("outbox") - if o.ID != id { - t.Errorf("%T should be initialized with %q as %T", o, id, id) - } - if len(o.Name) != 0 { - t.Errorf("%T should be initialized with 0 length Name", o) - } - if len(o.Content) != 0 { - t.Errorf("%T should be initialized with 0 length Content", o) - } - if len(o.Summary) != 0 { - t.Errorf("%T should be initialized with 0 length Summary", o) - } - if o.TotalItems != 0 { - t.Errorf("%T should be initialized with 0 TotalItems", o) - } -} - -func TestOutboxStream_GetID(t *testing.T) { - o := OutboxStream{} - if o.GetID() != "" { - t.Errorf("%T should be initialized with empty %T", o, o.GetID()) - } - id := ID("test_out_stream") - o.ID = id - if o.GetID() != id { - t.Errorf("%T should have %T as %q", o, id, id) - } -} - -func TestOutboxStream_GetType(t *testing.T) { - o := OutboxStream{} - - 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 TestOutboxStream_Append(t *testing.T) { - o := OutboxStream{} - - val := Object{ID: ID("grrr")} - - o.Append(val) - if !reflect.DeepEqual(o.OrderedItems[0], val) { - t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID) - } -} - -func TestOutbox_Append(t *testing.T) { - o := OutboxNew() - - val := Object{ID: ID("grrr")} - - o.Append(val) - if !reflect.DeepEqual(o.OrderedItems[0], val) { - t.Errorf("First item in %T.%T does not match %q", o, o.OrderedItems, val.ID) - } -} - -func TestOutbox_Collection(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_GetID(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_GetLink(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_GetType(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_IsLink(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_IsObject(t *testing.T) { - t.Skipf("TODO") -} - -func TestOutbox_UnmarshalJSON(t *testing.T) { - t.Skipf("TODO") -} diff --git a/shares.go b/shares.go deleted file mode 100644 index 03a7dac..0000000 --- a/shares.go +++ /dev/null @@ -1,25 +0,0 @@ -package activitypub - -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 - // and MAY be filtered on privileges of an authenticated user or as appropriate when no authentication - // is given. - SharesCollection = Shares - - // Shares is a type alias for an Ordered Collection - Shares = OrderedCollection -) - -// SharesNew initializes a new Shares -func SharesNew() *Shares { - id := ID("Shares") - - i := Shares{ID: id, Type: CollectionType} - i.Name = NaturalLanguageValuesNew() - i.Content = NaturalLanguageValuesNew() - - i.TotalItems = 0 - - return &i -} diff --git a/shares_test.go b/shares_test.go deleted file mode 100644 index 75343d4..0000000 --- a/shares_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package activitypub - -import "testing" - -func TestSharesNew(t *testing.T) { - t.Skipf("TODO") -}