Browse Source

Add basic Note and Activity types

master
Matt Baer 5 years ago
parent
commit
d16108618b
2 changed files with 85 additions and 0 deletions
  1. +58
    -0
      activitystreams/activity.go
  2. +27
    -0
      activitystreams/data.go

+ 58
- 0
activitystreams/activity.go View File

@@ -0,0 +1,58 @@
package activitystreams

import (
"time"
)

const (
toPublic = "https://www.w3.org/ns/activitystreams#Public"
)

type Activity struct {
BaseObject
Actor string `json:"actor"`
Published time.Time `json:"published"`
To []string `json:"to"`
CC []string `json:"cc"`
Object *Object `json:"object"`
}

func NewCreateActivity(o *Object) *Activity {
a := Activity{
BaseObject: BaseObject{
ID: o.ID + "/activity",
Type: "Create",
},
Actor: o.AttributedTo,
Published: o.Published,
To: o.To,
CC: o.CC,
Object: o,
}
return &a
}

type Object struct {
BaseObject
Published time.Time `json:"published"`
Summary *string `json:"summary"`
InReplyTo *string `json:"inReplyTo"`
URL string `json:"url"`
AttributedTo string `json:"attributedTo"`
To []string `json:"to"`
CC []string `json:"cc"`
Content string `json:"content"`
ContentMap map[string]string `json:"contentMap"`
}

func NewNoteObject() *Object {
o := Object{
BaseObject: BaseObject{
Type: "Note",
},
To: []string{
toPublic,
},
}
return &o
}

+ 27
- 0
activitystreams/data.go View File

@@ -1,5 +1,7 @@
package activitystreams

import "fmt"

type (
BaseObject struct {
Context []string `json:"@context"`
@@ -41,3 +43,28 @@ func NewOrderedCollection(accountRoot string, items int) *OrderedCollection {
}
return &oc
}

type OrderedCollectionPage struct {
BaseObject
TotalItems int `json:"totalItems"`
PartOf string `json:"partOf"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
OrderedItems []Activity `json:"orderedItems"`
}

func NewOrderedCollectionPage(accountRoot string, items, page int) *OrderedCollectionPage {
ocp := OrderedCollectionPage{
BaseObject: BaseObject{
Context: []string{
"https://www.w3.org/ns/activitystreams",
},
ID: fmt.Sprintf("%s/outbox?page=%d", accountRoot, page),
Type: "OrderedCollectionPage",
},
TotalItems: items,
PartOf: accountRoot + "/outbox",
Next: fmt.Sprintf("%s/outbox?page=%d", accountRoot, page+1),
}
return &ocp
}

Loading…
Cancel
Save