Making Collection,OrderedCollectin and Item array implement the ItemMatcher interface

This commit is contained in:
Marius Orcsik 2020-03-29 18:26:30 +02:00
parent 611ae1db29
commit 4d5fd9ff2d
No known key found for this signature in database
GPG key ID: 77618B618F79EB72
7 changed files with 26 additions and 5 deletions

View file

@ -290,3 +290,8 @@ func FollowingNew() *Following {
return &i
}
// ItemMatches
func (c Collection) ItemMatches(it Item) bool {
return c.Items.Contains(it.GetLink())
}

View file

@ -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())
}

View file

@ -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 {

View file

@ -18,3 +18,4 @@ func Flatten(it Item) Item {
}
return it
}

View file

@ -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())
}

View file

@ -385,3 +385,8 @@ func SharesNew() *Shares {
return &i
}
// ItemMatches
func (o OrderedCollection) ItemMatches(it Item) bool {
return o.OrderedItems.Contains(it.GetLink())
}

View file

@ -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())
}