146 lines
3.1 KiB
Go
146 lines
3.1 KiB
Go
package activitypub
|
|
|
|
import "time"
|
|
|
|
const (
|
|
Namespace = "https://www.w3.org/ns/activitystreams"
|
|
toPublic = "https://www.w3.org/ns/activitystreams#Public"
|
|
)
|
|
|
|
var Extensions = map[string]string{
|
|
"sc": "http://schema.org#",
|
|
"commentsEnabled": "sc:Boolean",
|
|
}
|
|
|
|
// Activity describes actions that have either already occurred, are in the
|
|
// process of occurring, or may occur in the future.
|
|
type Activity struct {
|
|
BaseObject
|
|
Actor string `json:"actor"`
|
|
Published time.Time `json:"published,omitempty"`
|
|
To []string `json:"to,omitempty"`
|
|
CC []string `json:"cc,omitempty"`
|
|
Object *Object `json:"object"`
|
|
}
|
|
|
|
type FollowActivity struct {
|
|
BaseObject
|
|
Actor string `json:"actor"`
|
|
Published time.Time `json:"published,omitempty"`
|
|
To []string `json:"to,omitempty"`
|
|
CC []string `json:"cc,omitempty"`
|
|
Object string `json:"object"`
|
|
}
|
|
|
|
// NewCreateActivity builds a basic Create activity that includes the given
|
|
// Object and the Object's AttributedTo property as the Actor.
|
|
func NewCreateActivity(o *Object) *Activity {
|
|
a := Activity{
|
|
BaseObject: BaseObject{
|
|
Context: []interface{}{
|
|
Namespace,
|
|
Extensions,
|
|
},
|
|
ID: o.ID,
|
|
Type: "Create",
|
|
},
|
|
Actor: o.AttributedTo,
|
|
Object: o,
|
|
Published: o.Published,
|
|
}
|
|
return &a
|
|
}
|
|
|
|
// NewUpdateActivity builds a basic Update activity that includes the given
|
|
// Object and the Object's AttributedTo property as the Actor.
|
|
func NewUpdateActivity(o *Object) *Activity {
|
|
a := Activity{
|
|
BaseObject: BaseObject{
|
|
Context: []interface{}{
|
|
Namespace,
|
|
Extensions,
|
|
},
|
|
ID: o.ID,
|
|
Type: "Update",
|
|
},
|
|
Actor: o.AttributedTo,
|
|
Object: o,
|
|
Published: o.Published,
|
|
}
|
|
return &a
|
|
}
|
|
|
|
// NewDeleteActivity builds a basic Delete activity that includes the given
|
|
// Object and the Object's AttributedTo property as the Actor.
|
|
func NewDeleteActivity(o *Object) *Activity {
|
|
a := Activity{
|
|
BaseObject: BaseObject{
|
|
Context: []interface{}{
|
|
Namespace,
|
|
},
|
|
ID: o.ID,
|
|
Type: "Delete",
|
|
},
|
|
Actor: o.AttributedTo,
|
|
Object: o,
|
|
}
|
|
return &a
|
|
}
|
|
|
|
// NewFollowActivity builds a basic Follow activity.
|
|
func NewFollowActivity(actorIRI, followeeIRI string) *FollowActivity {
|
|
a := FollowActivity{
|
|
BaseObject: BaseObject{
|
|
Context: []interface{}{
|
|
Namespace,
|
|
},
|
|
Type: "Follow",
|
|
},
|
|
Actor: actorIRI,
|
|
Object: followeeIRI,
|
|
}
|
|
return &a
|
|
}
|
|
|
|
// NewNoteObject creates a basic Note object that includes the public
|
|
// namespace in IRIs it's addressed to.
|
|
func NewNoteObject() *Object {
|
|
o := Object{
|
|
BaseObject: BaseObject{
|
|
Type: "Note",
|
|
},
|
|
To: []string{
|
|
toPublic,
|
|
},
|
|
}
|
|
return &o
|
|
}
|
|
|
|
// NewArticleObject creates a basic Article object that includes the public
|
|
// namespace in IRIs it's addressed to.
|
|
func NewArticleObject() *Object {
|
|
o := Object{
|
|
BaseObject: BaseObject{
|
|
Type: "Article",
|
|
},
|
|
To: []string{
|
|
toPublic,
|
|
},
|
|
}
|
|
return &o
|
|
}
|
|
|
|
// NewAnounceObject creates a basic Anounce object that includes the public
|
|
// namespace in IRIs it's addressed to.
|
|
func NewAnounceObject() *Object {
|
|
o := Object{
|
|
BaseObject: BaseObject{
|
|
Type: "Anounce",
|
|
},
|
|
To: []string{
|
|
toPublic,
|
|
},
|
|
}
|
|
return &o
|
|
}
|