100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package goap
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitlab.com/mstarongitlab/goutils/sliceutils"
|
|
)
|
|
|
|
type ActorData struct {
|
|
Next BaseApChain
|
|
Actor string
|
|
}
|
|
|
|
func (actor *ActorData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return actor.Next, true
|
|
}
|
|
|
|
func (actor *ActorData) MarshalToMap() map[string]any {
|
|
prev := actor.Next.MarshalToMap()
|
|
prev[KEY_ACTIVITYSTREAMS_ACTOR] = strToId(actor.Actor)
|
|
return prev
|
|
}
|
|
|
|
type ObjectData struct {
|
|
Next BaseApChain
|
|
ObjectUrl string
|
|
}
|
|
|
|
func (object *ObjectData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return object.Next, true
|
|
}
|
|
|
|
func (object *ObjectData) MarshalToMap() map[string]any {
|
|
return appendWithKey(
|
|
object.Next.MarshalToMap(),
|
|
KEY_ACTIVITYSTREAMS_OBJECT,
|
|
strToId(object.ObjectUrl),
|
|
)
|
|
}
|
|
|
|
type CCData struct {
|
|
Next BaseApChain
|
|
Targets []string
|
|
}
|
|
|
|
func (cc *CCData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return cc.Next, true
|
|
}
|
|
|
|
func (cc *CCData) MarshalToMap() map[string]any {
|
|
return appendWithKey(cc.Next.MarshalToMap(), KEY_ACTIVITYSTREAMS_CC, strsToIds(cc.Targets))
|
|
}
|
|
|
|
type ToData struct {
|
|
Next BaseApChain
|
|
Targets []string
|
|
}
|
|
|
|
func (cc *ToData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return cc.Next, true
|
|
}
|
|
|
|
func (cc *ToData) MarshalToMap() map[string]any {
|
|
return appendWithKey(cc.Next.MarshalToMap(), KEY_ACTIVITYSTREAMS_TO, strsToIds(cc.Targets))
|
|
}
|
|
|
|
type PublishedData struct {
|
|
Next BaseApChain
|
|
Timestamp time.Time
|
|
}
|
|
|
|
func (publisheddata *PublishedData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return publisheddata.Next, true
|
|
}
|
|
|
|
// Convert the chain to a map
|
|
// Should include the rest of the chain (extend the map the underlying object returns)
|
|
func (publisheddata *PublishedData) MarshalToMap() map[string]any {
|
|
m := publisheddata.Next.MarshalToMap()
|
|
m[KEY_ACTIVITYSTREAMS_PUBLISHED] = timeToXmlTime(publisheddata.Timestamp)
|
|
return m
|
|
}
|
|
|
|
type TagData struct {
|
|
Next BaseApChain
|
|
Tags []Tag
|
|
}
|
|
|
|
func (tagdata *TagData) GetSelfOrBase() (BaseApChain, bool) {
|
|
return tagdata.Next, true
|
|
}
|
|
|
|
func (tagdata *TagData) MarshalToMap() map[string]any {
|
|
m := tagdata.Next.MarshalToMap()
|
|
m[KEY_ACTIVITYSTREAMS_TAG] = sliceutils.Map(
|
|
tagdata.Tags,
|
|
func(t Tag) map[string]any { return t.Marshal() },
|
|
)
|
|
return m
|
|
}
|