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"
|
2024-04-11 16:19:18 -04:00
|
|
|
ToPublic = "https://www.w3.org/ns/activitystreams#Public"
|
2018-06-24 21:06:26 -04:00
|
|
|
)
|
|
|
|
|
|
2025-10-23 14:15:03 -04:00
|
|
|
var (
|
|
|
|
|
Extensions = map[string]string{}
|
|
|
|
|
|
|
|
|
|
apMonetizationContext = map[string]interface{}{
|
|
|
|
|
"monetization": "https://interledger.org/ns#monetization",
|
|
|
|
|
}
|
|
|
|
|
)
|
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
|
2023-10-02 21:30:47 -04:00
|
|
|
Actor string `json:"actor"`
|
|
|
|
|
Published time.Time `json:"published,omitempty"`
|
|
|
|
|
Updated *time.Time `json:"updated,omitempty"`
|
|
|
|
|
To []string `json:"to,omitempty"`
|
|
|
|
|
CC []string `json:"cc,omitempty"`
|
|
|
|
|
Object *Object `json:"object"`
|
2018-06-24 21:06:26 -04:00
|
|
|
}
|
|
|
|
|
|
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,
|
2019-04-04 16:57:46 -04:00
|
|
|
Extensions,
|
2018-06-25 13:37:46 -04:00
|
|
|
},
|
2018-08-08 16:04:01 -04:00
|
|
|
ID: o.ID,
|
2018-06-24 21:06:26 -04:00
|
|
|
Type: "Create",
|
|
|
|
|
},
|
2018-08-12 22:34:31 -04:00
|
|
|
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,
|
2019-04-04 16:57:46 -04:00
|
|
|
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 21:30:47 -04:00
|
|
|
}
|
|
|
|
|
if o.Updated != nil && !o.Updated.IsZero() {
|
|
|
|
|
a.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
|
2022-05-11 18:06:23 -04:00
|
|
|
Published time.Time `json:"published,omitempty"`
|
2023-10-02 21:30:47 -04:00
|
|
|
Updated *time.Time `json:"updated,omitempty"`
|
2018-06-25 13:35:47 -04:00
|
|
|
Summary *string `json:"summary,omitempty"`
|
2022-05-11 18:06:23 -04:00
|
|
|
InReplyTo *string `json:"inReplyTo,omitempty"`
|
2018-06-24 21:06:26 -04:00
|
|
|
URL string `json:"url"`
|
2022-05-11 18:06:23 -04:00
|
|
|
AttributedTo string `json:"attributedTo,omitempty"`
|
|
|
|
|
To []string `json:"to,omitempty"`
|
2018-06-25 13:35:47 -04:00
|
|
|
CC []string `json:"cc,omitempty"`
|
2018-07-24 20:09:31 +02:00
|
|
|
Name string `json:"name,omitempty"`
|
2022-05-11 18:06:23 -04:00
|
|
|
Content string `json:"content,omitempty"`
|
2018-06-25 13:35:47 -04:00
|
|
|
ContentMap map[string]string `json:"contentMap,omitempty"`
|
2022-05-11 18:06:23 -04:00
|
|
|
Tag []Tag `json:"tag,omitempty"`
|
2021-03-24 15:33:34 -04:00
|
|
|
Attachment []Attachment `json:"attachment,omitempty"`
|
2025-05-07 17:52:29 -04:00
|
|
|
Preview *Object `json:"preview,omitempty"`
|
2019-04-04 16:29:00 -04:00
|
|
|
|
2022-05-11 18:06:23 -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{
|
2024-04-11 16:19:18 -04:00
|
|
|
ToPublic,
|
2018-06-24 21:06:26 -04:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
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{
|
2024-04-11 16:19:18 -04:00
|
|
|
ToPublic,
|
2018-07-24 20:09:31 +02:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return &o
|
|
|
|
|
}
|
2022-05-11 18:06:23 -04:00
|
|
|
|
|
|
|
|
// NewPersonObject creates a basic Person object.
|
|
|
|
|
func NewPersonObject() *Object {
|
|
|
|
|
o := Object{
|
|
|
|
|
BaseObject: BaseObject{
|
|
|
|
|
Type: "Person",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return &o
|
|
|
|
|
}
|