subhub/activitypub/vocab.go

108 lines
2.8 KiB
Go

package activitypub
import (
"fmt"
"net/url"
"time"
)
const context = "https://ww.w3.org/ns/activitystreams"
type (
BaseObject struct {
Context []interface{} `json:"@context,omitempty"`
Type string `json:"type"`
ID string `json:"id"`
}
PublicKey struct {
ID string `json:"id"`
Owner string `json:"owner"`
PublicKeyPEM string `json:"publicKeyPem"`
privateKey []byte
}
Endpoints struct {
SharedInbox string `json:"sharedInbox,omitempty"`
}
Image struct {
Type string `json:"type"`
MediaType string `json:"mediaType"`
URL string `json:"url"`
}
// Object is the primary base type for the Activity Streams vocabulary.
Object struct {
BaseObject
Published time.Time `json:"published"`
Summary *string `json:"summary,omitempty"`
InReplyTo *string `json:"inReplyTo"`
URL string `json:"url"`
AttributedTo string `json:"attributedTo"`
To []string `json:"to"`
CC []string `json:"cc,omitempty"`
Name string `json:"name,omitempty"`
Content string `json:"content"`
ContentMap map[string]string `json:"contentMap,omitempty"`
//Tag []Tag `json:"tag"`
// Extensions
CommentsEnabled bool `json:"commentsEnabled"`
}
Group struct {
Context string `json:"@context"`
ID *url.URL `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}
)
type OrderedCollection struct {
BaseObject
TotalItems int `json:"totalItems"`
First string `json:"first"`
Last string `json:"last,omitempty"`
}
func NewOrderedCollection(accountRoot, collType string, items int) *OrderedCollection {
oc := OrderedCollection{
BaseObject: BaseObject{
Context: []interface{}{
Namespace,
},
ID: accountRoot + "/" + collType,
Type: "OrderedCollection",
},
First: accountRoot + "/" + collType + "?page=1",
TotalItems: items,
}
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 []interface{} `json:"orderedItems,omitempty"`
}
func NewOrderedCollectionPage(accountRoot, collType string, items, page int) *OrderedCollectionPage {
ocp := OrderedCollectionPage{
BaseObject: BaseObject{
Context: []interface{}{
Namespace,
},
ID: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page),
Type: "OrderedCollectionPage",
},
TotalItems: items,
PartOf: accountRoot + "/" + collType,
Next: fmt.Sprintf("%s/%s?page=%d", accountRoot, collType, page+1),
}
return &ocp
}