From ed06508b7b31d9dbdecd7c7073805c6d9997f130 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Fri, 27 Sep 2019 16:35:20 +0300 Subject: [PATCH] Sigh, local object/actor structs have just become more complicated --- actors.go | 10 +++++++--- object.go | 4 ++-- tests/unmarshalling_test.go | 12 +++++++----- unmarshall.go | 10 +++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/actors.go b/actors.go index 8e4fbb3..d3c6cd9 100644 --- a/actors.go +++ b/actors.go @@ -37,7 +37,7 @@ type Endpoints struct { // Actors are retrieved like any other Object in ActivityPub. // Like other ActivityStreams objects, actors have an id, which is a URI. type actor struct { - as.Parent + Parent // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox. Inbox as.Item `jsonld:"inbox,omitempty"` @@ -93,7 +93,7 @@ func actorNew(id as.ObjectID, typ as.ActivityVocabularyType) *actor { typ = as.ActorType } - a := actor{Parent: as.Object{ID: id, Type: typ}} + a := actor{Parent: Object{Parent: as.Parent{ID: id, Type: typ}}} a.Name = as.NaturalLanguageValuesNew() a.Content = as.NaturalLanguageValuesNew() a.Summary = as.NaturalLanguageValuesNew() @@ -155,8 +155,12 @@ func (a *actor) UnmarshalJSON(data []byte) error { func ToPerson(it as.Item) (*Person, error) { switch i := it.(type) { case *as.Object: - return &Person{Parent: *i}, nil + return &Person{Parent: Object{Parent: *i}}, nil case as.Object: + return &Person{Parent: Object{Parent: i}}, nil + case *Object: + return &Person{Parent: *i}, nil + case Object: return &Person{Parent: i}, nil case *actor: return i, nil diff --git a/object.go b/object.go index 2113998..d612952 100644 --- a/object.go +++ b/object.go @@ -15,11 +15,11 @@ type Source struct { MediaType as.MimeType `jsonld:"mediaType"` } -type Parent = as.Object +type Parent = Object // Object type Object struct { - Parent + as.Parent // Source property is intended to convey some sort of source from which the content markup was derived, // as a form of provenance, or to support future editing by clients. // In general, clients do the conversion from source to content, not the other way around. diff --git a/tests/unmarshalling_test.go b/tests/unmarshalling_test.go index 11b6ea5..ff716d2 100644 --- a/tests/unmarshalling_test.go +++ b/tests/unmarshalling_test.go @@ -288,11 +288,13 @@ var allTests = tests{ expected: true, blank: &ap.Person{}, result: &ap.Person{ - Parent: a.Parent{ - ID: a.ObjectID("http://example.com/accounts/ana"), - Type: a.PersonType, - Name: a.NaturalLanguageValues{{a.NilLangRef, "ana"}}, - URL: a.IRI("http://example.com/accounts/ana"), + Parent: ap.Parent{ + Parent: a.Parent{ + ID: a.ObjectID("http://example.com/accounts/ana"), + Type: a.PersonType, + Name: a.NaturalLanguageValues{{a.NilLangRef, "ana"}}, + URL: a.IRI("http://example.com/accounts/ana"), + }, }, PreferredUsername: a.NaturalLanguageValues{{a.NilLangRef, "Ana"}}, Outbox: &a.OrderedCollection{ diff --git a/unmarshall.go b/unmarshall.go index a910706..a3729cb 100644 --- a/unmarshall.go +++ b/unmarshall.go @@ -6,13 +6,13 @@ import ( ) func JSONGetItemByType(typ as.ActivityVocabularyType) (as.Item, error) { - obTyp := as.ActivityVocabularyTypes{as.ObjectType,} - if as.ObjectTypes.Contains(typ) || obTyp.Contains(typ) { - return &Object{Parent: Parent{Type: typ}}, nil + obTyp := as.ActivityVocabularyTypes{as.ObjectType} + if as.ObjectTypes.Contains(typ) || obTyp.Contains(typ) { + return &Object{Parent: as.Object{Type: typ}}, nil } - actTyp := as.ActivityVocabularyTypes{as.ActorType,} + actTyp := as.ActivityVocabularyTypes{as.ActorType} if as.ActorTypes.Contains(typ) || actTyp.Contains(typ) { - return &actor{Parent: Parent{Type: typ}}, nil + return &actor{Parent: Parent{Parent: as.Object{Type: typ}}}, nil } return as.JSONGetItemByType(typ) }