From 4d5fd9ff2dee496a1bcf2a3c01b1aacf0c5f45ee Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Sun, 29 Mar 2020 18:26:30 +0200 Subject: [PATCH] Making Collection,OrderedCollectin and Item array implement the ItemMatcher interface --- collection.go | 5 +++++ collection_page.go | 5 +++++ helpers.go | 6 +----- item.go | 1 + item_collection.go | 4 ++++ ordered_collection.go | 5 +++++ ordered_collection_page.go | 5 +++++ 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/collection.go b/collection.go index 9cc8c22..0f5d11e 100644 --- a/collection.go +++ b/collection.go @@ -290,3 +290,8 @@ func FollowingNew() *Following { return &i } + +// ItemMatches +func (c Collection) ItemMatches(it Item) bool { + return c.Items.Contains(it.GetLink()) +} diff --git a/collection_page.go b/collection_page.go index 9ebf65f..94b6c99 100644 --- a/collection_page.go +++ b/collection_page.go @@ -284,3 +284,8 @@ func ToCollectionPage(it Item) (*CollectionPage, error) { } return nil, errors.New("unable to convert to collection page") } + +// ItemMatches +func (c CollectionPage) ItemMatches(it Item) bool { + return c.Items.Contains(it.GetLink()) +} diff --git a/helpers.go b/helpers.go index 5d3a46c..b4c4502 100644 --- a/helpers.go +++ b/helpers.go @@ -92,11 +92,7 @@ func OnCollectionIntf(it Item, fn withCollectionInterfaceFn) error { if err != nil { return err } - c := Collection{ - TotalItems: uint(len(*col)), - Items: *col, - } - return fn(&c) + return fn(col) case CollectionType: col, err := ToCollection(it) if err != nil { diff --git a/item.go b/item.go index 555b217..486b6c0 100644 --- a/item.go +++ b/item.go @@ -18,3 +18,4 @@ func Flatten(it Item) Item { } return it } + diff --git a/item_collection.go b/item_collection.go index cad7e92..9f4649f 100644 --- a/item_collection.go +++ b/item_collection.go @@ -151,3 +151,7 @@ func ToItemCollection(it Item) (*ItemCollection, error) { } return nil, errors.New("unable to convert to item collection") } + +func (i ItemCollection) ItemMatches(it Item) bool { + return i.Contains(it.GetLink()) +} diff --git a/ordered_collection.go b/ordered_collection.go index dd19fae..4b20686 100644 --- a/ordered_collection.go +++ b/ordered_collection.go @@ -385,3 +385,8 @@ func SharesNew() *Shares { return &i } + +// ItemMatches +func (o OrderedCollection) ItemMatches(it Item) bool { + return o.OrderedItems.Contains(it.GetLink()) +} diff --git a/ordered_collection_page.go b/ordered_collection_page.go index 0a070cf..aed70c1 100644 --- a/ordered_collection_page.go +++ b/ordered_collection_page.go @@ -239,3 +239,8 @@ func ToOrderedCollectionPage(it Item) (*OrderedCollectionPage, error) { } return nil, errors.New("unable to convert to ordered collection page") } + +// ItemMatches +func (o OrderedCollectionPage) ItemMatches(it Item) bool { + return o.OrderedItems.Contains(it.GetLink()) +}