Changes
3 changed files (+91/-39)
-
-
@@ -2,6 +2,8 @@ package activitypubimport ( "time" "github.com/buger/jsonparser" ) // Activity Types
-
@@ -1358,10 +1360,43 @@ func (v View) IsLink() bool {return false } //// UnmarshalJSON //func (a *Activity) UnmarshalJSON(data []byte) error { // ob, err := unmarshal(data, *a) // *a = ob.(Activity) // // return err //} // UnmarshalJSON func (a *Activity) UnmarshalJSON(data []byte) error { a.ID = getAPObjectID(data) a.Type = getAPType(data) a.Name = getAPNaturalLanguageField(data, "name") a.Content = getAPNaturalLanguageField(data, "content") u := getURIField(data, "url") if len(u) > 0 { a.URL = u } a.Actor = getAPItem(data, "actor") a.Object = getAPItem(data, "object") a.Generator = getAPItem(data, "generator") a.AttributedTo = getAPItem(data, "attributedTo") a.InReplyTo = getAPItem(data, "inReplyTo") a.Published = getAPTime(data, "published") a.StartTime = getAPTime(data, "startTime") a.Updated = getAPTime(data, "updated") to := getAPObjectsArr(data, "to") if to != nil { a.To = to } if v, _, _, err := jsonparser.Get(data, "replies"); err == nil { r := Collection{} if r.UnmarshalJSON(v) == nil { a.Replies = &r } } return nil } // UnmarshalJSON func (c *Create) UnmarshalJSON(data []byte) error { a := Activity(*c) err := a.UnmarshalJSON(data) *c = Create(a) return err }
-
-
-
@@ -14,42 +14,55 @@ type CreateActivity struct {func CreateActivityNew(id ObjectID, a ObjectOrLink, o ObjectOrLink) CreateActivity { act := CreateNew(id, o) ok := false if a != nil { typ := a.GetType() if typ == ApplicationType { switch typ { case ApplicationType: var app Application app, ok = a.(Application) act.Actor = Actor(app) } if typ == GroupType { app, _ = a.(Application) if app.Inbox == nil { app.Inbox = InboxNew() } app.Inbox.Append(o) act.Actor = app case GroupType: var grp Group grp, ok = a.(Group) act.Actor = Actor(grp) } if typ == OrganizationType { grp, _ = a.(Group) if grp.Inbox == nil { grp.Inbox = InboxNew() } grp.Inbox.Append(o) act.Actor = grp case OrganizationType: var org Organization org, ok = a.(Organization) act.Actor = Actor(org) } if typ == PersonType { org, _ = a.(Organization) if org.Inbox == nil { org.Inbox = InboxNew() } org.Inbox.Append(o) act.Actor = org case PersonType: var pers Person pers, ok = a.(Person) act.Actor = Actor(pers) } if typ == ServiceType { pers, _ = a.(Person) if pers.Inbox == nil { pers.Inbox = InboxNew() } pers.Inbox.Append(o) act.Actor = pers case ServiceType: var serv Service serv, ok = a.(Service) act.Actor = Actor(serv) } if !ok { serv, _ = a.(Service) serv.Inbox.Append(o) act.Actor = serv default: actor, _ := a.(Actor) if actor.Inbox == nil { actor.Inbox = InboxNew() } actor.Inbox.Append(o) act.Actor = actor } } aa := act.Actor.(*Actor) aa.Inbox = InboxNew() aa.Inbox.Append(o) c := CreateActivity{ Activity: act,
-
-
-
@@ -45,11 +45,9 @@ func TestCreateActivityNewWithApplication(t *testing.T) {if !reflect.DeepEqual(c1.Activity.Actor.GetID(), a.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), a.GetID()) } /* if !reflect.DeepEqual(c1.Activity.Actor, Actor(*a)) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*a)) } */ //if !reflect.DeepEqual(c1.Activity.Actor, Actor(*a)) { // t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, Actor(*a)) //} if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) }
-
@@ -59,9 +57,15 @@ func TestCreateActivityNewWithApplication(t *testing.T) {if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := *c1.Activity.Actor.Inbox.(*Inbox) in := c1.Activity.Actor.(Application).Inbox.(*Inbox) if in.TotalItems != 1 { t.Errorf("Inbox collection of %q should have exactly an GetID", *c1.Activity.Actor.GetID()) t.Errorf("Inbox collection of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), in.TotalItems) } if len(in.OrderedItems) != 1 { t.Errorf("Inbox collection length of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), len(in.OrderedItems)) } if in.TotalItems != uint(len(in.OrderedItems)) { t.Errorf("Inbox collection length of %q should have same size as TotalItems, %d vs %d", *c1.Activity.Actor.GetID(), in.TotalItems, len(in.OrderedItems)) } if !reflect.DeepEqual(in.OrderedItems[0].GetID(), n.GetID()) { t.Errorf("First item in Inbox is does not match %q", *n.GetID())
-