Changes
11 changed files (+644/-26)
-
-
@@ -763,3 +763,58 @@ func (a Activity) MarshalJSON() ([]byte, error) {write(&b, '}') return b, nil } // Equals verifies if our receiver Object is equals with the "with" Object func (a Activity) Equals(with Item) bool { result := true OnActivity(with, func(w *Activity) error { OnObject(a, func(o *Object) error { result = o.Equals(w) return nil }) if w.Object != nil { if !ItemsEqual(a.Object, w.Object) { result = false return nil } } if w.Actor != nil { if !ItemsEqual(a.Actor, w.Actor) { result = false return nil } } if w.Target != nil { if !ItemsEqual(a.Target, w.Target) { result = false return nil } } if w.Result != nil { if !ItemsEqual(a.Result, w.Result) { result = false return nil } } if w.Origin != nil { if !ItemsEqual(a.Origin, w.Origin) { result = false return nil } } if w.Result != nil { if !ItemsEqual(a.Result, w.Result) { result = false return nil } } if w.Instrument != nil { if !ItemsEqual(a.Instrument, w.Instrument) { result = false return nil } } return nil }) return result }
-
-
-
@@ -131,7 +131,7 @@ type Actor struct {// see 5.2 Inbox. Inbox Item `jsonld:"inbox,omitempty"` // An [ActivityStreams] OrderedCollection comprised of all the messages produced by the actor; // see 5.1 Outbox. // see 5.1 outbox. Outbox Item `jsonld:"outbox,omitempty"` // A link to an [ActivityStreams] collection of the actors that this actor is following; // see 5.4 Following Collection
-
@@ -452,3 +452,19 @@ func ToActor(it Item) (*Actor, error) {} return nil, errors.New("unable to convert object") } // Equals verifies if our receiver Object is equals with the "with" Object func (a Actor) Equals(with Item) bool { result := true OnActor(with, func(w *Actor) error { OnObject(w, func(wo *Object) error { if !wo.Equals(a) { result = false return nil } return nil }) return nil }) return result }
-
-
-
@@ -21,7 +21,7 @@ type CollectionInterface interface {Collection() ItemCollection Append(ob Item) error Count() uint Contains(IRI) bool Contains(Item) bool } // Collection is a subtype of Activity Pub Object that represents ordered or unordered sets of Activity Pub Object or Link instances.
-
@@ -215,12 +215,12 @@ func (c *Collection) Count() uint {} // Contains verifies if Collection array contains the received one func (c Collection) Contains(r IRI) bool { func (c Collection) Contains(r Item) bool { if len(c.Items) == 0 { return false } for _, iri := range c.Items { if r.Equals(iri.GetLink(), false) { for _, it := range c.Items { if ItemsEqual(it, r) { return true } }
-
@@ -293,5 +293,57 @@ func FollowingNew() *Following {// ItemMatches func (c Collection) ItemMatches(it Item) bool { return c.Items.Contains(it.GetLink()) return c.Items.Contains(it) } // Equals func (c Collection) Equals(with Item) bool { if with == nil { return false } if !with.IsCollection() { return false } result := true OnCollection(with, func(w *Collection) error { OnObject(w, func(wo *Object) error { if !wo.Equals(c) { result = false return nil } return nil }) if w.TotalItems > 0 { if w.TotalItems != c.TotalItems { result = false return nil } } if w.Current != nil { if !ItemsEqual(c.Current, w.Current) { result = false return nil } } if w.First != nil { if !ItemsEqual(c.First, w.First) { result = false return nil } } if w.Last != nil { if !ItemsEqual(c.Last, w.Last) { result = false return nil } } if w.Items != nil { if !c.Items.Equals(w.Items) { result = false return nil } } return nil }) return result }
-
-
-
@@ -170,12 +170,12 @@ func (c *CollectionPage) Append(ob Item) error {} // Contains verifies if CollectionPage array contains the received one func (c CollectionPage) Contains(r IRI) bool { func (c CollectionPage) Contains(r Item) bool { if len(c.Items) == 0 { return false } for _, iri := range c.Items { if r.Equals(iri.GetLink(), false) { for _, it := range c.Items { if ItemsEqual(it, r) { return true } }
-
@@ -287,5 +287,63 @@ func ToCollectionPage(it Item) (*CollectionPage, error) {// ItemMatches func (c CollectionPage) ItemMatches(it Item) bool { return c.Items.Contains(it.GetLink()) return c.Items.Contains(it) } // Equals func (c CollectionPage) Equals(with Item) bool { if with == nil { return false } if !with.IsCollection() { return false } result := true OnCollectionPage(with, func(w *CollectionPage) error { OnCollection(w, func(wo *Collection) error { if !wo.Equals(c) { result = false return nil } return nil }) if w.PartOf != nil { if !ItemsEqual(c.PartOf, w.PartOf) { result = false return nil } } if w.Current != nil { if !ItemsEqual(c.Current, w.Current) { result = false return nil } } if w.First != nil { if !ItemsEqual(c.First, w.First) { result = false return nil } } if w.Last != nil { if !ItemsEqual(c.Last, w.Last) { result = false return nil } } if w.Next != nil { if !ItemsEqual(c.Next, w.Next) { result = false return nil } } if w.Prev != nil { if !ItemsEqual(c.Prev, w.Prev) { result = false return nil } } return nil }) return result }
-
-
-
@@ -23,3 +23,67 @@ func Flatten(it Item) Item {} 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 }
-
-
-
@@ -76,12 +76,12 @@ func (i ItemCollection) IsCollection() bool {} // Contains verifies if IRIs array contains the received one func (i ItemCollection) Contains(r IRI) bool { func (i ItemCollection) Contains(r Item) bool { if len(i) == 0 { return false } for _, iri := range i { if r.Equals(iri.GetLink(), false) { for _, it := range i { if ItemsEqual(it, r) { return true } }
-
@@ -153,5 +153,33 @@ func ToItemCollection(it Item) (*ItemCollection, error) {} func (i ItemCollection) ItemMatches(it Item) bool { return i.Contains(it.GetLink()) return i.Contains(it) } // Equals func (i ItemCollection) Equals(with Item) bool { if with == nil { return false } if !with.IsCollection() { return false } if with.GetType() != CollectionOfItems { return false } result := true OnItemCollection(with, func(w *ItemCollection) error { if w.Count() != i.Count() { result = false return nil } for _, it := range i { if !w.Contains(it.GetLink()) { result = false return nil } } return nil }) return result }
-
-
-
@@ -289,3 +289,19 @@ func (n *NaturalLanguageValues) UnmarshalText(data []byte) error {} return nil } // Equals func (n NaturalLanguageValues) Equals(with NaturalLanguageValues) bool { if n.Count() != with.Count() { return false } for _, wv := range with { for _, nv := range n { if nv == wv { continue } return false } } return true }
-
-
-
@@ -465,3 +465,62 @@ func TestNaturalLanguageValues_String(t *testing.T) {func TestNaturalLanguageValues_Count(t *testing.T) { t.Skipf("TODO") } func TestNaturalLanguageValues_Equals(t *testing.T) { type args struct { with NaturalLanguageValues } tests := []struct { name string n NaturalLanguageValues args args want bool }{ { name: "equal-key-value", n: NaturalLanguageValues{LangRefValue{ Ref: "en", Value: "test123#", }}, args: args{ with: NaturalLanguageValues{LangRefValue{ Ref: "en", Value: "test123#", }}, }, want: true, }, { name: "not-equal-key", n: NaturalLanguageValues{LangRefValue{ Ref: "en", Value: "test123#", }}, args: args{ with: NaturalLanguageValues{LangRefValue{ Ref: "fr", Value: "test123#", }}, }, want: false, }, { name: "not-equal-value", n: NaturalLanguageValues{LangRefValue{ Ref: "en", Value: "test123#", }}, args: args{ with: NaturalLanguageValues{LangRefValue{ Ref: "en", Value: "test123", }}, }, want: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.n.Equals(tt.args.with); got != tt.want { t.Errorf("Equals() = %v, want %v", got, tt.want) } }) } }
-
-
-
@@ -461,3 +461,186 @@ func (s Source) MarshalJSON() ([]byte, error) {} return nil, nil } // Equals verifies if our receiver Object is equals with the "with" Object func (o Object) Equals(with Item) bool { if with.IsCollection() { return false } if withID := with.GetID(); len(withID) > 0 && withID != o.ID { return false } if withType := with.GetType(); len(withType) > 0 && withType != o.Type { return false } if with.IsLink() && !with.GetLink().Equals(o.GetLink(), false) { return false } result := true OnObject(with, func(w *Object) error { if len(w.Name) > 0 { if !w.Name.Equals(o.Name) { result = false return nil } } if len(w.Summary) > 0 { if !w.Summary.Equals(o.Summary) { result = false return nil } } if len(w.Content) > 0 { if !w.Content.Equals(o.Content) { result = false return nil } } if w.Attachment != nil { if !ItemsEqual(o.Attachment, w.Attachment) { result = false return nil } } if w.AttributedTo != nil { if !ItemsEqual(o.AttributedTo, w.AttributedTo) { result = false return nil } } if w.Audience != nil { if !ItemsEqual(o.Audience, w.Audience) { result = false return nil } } if w.Context != nil { if !ItemsEqual(o.Context, w.Context) { result = false return nil } } if w.Generator != nil { if !ItemsEqual(o.Generator, w.Generator) { result = false return nil } } if w.Icon != nil { if !ItemsEqual(o.Icon, w.Icon) { result = false return nil } } if w.Image != nil { if !ItemsEqual(o.Image, w.Image) { result = false return nil } } if w.InReplyTo != nil { if !ItemsEqual(o.InReplyTo, w.InReplyTo) { result = false return nil } } if w.Location != nil { if !ItemsEqual(o.Location, w.Location) { result = false return nil } } if w.Preview != nil { if !ItemsEqual(o.Preview, w.Preview) { result = false return nil } } if w.Replies != nil { if !ItemsEqual(o.Replies, w.Replies) { result = false return nil } } if w.Tag != nil { if !ItemsEqual(o.Tag, w.Tag) { result = false return nil } } if w.URL != nil { if !w.URL.GetLink().Equals(o.URL.GetLink(), false) { result = false return nil } } if w.To != nil { if !ItemsEqual(o.To, w.To) { result = false return nil } } if w.Bto != nil { if !ItemsEqual(o.Bto, w.Bto) { result = false return nil } } if w.CC != nil { if !ItemsEqual(o.CC, w.CC) { result = false return nil } } if w.BCC != nil { if !ItemsEqual(o.BCC, w.BCC) { result = false return nil } } if !w.Published.IsZero() { if !w.Published.Equal(o.Published) { result = false return nil } } if !w.Updated.IsZero() { if !w.Updated.Equal(o.Updated) { result = false return nil } } if !w.StartTime.IsZero() { if !w.StartTime.Equal(o.StartTime) { result = false return nil } } if !w.EndTime.IsZero() { if !w.EndTime.Equal(o.EndTime) { result = false return nil } } if w.Duration != 0 { if w.Duration != o.Duration { result = false return nil } } if w.Likes != nil { if !ItemsEqual(o.Likes, w.Likes) { result = false return nil } } if w.Shares != nil { if !ItemsEqual(o.Shares, w.Shares) { result = false return nil } } return nil }) return result }
-
-
-
@@ -148,7 +148,7 @@ type (// 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 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,
-
@@ -197,12 +197,12 @@ func (o OrderedCollection) IsCollection() bool {} // Contains verifies if OrderedCollection array contains the received one func (o OrderedCollection) Contains(r IRI) bool { func (o OrderedCollection) Contains(r Item) bool { if len(o.OrderedItems) == 0 { return false } for _, iri := range o.OrderedItems { if r.Equals(iri.GetLink(), false) { for _, it := range o.OrderedItems { if ItemsEqual(it, r) { return true } }
-
@@ -334,7 +334,7 @@ func InboxNew() *OrderedCollection {return &i } // LikedCollection initializes a new Outbox // LikedCollection initializes a new outbox func LikedNew() *OrderedCollection { id := ID("liked")
-
@@ -347,7 +347,7 @@ func LikedNew() *OrderedCollection {return &l } // LikesCollection initializes a new Outbox // LikesCollection initializes a new outbox func LikesNew() *Likes { id := ID("likes")
-
@@ -360,7 +360,7 @@ func LikesNew() *Likes {return &l } // OutboxNew initializes a new Outbox // OutboxNew initializes a new outbox func OutboxNew() *Outbox { id := ID("outbox")
-
@@ -388,5 +388,33 @@ func SharesNew() *Shares {// ItemMatches func (o OrderedCollection) ItemMatches(it Item) bool { return o.OrderedItems.Contains(it.GetLink()) return o.OrderedItems.Contains(it) } // Equals func (o OrderedCollection) Equals(with Item) bool { if with == nil { return false } if !with.IsCollection() { return false } result := true OnOrderedCollection(with, func(w *OrderedCollection) error { OnCollection(w, func(wo *Collection) error { if !wo.Equals(o) { result = false return nil } return nil }) if w.OrderedItems != nil { if !o.OrderedItems.Equals(w.OrderedItems) { result = false return nil } } return nil }) return result }
-
-
-
@@ -173,12 +173,12 @@ func (o *OrderedCollectionPage) Append(ob Item) error {} // Contains verifies if OrderedCollectionPage array contains the received one func (o OrderedCollectionPage) Contains(r IRI) bool { func (o OrderedCollectionPage) Contains(r Item) bool { if len(o.OrderedItems) == 0 { return false } for _, iri := range o.OrderedItems { if r.Equals(iri.GetLink(), false) { for _, it := range o.OrderedItems { if ItemsEqual(it, r) { return true } }
-
@@ -242,5 +242,64 @@ func ToOrderedCollectionPage(it Item) (*OrderedCollectionPage, error) {// ItemMatches func (o OrderedCollectionPage) ItemMatches(it Item) bool { return o.OrderedItems.Contains(it.GetLink()) return o.OrderedItems.Contains(it) } // Equals func (o OrderedCollectionPage) Equals(with Item) bool { if with == nil { return false } if !with.IsCollection() { return false } result := true OnOrderedCollectionPage(with, func(w *OrderedCollectionPage) error { OnOrderedCollection(w, func(wo *OrderedCollection) error { if !wo.Equals(o) { result = false return nil } return nil }) if w.PartOf != nil { if !ItemsEqual(o.PartOf, w.PartOf) { result = false return nil } } if w.Current != nil { if !ItemsEqual(o.Current, w.Current) { result = false return nil } } if w.First != nil { if !ItemsEqual(o.First, w.First) { result = false return nil } } if w.Last != nil { if !ItemsEqual(o.Last, w.Last) { result = false return nil } } if w.Next != nil { if !ItemsEqual(o.Next, w.Next) { result = false return nil } } if w.Prev != nil { if !ItemsEqual(o.Prev, w.Prev) { result = false return nil } } return nil }) return result }
-