2019-12-03 16:23:59 +00:00
|
|
|
package activitypub
|
2017-09-11 20:45:57 +00:00
|
|
|
|
2018-03-25 18:54:51 +00:00
|
|
|
// Item struct
|
2020-03-31 11:45:24 +00:00
|
|
|
type Item = ObjectOrLink
|
2018-07-25 09:54:12 +00:00
|
|
|
|
2020-03-31 11:45:24 +00:00
|
|
|
const (
|
|
|
|
EmptyIRI IRI = ""
|
|
|
|
NilIRI IRI = "-"
|
|
|
|
|
|
|
|
EmptyID = EmptyIRI
|
|
|
|
NilID = NilIRI
|
|
|
|
)
|
2019-12-03 15:26:43 +00:00
|
|
|
|
2019-12-05 15:41:53 +00:00
|
|
|
// Flatten checks if Item can be flatten to an IRI or array of IRIs and returns it if so
|
|
|
|
func Flatten(it Item) Item {
|
|
|
|
if it.IsCollection() {
|
|
|
|
if c, ok := it.(CollectionInterface); ok {
|
|
|
|
it = FlattenItemCollection(c.Collection())
|
2019-08-23 18:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-05 15:41:53 +00:00
|
|
|
if it != nil && len(it.GetLink()) > 0 {
|
|
|
|
return it.GetLink()
|
|
|
|
}
|
|
|
|
return it
|
2019-08-23 18:39:28 +00:00
|
|
|
}
|
2020-05-07 14:44:17 +00:00
|
|
|
|
|
|
|
// ItemsEqual checks if it and with Items are equal
|
|
|
|
func ItemsEqual(it, with Item) bool {
|
|
|
|
if it == nil || with == nil{
|
|
|
|
return with == it
|
|
|
|
}
|
|
|
|
result := true
|
|
|
|
if it.IsCollection() {
|
|
|
|
if it.GetType() == CollectionOfItems {
|
|
|
|
OnItemCollection(it, func(c *ItemCollection) error {
|
|
|
|
result = c.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if it.GetType() == CollectionType {
|
|
|
|
OnCollection(it, func(c *Collection) error {
|
|
|
|
result = c.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if it.GetType() == OrderedCollectionType {
|
|
|
|
OnOrderedCollection(it, func(c *OrderedCollection) error {
|
|
|
|
result = c.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if it.GetType() == CollectionPageType {
|
|
|
|
OnCollectionPage(it, func(c *CollectionPage) error {
|
|
|
|
result = c.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if it.GetType() == OrderedCollectionPageType {
|
|
|
|
OnOrderedCollectionPage(it, func(c *OrderedCollectionPage) error {
|
|
|
|
result = c.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if it.IsObject() {
|
|
|
|
if ActivityTypes.Contains(with.GetType()) {
|
|
|
|
OnActivity(it, func(i*Activity) error {
|
|
|
|
result = i.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
2020-06-24 11:47:37 +00:00
|
|
|
} else if ActorTypes.Contains(with.GetType()) {
|
2020-05-07 14:44:17 +00:00
|
|
|
OnActor(it, func(i *Actor) error {
|
|
|
|
result = i.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
2020-06-24 11:47:37 +00:00
|
|
|
} else {
|
|
|
|
OnObject(it, func(i *Object) error {
|
|
|
|
result = i.Equals(with)
|
|
|
|
return nil
|
|
|
|
})
|
2020-05-07 14:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if with.IsLink() {
|
|
|
|
result = with.GetLink().Equals(it.GetLink(), false)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|