Changes
15 changed files (+1980/-1218)
-
activity.go (new)
-
@@ -0,0 +1,374 @@package activitypub import ( as "github.com/go-ap/activitystreams" ) // Activity is a subtype of Object that describes some form of action that may happen, // is currently happening, or has already happened. // The Activity type itself serves as an abstract base type for all types of activities. // It is important to note that the Activity type itself does not carry any specific semantics // about the kind of action being taken. type Activity struct { as.Activity } // IntransitiveActivity Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. // The object property is therefore inappropriate for these activities. type IntransitiveActivity struct { as.IntransitiveActivity } type ( // Accept indicates that the actor accepts the object. The target property can be used in certain circumstances to indicate // the context into which the object has been accepted. Accept = Activity // Add indicates that the actor has added the object to the target. If the target property is not explicitly specified, // the target would need to be determined implicitly by context. // The origin can be used to identify the context from which the object originated. Add = Activity // Announce indicates that the actor is calling the target's attention the object. // The origin typically has no defined meaning. Announce = Activity // Arrive is an IntransitiveActivity that indicates that the actor has arrived at the location. // The origin can be used to identify the context from which the actor originated. // The target typically has no defined meaning. Arrive = IntransitiveActivity // Block indicates that the actor is blocking the object. Blocking is a stronger form of Ignore. // The typical use is to support social systems that allow one user to block activities or content of other users. // The target and origin typically have no defined meaning. Block = Ignore // Create indicates that the actor has created the object. Create = Activity // Delete indicates that the actor has deleted the object. // If specified, the origin indicates the context from which the object was deleted. Delete = Activity // Dislike indicates that the actor dislikes the object. Dislike = Activity // Flag indicates that the actor is "flagging" the object. // Flagging is defined in the sense common to many social platforms as reporting content as being // inappropriate for any number of reasons. Flag = Activity // Follow indicates that the actor is "following" the object. Following is defined in the sense typically used within // Social systems in which the actor is interested in any activity performed by or on the object. // The target and origin typically have no defined meaning. Follow = Activity // Ignore indicates that the actor is ignoring the object. The target and origin typically have no defined meaning. Ignore = Activity // Invite is a specialization of Offer in which the actor is extending an invitation for the object to the target. Invite = Offer // Join indicates that the actor has joined the object. The target and origin typically have no defined meaning. Join = Activity // Leave indicates that the actor has left the object. The target and origin typically have no meaning. Leave = Activity // Like indicates that the actor likes, recommends or endorses the object. // The target and origin typically have no defined meaning. Like = Activity // Listen inherits all properties from Activity. Listen = Activity // Move indicates that the actor has moved object from origin to target. // If the origin or target are not specified, either can be determined by context. Move = Activity // Offer indicates that the actor is offering the object. // If specified, the target indicates the entity to which the object is being offered. Offer = Activity // Reject indicates that the actor is rejecting the object. The target and origin typically have no defined meaning. Reject = Activity // Read indicates that the actor has read the object. Read = Activity // Remove indicates that the actor is removing the object. If specified, // the origin indicates the context from which the object is being removed. Remove = Activity // TentativeReject is a specialization of Reject in which the rejection is considered tentative. TentativeReject = Reject // TentativeAccept is a specialization of Accept indicating that the acceptance is tentative. TentativeAccept = Accept // Travel indicates that the actor is traveling to target from origin. // Travel is an IntransitiveObject whose actor specifies the direct object. // If the target or origin are not specified, either can be determined by context. Travel = IntransitiveActivity // Undo indicates that the actor is undoing the object. In most cases, the object will be an Activity describing // some previously performed action (for instance, a person may have previously "liked" an article but, // for whatever reason, might choose to undo that like at some later point in time). // The target and origin typically have no defined meaning. Undo = Activity // Update indicates that the actor has updated the object. Note, however, that this vocabulary does not define a mechanism // for describing the actual set of modifications made to object. // The target and origin typically have no defined meaning. Update = Activity // View indicates that the actor has viewed the object. View = Activity ) // Question represents a question being asked. Question objects are an extension of IntransitiveActivity. // That is, the Question object is an Activity, but the direct object is the question // itself and therefore it would not contain an object property. // Either of the anyOf and oneOf properties may be used to express possible answers, // but a Question object must not have both properties. type Question = as.Question // AcceptNew initializes an Accept activity func AcceptNew(id as.ObjectID, ob as.Item) *Accept { return ActivityNew(id, as.AcceptType, ob) } // AddNew initializes an Add activity func AddNew(id as.ObjectID, ob as.Item, trgt as.Item) *Add { a := ActivityNew(id, as.AddType, ob) a.Target = trgt return a } // AnnounceNew initializes an Announce activity func AnnounceNew(id as.ObjectID, ob as.Item) *Announce { return ActivityNew(id, as.AnnounceType, ob) } // ArriveNew initializes an Arrive activity func ArriveNew(id as.ObjectID) *Arrive { return IntransitiveActivityNew(id, as.ArriveType) } // BlockNew initializes a Block activity func BlockNew(id as.ObjectID, ob as.Item) *Block { return ActivityNew(id, as.BlockType, ob) } // CreateNew initializes a Create activity func CreateNew(id as.ObjectID, ob as.Item) *Create { return ActivityNew(id, as.CreateType, ob) } // DeleteNew initializes a Delete activity func DeleteNew(id as.ObjectID, ob as.Item) *Delete { return ActivityNew(id, as.DeleteType, ob) } // DislikeNew initializes a Dislike activity func DislikeNew(id as.ObjectID, ob as.Item) *Dislike { return ActivityNew(id, as.DislikeType, ob) } // FlagNew initializes a Flag activity func FlagNew(id as.ObjectID, ob as.Item) *Flag { return ActivityNew(id, as.FlagType, ob) } // FollowNew initializes a Follow activity func FollowNew(id as.ObjectID, ob as.Item) *Follow { return ActivityNew(id, as.FollowType, ob) } // IgnoreNew initializes an Ignore activity func IgnoreNew(id as.ObjectID, ob as.Item) *Ignore { return ActivityNew(id, as.IgnoreType, ob) } // InviteNew initializes an Invite activity func InviteNew(id as.ObjectID, ob as.Item) *Invite { return ActivityNew(id, as.InviteType, ob) } // JoinNew initializes a Join activity func JoinNew(id as.ObjectID, ob as.Item) *Join { return ActivityNew(id, as.JoinType, ob) } // LeaveNew initializes a Leave activity func LeaveNew(id as.ObjectID, ob as.Item) *Leave { return ActivityNew(id, as.LeaveType, ob) } // LikeNew initializes a Like activity func LikeNew(id as.ObjectID, ob as.Item) *Like { return ActivityNew(id, as.LikeType, ob) } // ListenNew initializes a Listen activity func ListenNew(id as.ObjectID, ob as.Item) *Listen { return ActivityNew(id, as.ListenType, ob) } // MoveNew initializes a Move activity func MoveNew(id as.ObjectID, ob as.Item) *Move { return ActivityNew(id, as.MoveType, ob) } // OfferNew initializes an Offer activity func OfferNew(id as.ObjectID, ob as.Item) *Offer { return ActivityNew(id, as.OfferType, ob) } // RejectNew initializes a Reject activity func RejectNew(id as.ObjectID, ob as.Item) *Reject { return ActivityNew(id, as.RejectType, ob) } // ReadNew initializes a Read activity func ReadNew(id as.ObjectID, ob as.Item) *Read { return ActivityNew(id, as.ReadType, ob) } // RemoveNew initializes a Remove activity func RemoveNew(id as.ObjectID, ob as.Item, trgt as.Item) *Remove { a := ActivityNew(id, as.RemoveType, ob) a.Target = trgt return a } // TentativeRejectNew initializes a TentativeReject activity func TentativeRejectNew(id as.ObjectID, ob as.Item) *TentativeReject { a := ActivityNew(id, as.TentativeRejectType, ob) o := TentativeReject(*a) return &o } // TentativeAcceptNew initializes a TentativeAccept activity func TentativeAcceptNew(id as.ObjectID, ob as.Item) *TentativeAccept { return ActivityNew(id, as.TentativeAcceptType, ob) } // TravelNew initializes a Travel activity func TravelNew(id as.ObjectID) *Travel { return IntransitiveActivityNew(id, as.TravelType) } // UndoNew initializes an Undo activity func UndoNew(id as.ObjectID, ob as.Item) *Undo { return ActivityNew(id, as.UndoType, ob) } // UpdateNew initializes an Update activity func UpdateNew(id as.ObjectID, ob as.Item) *Update { return ActivityNew(id, as.UpdateType, ob) } // ViewNew initializes a View activity func ViewNew(id as.ObjectID, ob as.Item) *View { return ActivityNew(id, as.ViewType, ob) } // QuestionNew initializes a Question activity func QuestionNew(id as.ObjectID) *Question { q := Question{ ID: id, Type: as.QuestionType} q.Name = as.NaturalLanguageValueNew() q.Content = as.NaturalLanguageValueNew() return &q } // ActivityNew initializes a basic activity func ActivityNew(id as.ObjectID, typ as.ActivityVocabularyType, ob as.Item) *Activity { a := as.ActivityNew(id, typ, ob) return &Activity{ Activity: *a} } // IntransitiveActivityNew initializes a intransitive activity func IntransitiveActivityNew(id as.ObjectID, typ as.ActivityVocabularyType) *IntransitiveActivity { i := as.IntransitiveActivityNew(id, typ) return &IntransitiveActivity{ IntransitiveActivity: *i} } // UnmarshalJSON func (a *Activity) UnmarshalJSON(data []byte) error { as.ItemTyperFunc = JSONGetItemByType a.Parent.UnmarshalJSON(data) a.Actor = as.JSONGetItem(data, "actor") a.Object = as.JSONGetItem(data, "object") return nil } func loadActorWithInboxObject(a as.Item, o as.Item) as.Item { typ := a.GetType() switch typ { case as.ApplicationType: var app Application app, _ = a.(Application) var inbox *as.OrderedCollection if app.Inbox == nil { inbox = InboxNew() } else { inbox = app.Inbox.(*as.OrderedCollection) } inbox.Append(o) app.Inbox = inbox return app case as.GroupType: var grp Group grp, _ = a.(Group) var inbox *as.OrderedCollection if grp.Inbox == nil { inbox = InboxNew() } else { inbox = grp.Inbox.(*as.OrderedCollection) } inbox.Append(o) grp.Inbox = inbox return grp case as.OrganizationType: var org Organization org, _ = a.(Organization) var inbox *as.OrderedCollection if org.Inbox == nil { inbox = InboxNew() } else { inbox = org.Inbox.(*as.OrderedCollection) } inbox.Append(o) org.Inbox = inbox return org case as.PersonType: var pers Person pers, _ = a.(Person) var inbox *as.OrderedCollection if pers.Inbox == nil { inbox = InboxNew() } else { inbox = pers.Inbox.(*as.OrderedCollection) } inbox.Append(o) pers.Inbox = inbox return pers case as.ServiceType: var serv Service serv, _ = a.(Service) var inbox *as.OrderedCollection if serv.Inbox == nil { inbox = InboxNew() } else { inbox = serv.Inbox.(*as.OrderedCollection) } inbox.Append(o) serv.Inbox = inbox return serv default: o, _ := a.(as.Object) return Object{Parent: o} } }
-
-
activity_test.go (new)
-
@@ -0,0 +1,600 @@package activitypub import ( as "github.com/go-ap/activitystreams" "testing" ) func TestActivityNew(t *testing.T) { var testValue = as.ObjectID("test") var testType as.ActivityVocabularyType = "Accept" a := ActivityNew(testValue, testType, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != testType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, testType) } g := ActivityNew(testValue, "", nil) if g.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", g.ID, testValue) } if g.Type != as.ActivityType { t.Errorf("Activity Type '%v' different than expected '%v'", g.Type, as.ActivityType) } } func TestIntransitiveActivityNew(t *testing.T) { var testValue = as.ObjectID("test") var testType as.ActivityVocabularyType = "Arrive" a := IntransitiveActivityNew(testValue, testType) if a.ID != testValue { t.Errorf("IntransitiveActivity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != testType { t.Errorf("IntransitiveActivity Type '%v' different than expected '%v'", a.Type, testType) } g := IntransitiveActivityNew(testValue, "") if g.ID != testValue { t.Errorf("IntransitiveActivity Id '%v' different than expected '%v'", g.ID, testValue) } if g.Type != as.IntransitiveActivityType { t.Errorf("IntransitiveActivity Type '%v' different than expected '%v'", g.Type, as.IntransitiveActivityType) } } func TestAcceptNew(t *testing.T) { var testValue = as.ObjectID("test") a := AcceptNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.AcceptType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.AcceptType) } } func TestAddNew(t *testing.T) { var testValue = as.ObjectID("test") a := AddNew(testValue, nil, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.AddType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.AddType) } } func TestAnnounceNew(t *testing.T) { var testValue = as.ObjectID("test") a := AnnounceNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.AnnounceType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.AnnounceType) } } func TestArriveNew(t *testing.T) { var testValue = as.ObjectID("test") a := ArriveNew(testValue) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.ArriveType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.ArriveType) } } func TestBlockNew(t *testing.T) { var testValue = as.ObjectID("test") a := BlockNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.BlockType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.BlockType) } } func TestCreateNew(t *testing.T) { var testValue = as.ObjectID("test") a := CreateNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.CreateType) } } func TestDeleteNew(t *testing.T) { var testValue = as.ObjectID("test") a := DeleteNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.DeleteType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.DeleteType) } } func TestDislikeNew(t *testing.T) { var testValue = as.ObjectID("test") a := DislikeNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.DislikeType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.DislikeType) } } func TestFlagNew(t *testing.T) { var testValue = as.ObjectID("test") a := FlagNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.FlagType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.FlagType) } } func TestFollowNew(t *testing.T) { var testValue = as.ObjectID("test") a := FollowNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.FollowType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.FollowType) } } func TestIgnoreNew(t *testing.T) { var testValue = as.ObjectID("test") a := IgnoreNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.IgnoreType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.IgnoreType) } } func TestInviteNew(t *testing.T) { var testValue = as.ObjectID("test") a := InviteNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.InviteType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.InviteType) } } func TestJoinNew(t *testing.T) { var testValue = as.ObjectID("test") a := JoinNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.JoinType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.JoinType) } } func TestLeaveNew(t *testing.T) { var testValue = as.ObjectID("test") a := LeaveNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.LeaveType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.LeaveType) } } func TestLikeNew(t *testing.T) { var testValue = as.ObjectID("test") a := LikeNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.LikeType) } } func TestListenNew(t *testing.T) { var testValue = as.ObjectID("test") a := ListenNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.ListenType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.ListenType) } } func TestMoveNew(t *testing.T) { var testValue = as.ObjectID("test") a := MoveNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.MoveType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.MoveType) } } func TestOfferNew(t *testing.T) { var testValue = as.ObjectID("test") a := OfferNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.OfferType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.OfferType) } } func TestQuestionNew(t *testing.T) { var testValue = as.ObjectID("test") a := QuestionNew(testValue) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.QuestionType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.QuestionType) } } func TestRejectNew(t *testing.T) { var testValue = as.ObjectID("test") a := RejectNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.RejectType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.RejectType) } } func TestReadNew(t *testing.T) { var testValue = as.ObjectID("test") a := ReadNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.ReadType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.ReadType) } } func TestRemoveNew(t *testing.T) { var testValue = as.ObjectID("test") a := RemoveNew(testValue, nil, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.RemoveType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.RemoveType) } } func TestTentativeRejectNew(t *testing.T) { var testValue = as.ObjectID("test") a := TentativeRejectNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.TentativeRejectType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.TentativeRejectType) } } func TestTentativeAcceptNew(t *testing.T) { var testValue = as.ObjectID("test") a := TentativeAcceptNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.TentativeAcceptType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.TentativeAcceptType) } } func TestTravelNew(t *testing.T) { var testValue = as.ObjectID("test") a := TravelNew(testValue) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.TravelType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.TravelType) } } func TestUndoNew(t *testing.T) { var testValue = as.ObjectID("test") a := UndoNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.UndoType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.UndoType) } } func TestUpdateNew(t *testing.T) { var testValue = as.ObjectID("test") a := UpdateNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.UpdateType) } } func TestViewNew(t *testing.T) { var testValue = as.ObjectID("test") a := ViewNew(testValue, nil) if a.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue) } if a.Type != as.ViewType { t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, as.ViewType) } } func TestActivity_UnmarshalJSON(t *testing.T) { a := Activity{} dataEmpty := []byte("{}") a.UnmarshalJSON(dataEmpty) if a.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", a, a.ID) } if a.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", a, a.Type) } if a.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", a, a.AttributedTo) } if len(a.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", a, a.Name) } if len(a.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", a, a.Summary) } if len(a.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", a, a.Content) } if a.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", a, a.URL) } if !a.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", a, a.Published) } if !a.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", a, a.StartTime) } if !a.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", a, a.Updated) } } func TestCreate_UnmarshalJSON(t *testing.T) { c := Create{} dataEmpty := []byte("{}") c.UnmarshalJSON(dataEmpty) if c.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", c, c.ID) } if c.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", c, c.Type) } if c.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", c, c.AttributedTo) } if len(c.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", c, c.Name) } if len(c.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", c, c.Summary) } if len(c.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", c, c.Content) } if c.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", c, c.URL) } if !c.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", c, c.Published) } if !c.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", c, c.StartTime) } if !c.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", c, c.Updated) } } func TestDislike_UnmarshalJSON(t *testing.T) { d := Dislike{} dataEmpty := []byte("{}") d.UnmarshalJSON(dataEmpty) if d.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", d, d.ID) } if d.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", d, d.Type) } if d.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", d, d.AttributedTo) } if len(d.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", d, d.Name) } if len(d.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", d, d.Summary) } if len(d.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", d, d.Content) } if d.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", d, d.URL) } if !d.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", d, d.Published) } if !d.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", d, d.StartTime) } if !d.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", d, d.Updated) } } func TestLike_UnmarshalJSON(t *testing.T) { l := Like{} dataEmpty := []byte("{}") l.UnmarshalJSON(dataEmpty) if l.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", l, l.ID) } if l.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", l, l.Type) } if l.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", l, l.AttributedTo) } if len(l.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", l, l.Name) } if len(l.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", l, l.Summary) } if len(l.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", l, l.Content) } if l.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", l, l.URL) } if !l.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", l, l.Published) } if !l.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", l, l.StartTime) } if !l.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", l, l.Updated) } } func TestUpdate_UnmarshalJSON(t *testing.T) { u := Update{} dataEmpty := []byte("{}") u.UnmarshalJSON(dataEmpty) if u.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", u, u.ID) } if u.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", u, u.Type) } if u.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", u, u.AttributedTo) } if len(u.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", u, u.Name) } if len(u.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", u, u.Summary) } if len(u.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", u, u.Content) } if u.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", u, u.URL) } if !u.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", u, u.Published) } if !u.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", u, u.StartTime) } if !u.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", u, u.Updated) } }
-
-
actor.go (deleted)
-
@@ -1,13 +0,0 @@package activitypub import as "github.com/go-ap/activitystreams" // Actor is the ActivityPub version of an Activity Streams vocabulary Actor type Actor struct { as.Actor Inbox InboxStream Outbox OutboxStream Followers FollowersCollection Following FollowingCollection }
-
-
actors.go (new)
-
@@ -0,0 +1,400 @@package activitypub import as "github.com/go-ap/activitystreams" // Endpoints a json object which maps additional (typically server/domain-wide) // endpoints which may be useful either for this actor or someone referencing this actor. // This mapping may be nested inside the actor document as the value or may be a link to // a JSON-LD document with these properties. type Endpoints struct { // UploadMedia Upload endpoint URI for this user for binary data. UploadMedia as.Item `jsonld:"uploadMedia,omitempty"` // OauthAuthorizationEndpoint Endpoint URI so this actor's clients may access remote ActivityStreams objects which require authentication // to access. To use this endpoint, the client posts an x-www-form-urlencoded id parameter with the value being // the id of the requested ActivityStreams object. OauthAuthorizationEndpoint as.Item `jsonld:"oauthAuthorizationEndpoint,omitempty"` // OauthTokenEndpoint If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a browser-authenticated user may obtain a new authorization grant. OauthTokenEndpoint as.Item `jsonld:"oauthTokenEndpoint,omitempty"` // ProvideClientKey If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a client may acquire an access token. ProvideClientKey as.Item `jsonld:"provideClientKey,omitempty"` // SignClientKey If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which browser-authenticated users may authorize a client's public // key for client to server interactions. SignClientKey as.Item `jsonld:"signClientKey,omitempty"` // SharedInbox If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which a client key may be signed by the actor's key for a time window to // act on behalf of the actor in interacting with foreign servers. SharedInbox as.Item `jsonld:"sharedInbox,omitempty"` } // Actor is generally one of the ActivityStreams Actor Types, but they don't have to be. // For example, a Profile object might be used as an actor, or a type from an ActivityStreams extension. // 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 // 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"` // An [ActivityStreams] OrderedCollection comprised of all the messages produced by the actor; // see 5.1 Outbox. Outbox as.Item `jsonld:"outbox,omitempty"` // A link to an [ActivityStreams] collection of the actors that this actor is following; // see 5.4 Following Collection Following as.Item `jsonld:"following,omitempty"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. Followers as.Item `jsonld:"followers,omitempty"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. Liked as.Item `jsonld:"liked,omitempty"` // A short username which may be used to refer to the actor, with no uniqueness guarantees. PreferredUsername as.NaturalLanguageValue `jsonld:"preferredUsername,omitempty,collapsible"` // A json object which maps additional (typically server/domain-wide) endpoints which may be useful either // for this actor or someone referencing this actor. // This mapping may be nested inside the actor document as the value or may be a link // to a JSON-LD document with these properties. Endpoints Endpoints `jsonld:"endpoints,omitempty"` // A list of supplementary Collections which may be of interest. Streams []as.ItemCollection `jsonld:"streams,omitempty"` } type ( // Application describes a software application. Application Actor // Group represents a formal or informal collective of Actors. Group Actor // Organization represents an organization. Organization Actor // Person represents an individual person. Person Actor // Service represents a service of any kind. Service Actor ) // ActorNew initializes an Actor type actor func ActorNew(id as.ObjectID, typ as.ActivityVocabularyType) *Actor { if !as.ValidActorType(typ) { typ = as.ActorType } a := Actor{Parent: as.Object {ID: id, Type: typ}} a.Name = as.NaturalLanguageValueNew() a.Content = as.NaturalLanguageValueNew() a.Summary = as.NaturalLanguageValueNew() in := as.OrderedCollectionNew(as.ObjectID("test-inbox")) out := as.OrderedCollectionNew(as.ObjectID("test-outbox")) liked := as.OrderedCollectionNew(as.ObjectID("test-liked")) a.Inbox = in a.Outbox = out a.Liked = liked a.PreferredUsername = as.NaturalLanguageValueNew() return &a } // ApplicationNew initializes an Application type actor func ApplicationNew(id as.ObjectID) *Application { a := ActorNew(id, as.ApplicationType) o := Application(*a) return &o } // GroupNew initializes a Group type actor func GroupNew(id as.ObjectID) *Group { a := ActorNew(id, as.GroupType) o := Group(*a) return &o } // OrganizationNew initializes an Organization type actor func OrganizationNew(id as.ObjectID) *Organization { a := ActorNew(id, as.OrganizationType) o := Organization(*a) return &o } // PersonNew initializes a Person type actor func PersonNew(id as.ObjectID) *Person { a := ActorNew(id, as.PersonType) o := Person(*a) return &o } // ServiceNew initializes a Service type actor func ServiceNew(id as.ObjectID) *Service { a := ActorNew(id, as.ServiceType) o := Service(*a) return &o } // IsLink validates if current Actor is a Link func (a Actor) IsLink() bool { return a.Type == as.LinkType || as.ValidLinkType(a.Type) } // IsObject validates if current Actor is an Object func (a Actor) IsObject() bool { return a.Type == as.ObjectType || as.ValidObjectType(a.Type) } // GetID returns the ObjectID corresponding to the Actor object func (a Actor) GetID() *as.ObjectID { return &a.ID } // GetLink returns the IRI corresponding to the Actor object func (a Actor) GetLink() as.IRI { return as.IRI(a.ID) } // GetType returns the type corresponding to the Actor object func (a Actor) GetType() as.ActivityVocabularyType { return a.Type } // IsLink validates if current Application is a Link func (a Application) IsLink() bool { return a.Type == as.LinkType || as.ValidLinkType(a.Type) } // IsObject validates if current Application is an Object func (a Application) IsObject() bool { return a.Type == as.ObjectType || as.ValidObjectType(a.Type) } // GetID returns the ObjectID corresponding to the Application object func (a Application) GetID() *as.ObjectID { return a.GetActor().GetID() } // GetLink returns the IRI corresponding to the Application object func (a Application) GetLink() as.IRI { return as.IRI(a.ID) } // GetType returns the type corresponding to the Application object func (a Application) GetType() as.ActivityVocabularyType { return a.Type } // IsLink validates if current Group is a Link func (g Group) IsLink() bool { return g.Type == as.LinkType || as.ValidLinkType(g.Type) } // IsObject validates if current Group is an Object func (g Group) IsObject() bool { return g.Type == as.ObjectType || as.ValidObjectType(g.Type) } // GetID returns the ObjectID corresponding to the Group object func (g Group) GetID() *as.ObjectID { return g.GetActor().GetID() } // GetLink returns the IRI corresponding to the Group object func (g Group) GetLink() as.IRI { return as.IRI(g.ID) } // GetType returns the type corresponding to the Group object func (g Group) GetType() as.ActivityVocabularyType { return g.Type } // IsLink validates if current Organization is a Link func (o Organization) IsLink() bool { return o.Type == as.LinkType || as.ValidLinkType(o.Type) } // IsObject validates if current Organization is an Object func (o Organization) IsObject() bool { return o.Type == as.ObjectType || as.ValidObjectType(o.Type) } // GetID returns the ObjectID corresponding to the Organization object func (o Organization) GetID() *as.ObjectID { return o.GetActor().GetID() } // GetLink returns the IRI corresponding to the Organization object func (o Organization) GetLink() as.IRI { return as.IRI(o.ID) } // GetType returns the type corresponding to the Organization object func (o Organization) GetType() as.ActivityVocabularyType { return o.Type } // IsLink validates if current Service is a Link func (s Service) IsLink() bool { return s.Type == as.LinkType || as.ValidLinkType(s.Type) } // IsObject validates if current Service is an Object func (s Service) IsObject() bool { return s.Type == as.ObjectType || as.ValidObjectType(s.Type) } // GetID returns the ObjectID corresponding to the Service object func (s Service) GetID() *as.ObjectID { return s.GetActor().GetID() } // GetLink returns the IRI corresponding to the Service object func (s Service) GetLink() as.IRI { return as.IRI(s.ID) } // GetType returns the type corresponding to the Service object func (s Service) GetType() as.ActivityVocabularyType { return s.Type } // IsLink validates if current Person is a Link func (p Person) IsLink() bool { return p.Type == as.LinkType || as.ValidLinkType(p.Type) } // IsObject validates if current Person is an Object func (p Person) IsObject() bool { return p.Type == as.ObjectType || as.ValidObjectType(p.Type) } // GetID returns the ObjectID corresponding to the Person object func (p Person) GetID() *as.ObjectID { return p.GetActor().GetID() } // GetType returns the object type for the current Person object func (p Person) GetType() as.ActivityVocabularyType { return p.Type } // GetLink returns the IRI corresponding to the Person object func (p Person) GetLink() as.IRI { return as.IRI(p.ID) } // UnmarshalJSON func (a *Actor) UnmarshalJSON(data []byte) error { a.Parent.UnmarshalJSON(data) a.PreferredUsername = as.JSONGetNaturalLanguageField(data, "preferredUsername") out := as.JSONGetItem(data, "outbox") if out != nil { a.Outbox = out } inb := as.JSONGetItem(data, "inbox") if inb != nil { a.Inbox = inb } followers := as.JSONGetItem(data, "followers") if followers != nil { a.Followers = followers } following := as.JSONGetItem(data, "following") if following != nil { a.Following = following } liked := as.JSONGetItem(data, "liked") if liked != nil { a.Liked = liked } //streams := as.JSONGetItems(data, "streams") //if streams != nil { // a.Streams = streams //} // @todo(marius) : Add as.JSONGetIEndPoints return nil } func (p *Person) UnmarshalJSON(data []byte) error { a := p.GetActor() err := a.UnmarshalJSON(data) *p = Person(a) return err } // UnmarshalJSON func (a *Application) UnmarshalJSON(data []byte) error { act := a.GetActor() err := act.UnmarshalJSON(data) *a = Application(act) return err } // UnmarshalJSON func (g *Group) UnmarshalJSON(data []byte) error { a := g.GetActor() err := a.UnmarshalJSON(data) *g = Group(a) return err } // UnmarshalJSON func (o *Organization) UnmarshalJSON(data []byte) error { a := o.GetActor() err := a.UnmarshalJSON(data) *o = Organization(a) return err } // UnmarshalJSON func (s *Service) UnmarshalJSON(data []byte) error { a := s.GetActor() err := a.UnmarshalJSON(data) *s = Service(a) return err } // GetActor returns the underlying Actor type func (a Actor) GetActor() Actor { return a } // GetActor returns the underlying Actor type func (a Application) GetActor() Actor { return Actor(a) } // GetActor returns the underlying Actor type func (g Group) GetActor() Actor { return Actor(g) } // GetActor returns the underlying Actor type func (o Organization) GetActor() Actor { return Actor(o) } // GetActor returns the underlying Actor type func (p Person) GetActor() Actor { return Actor(p) } // GetActor returns the underlying Actor type func (s Service) GetActor() Actor { return Actor(s) }
-
-
actors_test.go (new)
-
@@ -0,0 +1,334 @@package activitypub import ( "reflect" "testing" as "github.com/go-ap/activitystreams" ) func TestActorNew(t *testing.T) { var testValue = as.ObjectID("test") var testType = as.ApplicationType o := ActorNew(testValue, testType) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != testType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, testType) } n := ActorNew(testValue, "") if n.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", n.ID, testValue) } if n.Type != as.ActorType { t.Errorf("APObject Type '%v' different than expected '%v'", n.Type, as.ActorType) } } func TestPersonNew(t *testing.T) { var testValue = as.ObjectID("test") o := PersonNew(testValue) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != as.PersonType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, as.PersonType) } } func TestApplicationNew(t *testing.T) { var testValue = as.ObjectID("test") o := ApplicationNew(testValue) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != as.ApplicationType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, as.ApplicationType) } } func TestGroupNew(t *testing.T) { var testValue = as.ObjectID("test") o := GroupNew(testValue) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != as.GroupType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type,as. GroupType) } } func TestOrganizationNew(t *testing.T) { var testValue = as.ObjectID("test") o := OrganizationNew(testValue) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != as.OrganizationType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, as.OrganizationType) } } func TestServiceNew(t *testing.T) { var testValue = as.ObjectID("test") o := ServiceNew(testValue) if o.ID != testValue { t.Errorf("APObject Id '%v' different than expected '%v'", o.ID, testValue) } if o.Type != as.ServiceType { t.Errorf("APObject Type '%v' different than expected '%v'", o.Type, as.ServiceType) } } func TestActor_IsLink(t *testing.T) { m := ActorNew("test", as.ActorType) if m.IsLink() { t.Errorf("%#v should not be a valid Link", m.Type) } } func TestActor_IsObject(t *testing.T) { m := ActorNew("test", as.ActorType) if !m.IsObject() { t.Errorf("%#v should be a valid object", m.Type) } } func TestActor_Object(t *testing.T) { m := ActorNew("test", as.ActorType) if reflect.DeepEqual(as.ObjectID(""), m.GetID()) { t.Errorf("%#v should not be an empty activity pub object", m.GetID()) } } func TestActor_Type(t *testing.T) { m := ActorNew("test", as.ActorType) if m.GetType() != as.ActorType { t.Errorf("%#v should be an empty Link object", m.GetType()) } } func TestPerson_IsLink(t *testing.T) { m := PersonNew("test") if m.IsLink() { t.Errorf("%T should not be a valid Link", m) } } func TestPerson_IsObject(t *testing.T) { m := PersonNew("test") if !m.IsObject() { t.Errorf("%T should be a valid object", m) } } func TestActor_UnmarshalJSON(t *testing.T) { } func TestActor_GetActor(t *testing.T) { } func TestActor_GetID(t *testing.T) { } func TestActor_GetLink(t *testing.T) { } func TestActor_GetType(t *testing.T) { } func TestApplication_GetActor(t *testing.T) { } func TestApplication_GetID(t *testing.T) { } func TestApplication_GetLink(t *testing.T) { } func TestApplication_GetType(t *testing.T) { } func TestApplication_IsLink(t *testing.T) { } func TestApplication_IsObject(t *testing.T) { } func TestGroup_GetActor(t *testing.T) { } func TestGroup_GetID(t *testing.T) { } func TestGroup_GetLink(t *testing.T) { } func TestGroup_GetType(t *testing.T) { } func TestGroup_IsLink(t *testing.T) { } func TestGroup_IsObject(t *testing.T) { } func TestOrganization_GetActor(t *testing.T) { } func TestOrganization_GetID(t *testing.T) { } func TestOrganization_GetLink(t *testing.T) { } func TestOrganization_GetType(t *testing.T) { } func TestOrganization_IsLink(t *testing.T) { } func TestOrganization_IsObject(t *testing.T) { } func TestPerson_GetActor(t *testing.T) { } func TestPerson_GetID(t *testing.T) { } func TestPerson_GetLink(t *testing.T) { } func TestPerson_GetType(t *testing.T) { } func validateEmptyPerson(p Person, t *testing.T) { if p.ID != "" { t.Errorf("Unmarshalled object %T should have empty ID, received %q", p, p.ID) } if p.Type != "" { t.Errorf("Unmarshalled object %T should have empty Type, received %q", p, p.Type) } if p.AttributedTo != nil { t.Errorf("Unmarshalled object %T should have empty AttributedTo, received %q", p, p.AttributedTo) } if len(p.Name) != 0 { t.Errorf("Unmarshalled object %T should have empty Name, received %q", p, p.Name) } if len(p.Summary) != 0 { t.Errorf("Unmarshalled object %T should have empty Summary, received %q", p, p.Summary) } if len(p.Content) != 0 { t.Errorf("Unmarshalled object %T should have empty Content, received %q", p, p.Content) } if p.URL != nil { t.Errorf("Unmarshalled object %T should have empty URL, received %v", p, p.URL) } if !p.Published.IsZero() { t.Errorf("Unmarshalled object %T should have empty Published, received %q", p, p.Published) } if !p.StartTime.IsZero() { t.Errorf("Unmarshalled object %T should have empty StartTime, received %q", p, p.StartTime) } if !p.Updated.IsZero() { t.Errorf("Unmarshalled object %T should have empty Updated, received %q", p, p.Updated) } } func TestPerson_UnmarshalJSON(t *testing.T) { p := Person{} dataEmpty := []byte("{}") p.UnmarshalJSON(dataEmpty) validateEmptyPerson(p, t) } func TestApplication_UnmarshalJSON(t *testing.T) { a := Application{} dataEmpty := []byte("{}") a.UnmarshalJSON(dataEmpty) validateEmptyPerson(Person(a), t) } func TestGroup_UnmarshalJSON(t *testing.T) { g := Group{} dataEmpty := []byte("{}") g.UnmarshalJSON(dataEmpty) validateEmptyPerson(Person(g), t) } func TestOrganization_UnmarshalJSON(t *testing.T) { o := Organization{} dataEmpty := []byte("{}") o.UnmarshalJSON(dataEmpty) validateEmptyPerson(Person(o), t) } func TestService_UnmarshalJSON(t *testing.T) { s := Service{} dataEmpty := []byte("{}") s.UnmarshalJSON(dataEmpty) validateEmptyPerson(Person(s), t) } func TestService_GetActor(t *testing.T) { } func TestService_GetID(t *testing.T) { } func TestService_GetLink(t *testing.T) { } func TestService_GetType(t *testing.T) { } func TestService_IsLink(t *testing.T) { } func TestService_IsObject(t *testing.T) { }
-
-
create_activity.go (deleted)
-
@@ -1,115 +0,0 @@package activitypub import ( "time" as "github.com/go-ap/activitystreams" ) // CreateActivity is the type for a create activity message type CreateActivity struct { Activity *as.Create `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } func loadActorWithInboxObject(a as.Item, o as.Item) as.Item { typ := a.GetType() switch typ { case as.ApplicationType: var app as.Application app, _ = a.(as.Application) var inbox *as.OrderedCollection if app.Inbox == nil { inbox = InboxNew() } else { inbox = app.Inbox.(*as.OrderedCollection) } inbox.Append(o) app.Inbox = inbox return app case as.GroupType: var grp as.Group grp, _ = a.(as.Group) var inbox *as.OrderedCollection if grp.Inbox == nil { inbox = InboxNew() } else { inbox = grp.Inbox.(*as.OrderedCollection) } inbox.Append(o) grp.Inbox = inbox return grp case as.OrganizationType: var org as.Organization org, _ = a.(as.Organization) var inbox *as.OrderedCollection if org.Inbox == nil { inbox = InboxNew() } else { inbox = org.Inbox.(*as.OrderedCollection) } inbox.Append(o) org.Inbox = inbox return org case as.PersonType: var pers as.Person pers, _ = a.(as.Person) var inbox *as.OrderedCollection if pers.Inbox == nil { inbox = InboxNew() } else { inbox = pers.Inbox.(*as.OrderedCollection) } inbox.Append(o) pers.Inbox = inbox return pers case as.ServiceType: var serv as.Service serv, _ = a.(as.Service) var inbox *as.OrderedCollection if serv.Inbox == nil { inbox = InboxNew() } else { inbox = serv.Inbox.(*as.OrderedCollection) } inbox.Append(o) serv.Inbox = inbox return serv default: actor, _ := a.(as.Actor) var inbox *as.OrderedCollection if actor.Inbox == nil { inbox = InboxNew() } else { inbox = actor.Inbox.(*as.OrderedCollection) } inbox.Append(o) actor.Inbox = inbox return actor } } // CreateActivityNew initializes a new CreateActivity message func CreateActivityNew(id as.ObjectID, a as.Item, o as.Item) CreateActivity { act := as.CreateNew(id, o) if a != nil { if a.IsObject() { act.Actor = loadActorWithInboxObject(a, o) } if a.IsLink() { act.Actor = a } } act.RecipientsDeduplication() c := CreateActivity{ Activity: act, Published: time.Now(), } return c }
-
-
create_activity_test.go (deleted)
-
@@ -1,261 +0,0 @@package activitypub import ( "reflect" "testing" "time" as "github.com/go-ap/activitystreams" ) func TestCreateActivityNew(t *testing.T) { var testValue = as.ObjectID("test") var now time.Time c := CreateActivityNew(testValue, nil, nil) now = time.Now() if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.CreateType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now) } } func TestCreateActivityNewWithApplication(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := CreateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(as.Application).Inbox.(*as.OrderedCollection) if in.TotalItems != 1 { 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()) } } func TestCreateActivityNewWithGroup(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := CreateActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != g.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), g.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), g.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestCreateActivityNewWithOrganization(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" o := as.OrganizationNew("users") c1 := CreateActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != o.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), o.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), o.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestCreateActivityNewWithPerson(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := CreateActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != b.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), b.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), b.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestCreateActivityNewWithService(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := CreateActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != s.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), s.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), s.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestCreateActivityNewWithActor(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := CreateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.CreateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.CreateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, *a) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
-
-
@@ -2,6 +2,6 @@ module github.com/go-ap/activitypubrequire ( github.com/buger/jsonparser v0.0.0-20181023193515-52c6e1462ebd github.com/go-ap/activitystreams v0.0.0-20190124104215-6a208fd55a29 github.com/go-ap/jsonld v0.0.0-20190124103729-2f041c2116c4 github.com/go-ap/activitystreams v0.0.0-20190130195050-f4e240055d94 github.com/go-ap/jsonld v0.0.0-20190128144341-adfba0c0ddf2 )
-
-
like_activity.go (deleted)
-
@@ -1,145 +0,0 @@package activitypub import ( as "github.com/go-ap/activitystreams" "time" ) // LikeActivity is the type for a create activity message type LikeActivity struct { Activity *as.Like `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } // DislikeActivity is the type for a create activity message type DislikeActivity struct { Activity *as.Dislike `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } func loadActorWithLikedObject(a as.Item, o as.Item) as.Item { typ := a.GetType() switch typ { case as.ApplicationType: var app as.Application app, _ = a.(as.Application) var liked *as.OrderedCollection if app.Liked == nil { liked = LikedNew() } else { liked = app.Liked.(*as.OrderedCollection) } liked.Append(o) app.Liked = liked return app case as.GroupType: var grp as.Group grp, _ = a.(as.Group) var liked *as.OrderedCollection if grp.Liked == nil { liked = LikedNew() } else { liked = grp.Liked.(*as.OrderedCollection) } liked.Append(o) grp.Liked = liked return grp case as.OrganizationType: var org as.Organization org, _ = a.(as.Organization) var liked *as.OrderedCollection if org.Liked == nil { liked = LikedNew() } else { liked = org.Liked.(*as.OrderedCollection) } liked.Append(o) org.Liked = liked return org case as.PersonType: var pers as.Person pers, _ = a.(as.Person) var liked *as.OrderedCollection if pers.Liked == nil { liked = LikedNew() } else { liked = pers.Liked.(*as.OrderedCollection) } liked.Append(o) pers.Liked = liked return pers case as.ServiceType: var serv as.Service serv, _ = a.(as.Service) var liked *as.OrderedCollection if serv.Liked == nil { liked = LikedNew() } else { liked = serv.Liked.(*as.OrderedCollection) } liked.Append(o) serv.Liked = liked return serv default: actor, _ := a.(as.Actor) var liked *as.OrderedCollection if actor.Liked == nil { liked = LikedNew() } else { liked = actor.Liked.(*as.OrderedCollection) } liked.Append(o) actor.Liked = liked return actor } } // LikeActivityNew initializes a new LikeActivity message func LikeActivityNew(id as.ObjectID, a as.Item, o as.Item) LikeActivity { act := as.LikeNew(id, o) if a != nil { if a.IsObject() { act.Actor = loadActorWithLikedObject(a, o) } if a.IsLink() { act.Actor = a } } act.RecipientsDeduplication() c := LikeActivity{ Activity: act, Published: time.Now(), } return c } // DislikeActivityNew initializes a new LikeActivity message func DislikeActivityNew(id as.ObjectID, a as.Item, o as.Item) DislikeActivity { act := as.DislikeNew(id, o) if a != nil { if a.IsObject() { act.Actor = loadActorWithLikedObject(a, o) } if a.IsLink() { act.Actor = a } } act.RecipientsDeduplication() d := DislikeActivity{ Activity: act, Published: time.Now(), } return d }
-
-
like_activity_test.go (deleted)
-
@@ -1,259 +0,0 @@package activitypub import ( as "github.com/go-ap/activitystreams" "reflect" "testing" "time" ) func TestLikeActivityNew(t *testing.T) { var testValue = as.ObjectID("test") var now time.Time c := LikeActivityNew(testValue, nil, nil) now = time.Now() if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.LikeType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now) } } func TestLikeActivityNewWithApplication(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := LikeActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(as.Application).Liked.(*as.OrderedCollection) if in.TotalItems != 1 { t.Errorf("Liked collection of %q should have exactly one element, not %d", *c1.Activity.Actor.GetID(), in.TotalItems) } if len(in.OrderedItems) != 1 { t.Errorf("Liked 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("Liked 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 Liked is does not match %q", *n.GetID()) } } func TestLikeActivityNewWithGroup(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := LikeActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != g.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), g.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), g.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestLikeActivityNewWithOrganization(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) o := as.OrganizationNew("users") c1 := LikeActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != o.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), o.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), o.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestLikeActivityNewWithPerson(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := LikeActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != b.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), b.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), b.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestLikeActivityNewWithService(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := LikeActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != s.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), s.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), s.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestLikeActivityNewWithActor(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := LikeActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.LikeType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.LikeType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, *a) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-
-
-
@@ -14,9 +14,11 @@ type Source struct {MediaType as.MimeType `jsonld:"mediaType"` } type Parent = as.Object // Object type Object struct { as.Object 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.
-
@@ -45,7 +47,7 @@ func (s *Source) UnmarshalJSON(data []byte) error {// UnmarshalJSON func (o *Object) UnmarshalJSON(data []byte) error { o.Object.UnmarshalJSON(data) o.Parent.UnmarshalJSON(data) o.Source = GetAPSource(data) return nil }
-
-
-
@@ -133,14 +133,14 @@ func deepValueEqual(t canErrorFunc, v1, v2 reflect.Value, visited map[visit]boolif v1.IsNil() { isNil1 = "is" } else { isNil1 = "isn't" isNil1 = "is not" } if v2.IsNil() { isNil2 = "is" } else { isNil2 = "isn't" isNil2 = "is not" } t("Interface %q %s nil and %q %s nil", v1.Type().Name(), isNil1, v2.Type().Name(), isNil2) t("Interface '%s' %s nil and '%s' %s nil", v1.Type().Name(), isNil1, v2.Type().Name(), isNil2) return false } return deepValueEqual(t, v1.Elem(), v2.Elem(), visited, depth+1)
-
@@ -152,7 +152,7 @@ func deepValueEqual(t canErrorFunc, v1, v2 reflect.Value, visited map[visit]boolcase reflect.Struct: for i, n := 0, v1.NumField(); i < n; i++ { if !deepValueEqual(t, v1.Field(i), v2.Field(i), visited, depth+1) { t("Struct fields at pos %d %q:%q and %q:%q are not deeply equal", i, v1.Type().Field(i).Name, v1.Field(i).Type().Name(), v2.Type().Field(i).Name, v2.Field(i).Type().Name()) t("Struct fields at pos %d %s[%s] and %s[%s] are not deeply equal", i, v1.Type().Field(i).Name, v1.Field(i).Type().Name(), v2.Type().Field(i).Name, v2.Field(i).Type().Name()) if v1.Field(i).CanAddr() && v2.Field(i).CanAddr() { t(" Values: %#v - %#v", v1.Field(i).Interface(), v2.Field(i).Interface()) }
-
@@ -196,122 +196,95 @@ var zLoc, _ = time.LoadLocation("UTC")var allTests = tests{ "empty": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{}, }, "link_simple": testPair{ expected: true, blank: &a.Link{}, result: &a.Link{ Type: a.LinkType, Href: a.IRI("http://example.org/abc"), HrefLang: a.LangRef("en"), MediaType: a.MimeType("text/html"), Name: a.NaturalLanguageValue{{ a.NilLangRef, "An example link", }}, }, blank: &ap.Object{}, result: &ap.Object{}, }, "object_with_url": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ URL: a.IRI("http://littr.git/api/accounts/system"), }, blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{URL: a.IRI("http://littr.git/api/accounts/system")}}, }, "object_with_url_collection": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ URL: a.ItemCollection{ a.IRI("http://littr.git/api/accounts/system"), a.IRI("http://littr.git/~system"), blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{ URL: a.ItemCollection{ a.IRI("http://littr.git/api/accounts/system"), a.IRI("http://littr.git/~system"), }, }, }, }, "object_simple": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Name: a.NaturalLanguageValue{{ a.NilLangRef, "A Simple, non-specific object", }}, }, }, "object_with_tags": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Name: a.NaturalLanguageValue{{ a.NilLangRef, "A Simple, non-specific object", }}, Tag: a.ItemCollection{ &a.Object{ Name: a.NaturalLanguageValue{{ a.NilLangRef, "#my_tag", }}, ID: a.ObjectID("http://example.com/tag/my_tag"), }, &a.Mention{ Name: a.NaturalLanguageValue{{ a.NilLangRef, "@ana", }}, Type: a.MentionType, ID: a.ObjectID("http://example.com/users/ana"), }, blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Name: a.NaturalLanguageValue{{ a.NilLangRef, "A Simple, non-specific object", }}, }, }, }, "object_with_replies": testPair{ "object_with_tags": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Replies: &a.Collection{ Parent: a.Parent{ ID: a.ObjectID("http://www.test.example/object/1/replies"), Type: a.CollectionType, }, TotalItems: 1, Items: a.ItemCollection{ blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Name: a.NaturalLanguageValue{{ a.NilLangRef, "A Simple, non-specific object", }}, Tag: a.ItemCollection{ &a.Object{ ID: a.ObjectID("http://www.test.example/object/1/replies/2"), Type: a.ArticleType, Name: a.NaturalLanguageValue{{a.NilLangRef, "Example title"}}, Name: a.NaturalLanguageValue{{ a.NilLangRef, "#my_tag", }}, ID: a.ObjectID("http://example.com/tag/my_tag"), }, &a.Mention{ Name: a.NaturalLanguageValue{{ a.NilLangRef, "@ana", }}, Type: a.MentionType, ID: a.ObjectID("http://example.com/users/ana"), }, }, }, }, }, "activity_simple": testPair{ "object_with_replies": testPair{ expected: true, blank: &a.Activity{}, result: &a.Activity{ Parent: a.Parent{ Type: a.ActivityType, Summary: a.NaturalLanguageValue{{a.NilLangRef, "Sally did something to a note"}}, }, Actor: &a.Person{ Parent: a.Parent{ Type: a.PersonType, Name: a.NaturalLanguageValue{{a.NilLangRef, "Sally"}}, blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), Replies: &a.Collection{ Parent: a.Parent{ 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.NilLangRef, "Example title"}}, }, }, }, }, Object: &a.Object{ Type: a.NoteType, Name: a.NaturalLanguageValue{{a.NilLangRef, "A Note"}}, }, }, }, "person_with_outbox": testPair{ expected: true, blank: &a.Person{}, result: &a.Person{ blank: &ap.Person{}, result: &ap.Person{ Parent: a.Parent{ ID: a.ObjectID("http://example.com/accounts/ana"), Type: a.PersonType,
-
@@ -414,41 +387,43 @@ var allTests = tests{}, }, }, "like_activity_with_iri_actor": { //"like_activity_with_iri_actor": { // expected: true, // blank: &ap.Like{}, // result: &ap.Like{ // Activity: a.Activity{ // Parent: a.Parent{ // Type: a.LikeType, // Published: time.Date(2018, time.September, 6, 15, 15, 9, 0, zLoc), // }, // Actor: a.IRI("https://littr.git/api/accounts/24d4b96f"), // Object: &a.Article{ // ID: a.ObjectID("https://littr.git/api/accounts/ana/liked/7ca154ff"), // Type: a.ArticleType, // }, // }, // }, //}, "object_with_audience": testPair{ expected: true, blank: &ap.LikeActivity{}, result: &ap.LikeActivity{ Activity: &a.Like{ Parent: a.Parent{ Type: a.LikeType, blank: &ap.Object{}, result: &ap.Object{ Parent: a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), To: a.ItemCollection{ a.IRI("https://www.w3.org/ns/activitystreams#Public"), }, Actor: a.IRI("https://littr.git/api/accounts/24d4b96f"), Object: &a.Object{ ID: a.ObjectID("https://littr.git/api/accounts/ana/liked/7ca154ff"), Type: a.ArticleType, Bto: a.ItemCollection{ a.IRI("http://example.com/sharedInbox"), }, CC: a.ItemCollection{ a.IRI("https://example.com/actors/ana"), a.IRI("https://example.com/actors/bob"), }, BCC: a.ItemCollection{ a.IRI("https://darkside.cookie/actors/darthvader"), }, }, Published: time.Date(2018, time.September, 6, 15, 15, 9, 0, zLoc), }, }, "object_with_audience": testPair{ expected: true, blank: &a.Object{}, result: &a.Object{ Type: a.ObjectType, ID: a.ObjectID("http://www.test.example/object/1"), To: a.ItemCollection{ a.IRI("https://www.w3.org/ns/activitystreams#Public"), }, Bto: a.ItemCollection{ a.IRI("http://example.com/sharedInbox"), }, CC: a.ItemCollection{ a.IRI("https://example.com/actors/ana"), a.IRI("https://example.com/actors/bob"), }, BCC: a.ItemCollection{ a.IRI("https://darkside.cookie/actors/darthvader"), }, }, },
-
-
unmarshall.go (new)
-
@@ -0,0 +1,167 @@package activitypub import ( as "github.com/go-ap/activitystreams" ) func JSONGetItemByType(typ as.ActivityVocabularyType) (as.Item, error) { var ret as.Item var err error switch typ { case as.ObjectType: o := Object{} o.Type = typ ret = &o case as.ActivityType: ret = &Activity{} o := ret.(*Activity) o.Type = typ case as.IntransitiveActivityType: ret = &IntransitiveActivity{} o := ret.(*IntransitiveActivity) o.Type = typ case as.ActorType: ret = &Object{} o := ret.(*Object) o.Type = typ case as.ApplicationType: ret = &Application{} o := ret.(*Application) o.Type = typ case as.GroupType: ret = &Group{} o := ret.(*Group) o.Type = typ case as.OrganizationType: ret = &Organization{} o := ret.(*Organization) o.Type = typ case as.PersonType: ret = &Person{} o := ret.(*Person) o.Type = typ case as.ServiceType: ret = &Service{} o := ret.(*Service) o.Type = typ case as.AcceptType: ret = &Accept{} o := ret.(*Accept) o.Type = typ case as.AddType: ret = &Add{} o := ret.(*Add) o.Type = typ case as.AnnounceType: ret = &Announce{} o := ret.(*Announce) o.Type = typ case as.ArriveType: ret = &Arrive{} o := ret.(*Arrive) o.Type = typ case as.BlockType: ret = &Block{} o := ret.(*Block) o.Type = typ case as.CreateType: ret = &Create{} o := ret.(*Create) o.Type = typ case as.DeleteType: ret = &Delete{} o := ret.(*Delete) o.Type = typ case as.DislikeType: ret = &Dislike{} o := ret.(*Dislike) o.Type = typ case as.FlagType: ret = &Flag{} o := ret.(*Flag) o.Type = typ case as.FollowType: ret = &Follow{} o := ret.(*Follow) o.Type = typ case as.IgnoreType: ret = &Ignore{} o := ret.(*Ignore) o.Type = typ case as.InviteType: ret = &Invite{} o := ret.(*Invite) o.Type = typ case as.JoinType: ret = &Join{} o := ret.(*Join) o.Type = typ case as.LeaveType: ret = &Leave{} o := ret.(*Leave) o.Type = typ case as.LikeType: ret = &Like{} o := ret.(*Like) o.Type = typ case as.ListenType: ret = &Listen{} o := ret.(*Listen) o.Type = typ case as.MoveType: ret = &Move{} o := ret.(*Move) o.Type = typ case as.OfferType: ret = &Offer{} o := ret.(*Offer) o.Type = typ case as.QuestionType: ret = &Question{} o := ret.(*Question) o.Type = typ case as.RejectType: ret = &Reject{} o := ret.(*Reject) o.Type = typ case as.ReadType: ret = &Read{} o := ret.(*Read) o.Type = typ case as.RemoveType: ret = &Remove{} o := ret.(*Remove) o.Type = typ case as.TentativeRejectType: ret = &TentativeReject{} o := ret.(*TentativeReject) o.Type = typ case as.TentativeAcceptType: ret = &TentativeAccept{} o := ret.(*TentativeAccept) o.Type = typ case as.TravelType: ret = &Travel{} o := ret.(*Travel) o.Type = typ case as.UndoType: ret = &Undo{} o := ret.(*Undo) o.Type = typ case as.UpdateType: ret = &Update{} o := ret.(*Update) o.Type = typ case as.ViewType: ret = &View{} o := ret.(*View) o.Type = typ case "": // when no type is available use a plain Object ret = &Object{} default: return as.JSONGetItemByType(typ) } return ret, err }
-
-
update_activity.go (deleted)
-
@@ -1,37 +0,0 @@package activitypub import ( as "github.com/go-ap/activitystreams" "time" ) // UpdateActivity is the type for a Update activity message type UpdateActivity struct { Activity *as.Update `jsonld:"activity"` Published time.Time `jsonld:"published"` To as.ItemCollection `jsonld:"to,omitempty,collapsible"` CC as.ItemCollection `jsonld:"cc,omitempty,collapsible"` } // UpdateActivityNew initializes a new UpdateActivity message func UpdateActivityNew(id as.ObjectID, a as.Item, o as.Item) UpdateActivity { act := as.UpdateNew(id, o) if a != nil { if a.IsObject() { act.Actor = loadActorWithInboxObject(a, o) } if a.IsLink() { act.Actor = a } } act.RecipientsDeduplication() c := UpdateActivity{ Activity: act, Published: time.Now(), } return c }
-
-
update_activity_test.go (deleted)
-
@@ -1,260 +0,0 @@package activitypub import ( as "github.com/go-ap/activitystreams" "reflect" "testing" "time" ) func TestUpdateActivityNew(t *testing.T) { var testValue = as.ObjectID("test") var now time.Time c := UpdateActivityNew(testValue, nil, nil) now = time.Now() if c.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c.Activity.ID, testValue) } if c.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c.Activity.Type, as.UpdateType) } if now.Sub(c.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c.Published, now) } } func TestUpdateActivityNewWithApplication(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ApplicationNew("some::app::") c1 := UpdateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*a)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } in := c1.Activity.Actor.(as.Application).Inbox.(*as.OrderedCollection) if in.TotalItems != 1 { 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()) } } func TestUpdateActivityNewWithGroup(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" g := as.GroupNew("users") c1 := UpdateActivityNew(testValue, *g, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != g.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), g.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), g.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), g.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *g) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*g)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestUpdateActivityNewWithOrganization(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" o := as.OrganizationNew("users") c1 := UpdateActivityNew(testValue, *o, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != o.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), o.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), o.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), o.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *o) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*o)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestUpdateActivityNewWithPerson(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" b := as.PersonNew("bob") c1 := UpdateActivityNew(testValue, *b, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != b.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), b.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), b.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), b.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *b) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*b)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestUpdateActivityNewWithService(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" s := as.ServiceNew("::zz::") c1 := UpdateActivityNew(testValue, *s, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != s.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), s.ID) } if !reflect.DeepEqual(c1.Activity.Actor.GetID(), s.GetID()) { t.Errorf("Actor %#v different than expected %#v", c1.Activity.Actor.GetID(), s.GetID()) } if !reflect.DeepEqual(c1.Activity.Actor, *s) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, as.Actor(*s)) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } } func TestUpdateActivityNewWithActor(t *testing.T) { testValue := as.ObjectID("my:note") n := as.ObjectNew(as.NoteType) n.ID = "my:note" a := as.ActorNew("bob", as.ActorType) c1 := UpdateActivityNew(testValue, *a, n) now := time.Now() if c1.Activity.ID != testValue { t.Errorf("Activity Id '%v' different than expected '%v'", c1.Activity.ID, testValue) } if c1.Activity.Type != as.UpdateType { t.Errorf("Activity Type '%v' different than expected '%v'", c1.Activity.Type, as.UpdateType) } if now.Sub(c1.Published).Round(time.Millisecond) != 0 { t.Errorf("Published time '%v' different than expected '%v'", c1.Published, now) } if *c1.Activity.Actor.GetID() != a.ID { t.Errorf("Actor ID %q different than expected %q", *c1.Activity.Actor.GetID(), a.ID) } 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, *a) { t.Errorf("Actor %#v\n\n different than expected\n\n %#v", c1.Activity.Actor, *a) } if *c1.Activity.Object.GetID() != n.ID { t.Errorf("GetID %q different than expected %q", *c1.Activity.Object.GetID(), n.ID) } if !reflect.DeepEqual(c1.Activity.Object.GetID(), n.GetID()) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object.GetID(), n.GetID()) } if !reflect.DeepEqual(c1.Activity.Object, n) { t.Errorf("GetID %#v different than expected %#v", c1.Activity.Object, n) } }
-