Changes
5 changed files (+57/-20)
-
-
@@ -1,7 +1,6 @@package activitypub import ( "fmt" "time" "github.com/buger/jsonparser"
-
@@ -384,20 +383,18 @@ func (a *Actor) UnmarshalJSON(data []byte) error {} o := OutboxStream{} v, _, _, err := jsonparser.Get(data, "outbox") if err != nil { fmt.Print(err) if v, _, _, err := jsonparser.Get(data, "outbox"); err == nil { if o.UnmarshalJSON(v) == nil { a.Outbox = &o } } o.UnmarshalJSON(v) a.Outbox = &o r := Collection{} v1, _, _, err := jsonparser.Get(data, "replies") if err != nil { fmt.Print(err) if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { o.Replies = &r } } r.UnmarshalJSON(v1) r.Replies = &r return nil }
-
-
-
@@ -345,15 +345,18 @@ func (c *Collection) UnmarshalJSON(data []byte) error {c.Type = getAPType(data) c.Name = getAPNaturalLanguageField(data, "name") c.Content = getAPNaturalLanguageField(data, "content") c.TotalItems = uint(getAPInt(data, "totalItems")) u := getURIField(data, "url") if len(u) > 0 { c.URL = u } c.TotalItems = uint(getAPInt(data, "totalItems")) it := getAPItems(data, "items") if it != nil { c.Items = it } c.Published = getAPTime(data, "published") c.StartTime = getAPTime(data, "startTime") c.Updated = getAPTime(data, "updated") return nil }
-
-
-
@@ -443,13 +443,12 @@ func (o *Object) UnmarshalJSON(data []byte) error {//} //fmt.Printf("%s\n %#v", data, o) r := Collection{} v1, _, _, err := jsonparser.Get(data, "replies") if err != nil { fmt.Print(err) if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { o.Replies = &r } } r.UnmarshalJSON(v1) r.Replies = &r return nil }
-
-
-
@@ -0,0 +1,17 @@{ "@context": "https://www.w3.org/ns/activitystreams", "type": "Object", "id": "http://www.test.example/object/1", "replies": { "id": "http://www.test.example/object/1/replies", "type": "Collection", "totalItems": 1, "items": [ { "id": "http://www.test.example/object/1/replies/2", "type": "Article", "name": "Example title" } ] } }
-
-
-
@@ -224,6 +224,27 @@ var allTests = tests{}, }, }, "object_with_replies": testPair{ path: "./mocks/object_with_replies.json", expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Replies: &a.Collection{ ID: a.ObjectID("http://www.test.example/object/1/replies"), Type: a.CollectionType, TotalItems: 1, Items: a.ItemCollection{ &a.Object{ ID: a.ObjectID("http://www.test.example/object/1/replies/2"), Type: a.ArticleType, Name: a.NaturalLanguageValue{a.NullLangRef: "Example title"}, }, }, }, }, }, //"activity_simple": testPair{ // path: "./mocks/activity_simple.json", // expected: false,
-
@@ -343,7 +364,7 @@ func Test_ActivityPubUnmarshall(t *testing.T) {f = t.Fatalf } f("\n%#v\n should %sequal to\n%#v", object, expLbl, pair.result) f("\n%#v\n should %sequal to expected\n%#v", object, expLbl, pair.result) continue } if !status {
-