diff --git a/actor.go b/actor.go index 7ac539d..114523b 100644 --- a/actor.go +++ b/actor.go @@ -27,6 +27,14 @@ import ( // Actor represents a local actor we can act on // behalf of. + +//type Attachment struct { +// Type string +// Name string +// Href string +// Rel string +//} + type Actor struct { Name, summary, actorType, iri string followersIRI string @@ -41,15 +49,18 @@ type Actor struct { publicKeyID string OnFollow func(map[string]interface{}) OnReceiveContent func(map[string]interface{}) + attachment []interface {} } // ActorToSave is a stripped down actor representation // with exported properties in order for json to be // able to marshal it. // see https://stackoverflow.com/questions/26327391/json-marshalstruct-returns + type ActorToSave struct { Name, Summary, ActorType, IRI, PublicKey, PrivateKey string - Followers, Following, Rejected, Requested map[string]interface{} + Followers, Following, Rejected, Requested map[string]interface{} + Attachment []interface {} } // MakeActor creates and returns a new local actor we can act @@ -59,6 +70,7 @@ func MakeActor(name, summary, actorType string) (Actor, error) { following := make(map[string]interface{}) rejected := make(map[string]interface{}) requested := make(map[string]interface{}) + var attachment []interface{} followersIRI := baseURL + name + "/followers" publicKeyID := baseURL + name + "#main-key" iri := baseURL + name @@ -79,6 +91,7 @@ func MakeActor(name, summary, actorType string) (Actor, error) { requested: requested, followersIRI: followersIRI, publicKeyID: publicKeyID, + attachment: attachment, } // set auto accept by default (this could be a configuration value) @@ -199,6 +212,7 @@ func LoadActor(name string) (Actor, error) { privateKeyPem: jsonData["PrivateKey"].(string), followersIRI: baseURL + name + "/followers", publicKeyID: baseURL + name + "#main-key", + attachment: jsonData["Attachment"].([]interface{}), } actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) } @@ -265,6 +279,7 @@ func (a *Actor) save() error { Requested: a.requested, PublicKey: a.publicKeyPem, PrivateKey: a.privateKeyPem, + Attachment: a.attachment, } actorJSON, err := json.MarshalIndent(actorToSave, "", "\t") @@ -296,6 +311,7 @@ func (a *Actor) whoAmI() string { self["outbox"] = baseURL + a.Name + "/outbox" self["followers"] = baseURL + a.Name + "/peers/followers" self["following"] = baseURL + a.Name + "/peers/following" + self["attachment"] = a.attachment self["publicKey"] = map[string]string{ "id": baseURL + a.Name + "#main-key", "owner": baseURL + a.Name, @@ -326,7 +342,7 @@ func (a *Actor) newID() (hash string, url string) { // CreateNote posts an activityPub note to our followers // -func (a *Actor) CreateNote(content, inReplyTo string) { +func (a *Actor) CreateNote(content, inReplyTo string,attachment []interface{}) { // for now I will just write this to the outbox hash, id := a.newItemID() create := make(map[string]interface{}) @@ -342,6 +358,9 @@ func (a *Actor) CreateNote(content, inReplyTo string) { if inReplyTo != "" { note["inReplyTo"] = inReplyTo } + if inReplyTo != nil { + note["attachment"] = attachment + } note["id"] = id note["published"] = time.Now().Format(time.RFC3339) note["url"] = create["id"]