-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
package activitypub
// Item struct
type Item = ObjectOrLink
const (
EmptyIRI IRI = ""
NilIRI IRI = "-"
EmptyID = EmptyIRI
NilID = NilIRI
)
// 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())
}
}
if it != nil && len(it.GetLink()) > 0 {
return it.GetLink()
}
return it
}
// 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 ObjectTypes.Contains(it.GetType()) {
OnObject(it, func(i *Object) error {
result = i.Equals(with)
return nil
})
}
if ActivityTypes.Contains(with.GetType()) {
OnActivity(it, func(i*Activity) error {
result = i.Equals(with)
return nil
})
}
if ActorTypes.Contains(with.GetType()) {
OnActor(it, func(i *Actor) error {
result = i.Equals(with)
return nil
})
}
}
if with.IsLink() {
result = with.GetLink().Equals(it.GetLink(), false)
}
return result
}