Changes
3 changed files (+92/-15)
-
-
@@ -6,8 +6,8 @@ import "time"type CreateActivity struct { Activity *Create Published time.Time To *ObjectOrLink CC *ObjectOrLink To ObjectsArr CC ObjectsArr } // CreateActivityNew initializes a new CreateActivity message
-
-
-
@@ -91,9 +91,11 @@ type (Object() apObject Link() Link } // LinkOrUri is an interface that Object and Link structs implement, and at the same time // ObjectsArr is a named type for matching an ObjectOrLink slice type to Collection interface ObjectsArr []ObjectOrLink // LinkOrURI is an interface that Object and Link structs implement, and at the same time // they are kept disjointed LinkOrUri interface{} LinkOrURI interface{} // ImageOrLink is an interface that Image and Link structs implement ImageOrLink interface{} // MimeType is the type for MIME types
-
@@ -192,15 +194,15 @@ type apObject struct {// The date and time at which the object was updated Updated time.Time `jsonld:"updated,omitempty"` // Identifies one or more links to representations of the object URL LinkOrUri `jsonld:"url,omitempty"` URL LinkOrURI `jsonld:"url,omitempty"` // Identifies an entity considered to be part of the public primary audience of an Activity Pub Object To ObjectOrLink `jsonld:"to,omitempty"` To ObjectsArr `jsonld:"to,omitempty"` // Identifies an Activity Pub Object that is part of the private primary audience of this Activity Pub Object. Bto ObjectOrLink `jsonld:"bto,omitempty"` Bto ObjectsArr `jsonld:"bto,omitempty"` // Identifies an Activity Pub Object that is part of the public secondary audience of this Activity Pub Object. Cc ObjectOrLink `jsonld:"cc,omitempty"` CC ObjectsArr `jsonld:"cc,omitempty"` // Identifies one or more Objects that are part of the private secondary audience of this Activity Pub Object. Bcc ObjectOrLink `jsonld:"bcc,omitempty"` BCC ObjectsArr `jsonld:"bcc,omitempty"` // When the object describes a time-bound resource, such as an audio or video, a meeting, etc, // the duration property indicates the object's approximate duration. // The value must be expressed as an xsd:duration as defined by [ xmlschema11-2],
-
@@ -259,3 +261,40 @@ func (o apObject) Object() apObject {func (o apObject) Link() Link { return Link{} } func (c *ObjectsArr) Append(o ObjectOrLink) error { old_len := len(*c) d := make(ObjectsArr, old_len+1) for k, it := range *c { d[k] = it } d[old_len] = o *c = d return nil } // RecipientsDeduplication normalizes the received recipient lists func RecipientsDeduplication(others ...*ObjectsArr) error { recIds := make([]ObjectID, 0) for _, list := range others { if list == nil { continue } for i, rec := range *list { save := true for _, id := range recIds { if rec.Object().ID == id { // remove the element *list = append((*list)[:i], (*list)[i+1:]...) save = false continue } } if save { recIds = append(recIds, rec.Object().ID) } } } return nil }
-
-
-
@@ -1,6 +1,6 @@package tests // S2S tests from: https://test.activitypub.rocks/ // Server to Server tests from: https://test.activitypub.rocks/ import ( "activitypub"
-
@@ -23,7 +23,6 @@ func testActivityHasObject(activity interface{}, obj LinkOrObject) error {*/ func TestMain(m *testing.M) { // call flag.Parse() here if TestMain uses flags fmt.Println("starting") status := m.Run() fmt.Println("ending")
-
@@ -163,7 +162,46 @@ func TestTargetPropertyExistsForRemove(t *testing.T) {// (For example, the same actor could appear on both the to and cc fields, or the actor could be explicitly addressed // in to but could also be a member of the addressed followers collection of the sending actor.) // The server should deduplicate the list of inboxes to deliver to before delivering. //func TestDeduplication(t *testing.T) { // to := activitypub.PersonNew("bob") // cc := []*activitypub.Person{activitypub.PersonNew("alice")} //} func TestDeduplication(t *testing.T) { to := activitypub.PersonNew("bob") o := activitypub.ObjectNew("something", activitypub.ArticleType) cc := activitypub.PersonNew("alice") c := activitypub.CreateNew("create", o) c.To.Append(to) c.CC.Append(cc) c.BCC.Append(cc) activitypub.RecipientsDeduplication(&c.To, &c.Bto, &c.CC, &c.BCC) iter := func(list activitypub.ObjectsArr, recIds *[]activitypub.ObjectID) error { for _, rec := range list { for _, id := range *recIds { if rec.Object().ID == id { return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id) } } *recIds = append(*recIds, rec.Object().ID) } return nil } var err error recIds := make([]activitypub.ObjectID, 0) err = iter(c.To, &recIds) if err != nil { t.Error(err) } err = iter(c.Bto, &recIds) if err != nil { t.Error(err) } err = iter(c.CC, &recIds) if err != nil { t.Error(err) } err = iter(c.BCC, &recIds) if err != nil { t.Error(err) } }
-