Files
web-core-fr-gp/activitystreams/activity.go
T

176 lines
4.5 KiB
Go
Raw Normal View History

2018-08-04 14:38:40 +02:00
// Package activitystreams provides all the basic ActivityStreams
// implementation needed for Write.as.
2018-06-24 21:06:26 -04:00
package activitystreams
import (
"time"
)
const (
2018-08-04 14:23:14 +02:00
Namespace = "https://www.w3.org/ns/activitystreams"
toPublic = "https://www.w3.org/ns/activitystreams#Public"
2018-06-24 21:06:26 -04:00
)
2019-11-11 21:56:08 +09:00
var Extensions = map[string]string{}
2019-04-04 16:29:00 -04:00
2018-08-04 14:38:40 +02:00
// Activity describes actions that have either already occurred, are in the
// process of occurring, or may occur in the future.
2018-06-24 21:06:26 -04:00
type Activity struct {
BaseObject
Actor string `json:"actor"`
Published time.Time `json:"published,omitempty"`
2023-10-02 19:27:51 -04:00
Updated time.Time `json:"updated,omitempty"`
To []string `json:"to,omitempty"`
CC []string `json:"cc,omitempty"`
2018-06-24 21:06:26 -04:00
Object *Object `json:"object"`
}
2018-08-17 20:42:39 -04:00
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"`
}
2018-08-04 14:38:40 +02:00
// NewCreateActivity builds a basic Create activity that includes the given
// Object and the Object's AttributedTo property as the Actor.
2018-06-24 21:06:26 -04:00
func NewCreateActivity(o *Object) *Activity {
a := Activity{
BaseObject: BaseObject{
2018-08-03 00:21:06 +02:00
Context: []interface{}{
2018-08-04 14:23:14 +02:00
Namespace,
Extensions,
},
2018-08-08 16:04:01 -04:00
ID: o.ID,
2018-06-24 21:06:26 -04:00
Type: "Create",
},
Actor: o.AttributedTo,
Object: o,
Published: o.Published,
2018-06-24 21:06:26 -04:00
}
return &a
}
2018-08-16 20:31:25 -04:00
// 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,
2018-08-16 20:31:25 -04:00
},
ID: o.ID,
Type: "Update",
},
Actor: o.AttributedTo,
Object: o,
Published: o.Published,
2023-10-02 19:27:51 -04:00
Updated: o.Updated,
2018-08-16 20:31:25 -04:00
}
return &a
}
2018-08-08 15:29:42 -04:00
// 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
}
2018-08-17 20:42:39 -04:00
// 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
}
2018-08-04 14:38:40 +02:00
// Object is the primary base type for the Activity Streams vocabulary.
2018-06-24 21:06:26 -04:00
type Object struct {
BaseObject
Published time.Time `json:"published,omitempty"`
2023-10-02 19:27:51 -04:00
Updated time.Time `json:"updated,omitempty"`
Summary *string `json:"summary,omitempty"`
InReplyTo *string `json:"inReplyTo,omitempty"`
2018-06-24 21:06:26 -04:00
URL string `json:"url"`
AttributedTo string `json:"attributedTo,omitempty"`
To []string `json:"to,omitempty"`
CC []string `json:"cc,omitempty"`
2018-07-24 20:09:31 +02:00
Name string `json:"name,omitempty"`
Content string `json:"content,omitempty"`
ContentMap map[string]string `json:"contentMap,omitempty"`
Tag []Tag `json:"tag,omitempty"`
Attachment []Attachment `json:"attachment,omitempty"`
2019-04-04 16:29:00 -04:00
// Person
Inbox string `json:"inbox,omitempty"`
Outbox string `json:"outbox,omitempty"`
Following string `json:"following,omitempty"`
Followers string `json:"followers,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
Icon *Image `json:"icon,omitempty"`
PublicKey *PublicKey `json:"publicKey,omitempty"`
Endpoints *Endpoints `json:"endpoints,omitempty"`
2019-04-04 16:29:00 -04:00
// Extensions
2019-11-11 21:56:08 +09:00
// NOTE: add extensions here
2018-06-24 21:06:26 -04:00
}
2018-08-04 14:38:40 +02:00
// NewNoteObject creates a basic Note object that includes the public
// namespace in IRIs it's addressed to.
2018-06-24 21:06:26 -04:00
func NewNoteObject() *Object {
o := Object{
BaseObject: BaseObject{
Type: "Note",
},
To: []string{
toPublic,
},
}
return &o
}
2018-07-24 20:09:31 +02:00
2018-08-04 14:38:40 +02:00
// NewArticleObject creates a basic Article object that includes the public
// namespace in IRIs it's addressed to.
2018-07-24 20:09:31 +02:00
func NewArticleObject() *Object {
o := Object{
BaseObject: BaseObject{
Type: "Article",
},
To: []string{
toPublic,
},
}
return &o
}
// NewPersonObject creates a basic Person object.
func NewPersonObject() *Object {
o := Object{
BaseObject: BaseObject{
Type: "Person",
},
}
return &o
}