From 2498ecea51d8747f32e39556666a3d00113412fc Mon Sep 17 00:00:00 2001 From: mStar Date: Tue, 30 Jul 2024 17:16:33 +0200 Subject: [PATCH] More meow --- commonTypes.go | 10 +- constants.go | 42 +++-- examples/mk_note_create_dm.json | 99 ++++++++++ ...k_note_create_follower_only_with_ping.json | 86 +++++++++ go.mod | 2 +- go.sum | 4 +- nsActivitystreams.go | 173 +++++++++++++++--- variousTypes.go | 31 +--- 8 files changed, 376 insertions(+), 71 deletions(-) create mode 100644 examples/mk_note_create_dm.json create mode 100644 examples/mk_note_create_follower_only_with_ping.json diff --git a/commonTypes.go b/commonTypes.go index 7d93286..51dbaa3 100644 --- a/commonTypes.go +++ b/commonTypes.go @@ -10,22 +10,22 @@ package goap // // ] // ``` -type IdType struct { +type FullIdType struct { Next BaseApChain Id string } -func (idtype *IdType) GetSelfOrBase() (BaseApChain, bool) { +func (idtype *FullIdType) GetSelfOrBase() (BaseApChain, bool) { return idtype.Next, true } -func (idtype *IdType) MarshalToMapWithName(name string) map[string]any { +func (idtype *FullIdType) MarshalToMapWithName(name string) map[string]any { m := idtype.Next.MarshalToMap() m[name] = []map[string]any{{KEY_ID: idtype.Id}} return m } -func ParseIdTypeWithName(m map[string]any, b BaseApChain, name string) (*IdType, error) { +func ParseIdTypeWithName(m map[string]any, b BaseApChain, name string) (*FullIdType, error) { rawData1, ok := m[name] if !ok { return nil, NoRequiredFieldError{name} @@ -45,7 +45,7 @@ func ParseIdTypeWithName(m map[string]any, b BaseApChain, name string) (*IdType, if !ok { return nil, BadFieldValueError{name, rawData2, ""} } - return &IdType{ + return &FullIdType{ Next: b, Id: data2, }, nil diff --git a/constants.go b/constants.go index 0e8dca0..a10b348 100644 --- a/constants.go +++ b/constants.go @@ -9,56 +9,56 @@ const ( const ( KEY_MASTO_DEVICES = "http://joinmastodon.org/ns#devices" // No idea what this is, but Masto includes it KEY_MASTO_DISCOVERABLE = "http://joinmastodon.org/ns#discoverable" // iirc this is whether the object can be found by crawlers + KEY_MASTO_EMOJI = "http://joinmastodon.org/ns#Emoji" // Object is an emoji KEY_MASTO_FEATURED = "http://joinmastodon.org/ns#featured" // Users tagged? I think KEY_MASTO_FEATURED_TAGS = "http://joinmastodon.org/ns#featuredTags" // Hashtags included, I think KEY_MASTO_INDEXABLE = "http://joinmastodon.org/ns#indexable" // Is the object crawlable round 2 KEY_MASTO_MEMORIAL = "http://joinmastodon.org/ns#memorial" // Account dead and disabled? - KEY_MASTO_EMOJI = "http://joinmastodon.org/ns#Emoji" // Object is an emoji ) const ( KEY_W3_INBOX = "http://www.w3.org/ns/ldp#inbox" // Where to send activities to - KEY_W3_SECURITY_PUBLICKEY = "https://w3id.org/security#publicKey" // Public key of the account - KEY_W3_SECURITY_OWNER = "https://w3id.org/security#owner" // Owner of the public key - KEY_W3_SECURITY_PUBLICKEYPEM = "https://w3id.org/security#publicKeyPem" // Pem content of the key KEY_W3_SECURITY_KEY = "https://w3id.org/security#Key" // Object is a PublicKey + KEY_W3_SECURITY_OWNER = "https://w3id.org/security#owner" // Owner of the public key + KEY_W3_SECURITY_PUBLICKEY = "https://w3id.org/security#publicKey" // Public key of the account + KEY_W3_SECURITY_PUBLICKEYPEM = "https://w3id.org/security#publicKeyPem" // Pem content of the key KEY_W3_VCARD_ADRESS = "http://www.w3.org/2006/vcard/ns#Address" // Vcard address of an account KEY_W3_VCARD_BIRTHDAY = "http://www.w3.org/2006/vcard/ns#bday" // Vcard birthday of an account ) const ( + KEY_ACTIVITYSTREAMS_ACTOR = "https://www.w3.org/ns/activitystreams#actor" KEY_ACTIVITYSTREAMS_ALSOKNOWNAS = "https://www.w3.org/ns/activitystreams#alsoKnownAs" // Lists of usernames? KEY_ACTIVITYSTREAMS_ATTACHMENTS = "https://www.w3.org/ns/activitystreams#attachment" // Attached elements like emotes and hashtags - KEY_ACTIVITYSTREAMS_NAME = "https://www.w3.org/ns/activitystreams#name" // Name of the object + KEY_ACTIVITYSTREAMS_ATTRIBUTEDTO = "https://www.w3.org/ns/activitystreams#attributedTo" // Creator of object? + KEY_ACTIVITYSTREAMS_CC = "https://www.w3.org/ns/activitystreams#cc" // Urls also included in the object + KEY_ACTIVITYSTREAMS_CONTENT = "https://www.w3.org/ns/activitystreams#content" // (String) content of an object KEY_ACTIVITYSTREAMS_ENDPOINTS = "https://www.w3.org/ns/activitystreams#endpoints" // list of assocciated endpoints - KEY_ACTIVITYSTREAMS_SHAREDINBOX = "https://www.w3.org/ns/activitystreams#sharedInbox" // Link to the shared inbox of the server KEY_ACTIVITYSTREAMS_FOLLOWERS = "https://www.w3.org/ns/activitystreams#followers" // Who is following the account KEY_ACTIVITYSTREAMS_FOLLOWING = "https://www.w3.org/ns/activitystreams#following" // Who is this account following + KEY_ACTIVITYSTREAMS_HREF = "https://www.w3.org/ns/activitystreams#href" // Some url with id KEY_ACTIVITYSTREAMS_ICON = "https://www.w3.org/ns/activitystreams#icon" // User icon - KEY_ACTIVITYSTREAMS_MEDIATYPE = "https://www.w3.org/ns/activitystreams#mediaType" // What type of media is this? Example image/jpeg - KEY_ACTIVITYSTREAMS_URL = "https://www.w3.org/ns/activitystreams#url" // Some url KEY_ACTIVITYSTREAMS_IMAGE = "https://www.w3.org/ns/activitystreams#image" // Account banner - KEY_ACTIVITYSTREAMS_RESTRICTED_FOLLOW = "https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers" // Does the account manually approve follow requests + KEY_ACTIVITYSTREAMS_MEDIATYPE = "https://www.w3.org/ns/activitystreams#mediaType" // What type of media is this? Example image/jpeg + KEY_ACTIVITYSTREAMS_NAME = "https://www.w3.org/ns/activitystreams#name" // Name of the object KEY_ACTIVITYSTREAMS_OUTBOX = "https://www.w3.org/ns/activitystreams#outbox" // Link to the account's outbox + KEY_ACTIVITYSTREAMS_OBJECT = "https://www.w3.org/ns/activitystreams#object" // Object url and sometimes value KEY_ACTIVITYSTREAMS_PREFFEREDUSERNAME = "https://www.w3.org/ns/activitystreams#preferredUsername" // What the shown username is KEY_ACTIVITYSTREAMS_PUBLISHED = "https://www.w3.org/ns/activitystreams#published" // When an object was created - KEY_ACTIVITYSTREAMS_SUMMARY = "https://www.w3.org/ns/activitystreams#summary" // Summary of an account or the cw of a note - KEY_ACTIVITYSTREAMS_TAG = "https://www.w3.org/ns/activitystreams#tag" // A tag, usually hashtags included somewhere - KEY_ACTIVITYSTREAMS_CC = "https://www.w3.org/ns/activitystreams#cc" // Urls also included in the object - KEY_ACTIVITYSTREAMS_TO = "https://www.w3.org/ns/activitystreams#to" // Urls to send an activity to - KEY_ACTIVITYSTREAMS_OBJECT = "https://www.w3.org/ns/activitystreams#object" // Object url and sometimes value - KEY_ACTIVITYSTREAMS_HREF = "https://www.w3.org/ns/activitystreams#href" // Some url with id - KEY_ACTIVITYSTREAMS_ATTRIBUTEDTO = "https://www.w3.org/ns/activitystreams#attributedTo" // Creator of object? - KEY_ACTIVITYSTREAMS_CONTENT = "https://www.w3.org/ns/activitystreams#content" // (String) content of an object - KEY_ACTIVITYSTREAMS_REPLIES = "https://www.w3.org/ns/activitystreams#replies" // Object containing the replies. Should always be a Collection - KEY_ACTIVITYSTREAMS_SENSITIVE = "https://www.w3.org/ns/activitystreams#sensitive" // Whether the content of the object is marked as sensitive KEY_ACTIVITYSTREAMS_PUBLIC = "https://www.w3.org/ns/activitystreams#Public" // Note target + KEY_ACTIVITYSTREAMS_RESTRICTED_FOLLOW = "https://www.w3.org/ns/activitystreams#manuallyApprovesFollowers" // Does the account manually approve follow requests + KEY_ACTIVITYSTREAMS_REPLIES = "https://www.w3.org/ns/activitystreams#replies" // Object containing the replies. Should always be a Collection + KEY_ACTIVITYSTREAMS_SHAREDINBOX = "https://www.w3.org/ns/activitystreams#sharedInbox" // Link to the shared inbox of the server + KEY_ACTIVITYSTREAMS_SUMMARY = "https://www.w3.org/ns/activitystreams#summary" // Summary of an account or the cw of a note + KEY_ACTIVITYSTREAMS_SENSITIVE = "https://www.w3.org/ns/activitystreams#sensitive" // Whether the content of the object is marked as sensitive + KEY_ACTIVITYSTREAMS_TAG = "https://www.w3.org/ns/activitystreams#tag" // A tag, usually hashtags included somewhere + KEY_ACTIVITYSTREAMS_TO = "https://www.w3.org/ns/activitystreams#to" // Urls to send an activity to + KEY_ACTIVITYSTREAMS_URL = "https://www.w3.org/ns/activitystreams#url" // Some url KEY_ACTIVITYSTREAMS_UPDATED = "https://www.w3.org/ns/activitystreams#updated" // When the content was last updated // Object types (I think) // Those are values the object type can have - KEY_ACTIVITYSTREAMS_ACTOR = "https://www.w3.org/ns/activitystreams#actor" KEY_ACTIVITYSTREAMS_FOLLOW = "https://www.w3.org/ns/activitystreams#Follow" // Object is an activity of type follow KEY_ACTIVITYSTREAMS_PERSON = "https://www.w3.org/ns/activitystreams#Person" // Object is of type Person KEY_ACTIVITYSTREAMS_CREATE = "https://www.w3.org/ns/activitystreams#Create" // Object is an activity of type Create @@ -68,11 +68,13 @@ const ( KEY_ACTIVITYSTREAMS_LIKE = "https://www.w3.org/ns/activitystreams#Like" // Object is an activity of type like KEY_ACTIVITYSTREAMS_NOTE = "https://www.w3.org/ns/activitystreams#Note" // Object is of type Note + // Collection things KEY_ACTIVITYSTREAMS_FIRST = "https://www.w3.org/ns/activitystreams#first" // First page in a collection KEY_ACTIVITYSTREAMS_ITEMS = "https://www.w3.org/ns/activitystreams#items" // Items in this collection page KEY_ACTIVITYSTREAMS_NEXT = "https://www.w3.org/ns/activitystreams#next" // Next page in a collection KEY_ACTIVITYSTREAMS_PARTOF = "https://www.w3.org/ns/activitystreams#partOf" // Collection the current page is a part of + // Misc KEY_ACTIVITYSTREAMS_OAUTHAUTHORIZATION = "https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint" // Endpoint url for oauth login? KEY_ACTIVITYSTREAMS_OAUTHTOKEN = "https://www.w3.org/ns/activitystreams#oauthTokenEndpoint" // Endpoint url for oauth token verification? KEY_ACTIVITYSTREAMS_UPLOADMEDIA = "https://www.w3.org/ns/activitystreams#uploadMedia" // Endpoint url to upload media to? diff --git a/examples/mk_note_create_dm.json b/examples/mk_note_create_dm.json new file mode 100644 index 0000000..9e7705b --- /dev/null +++ b/examples/mk_note_create_dm.json @@ -0,0 +1,99 @@ +[ + { + "@id": "https://woem.men/notes/9walk87geegt0051/activity", + "@type": [ + "https://www.w3.org/ns/activitystreams#Create" + ], + "https://www.w3.org/ns/activitystreams#actor": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5" + } + ], + "https://www.w3.org/ns/activitystreams#cc": [], + "https://www.w3.org/ns/activitystreams#object": [ + { + "@id": "https://woem.men/notes/9walk87geegt0051", + "@type": [ + "https://www.w3.org/ns/activitystreams#Note" + ], + "https://www.w3.org/ns/activitystreams#attachment": [], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5" + } + ], + "https://www.w3.org/ns/activitystreams#cc": [], + "https://www.w3.org/ns/activitystreams#content": [ + { + "@value": "\u003cp\u003e\u003ca href=\"https://transgirl.cafe/@melody\" class=\"u-url mention\"\u003e@melody@transgirl.cafe\u003c/a\u003e \u003ca href=\"https://activitypub.academy/@dibona_tuladan\" class=\"u-url mention\"\u003e@dibona_tuladan@activitypub.academy\u003c/a\u003e dm test\u003c/p\u003e" + } + ], + "https://www.w3.org/ns/activitystreams#published": [ + { + "@type": "http://www.w3.org/2001/XMLSchema#dateTime", + "@value": "2024-07-29T13:36:29.068Z" + } + ], + "https://www.w3.org/ns/activitystreams#sensitive": [ + { + "@value": false + } + ], + "https://www.w3.org/ns/activitystreams#tag": [ + { + "@type": [ + "https://www.w3.org/ns/activitystreams#Mention" + ], + "https://www.w3.org/ns/activitystreams#href": [ + { + "@id": "https://transgirl.cafe/users/9ujjey44qdrt01g2" + } + ], + "https://www.w3.org/ns/activitystreams#name": [ + { + "@value": "@melody@transgirl.cafe" + } + ] + }, + { + "@type": [ + "https://www.w3.org/ns/activitystreams#Mention" + ], + "https://www.w3.org/ns/activitystreams#href": [ + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ], + "https://www.w3.org/ns/activitystreams#name": [ + { + "@value": "@dibona_tuladan@activitypub.academy" + } + ] + } + ], + "https://www.w3.org/ns/activitystreams#to": [ + { + "@id": "https://transgirl.cafe/users/9ujjey44qdrt01g2" + }, + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ] + } + ], + "https://www.w3.org/ns/activitystreams#published": [ + { + "@type": "http://www.w3.org/2001/XMLSchema#dateTime", + "@value": "2024-07-29T13:36:29.068Z" + } + ], + "https://www.w3.org/ns/activitystreams#to": [ + { + "@id": "https://transgirl.cafe/users/9ujjey44qdrt01g2" + }, + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ] + } +] diff --git a/examples/mk_note_create_follower_only_with_ping.json b/examples/mk_note_create_follower_only_with_ping.json new file mode 100644 index 0000000..2ad7f93 --- /dev/null +++ b/examples/mk_note_create_follower_only_with_ping.json @@ -0,0 +1,86 @@ +[ + { + "@id": "https://woem.men/notes/9wallcddeegt0052/activity", + "@type": [ + "https://www.w3.org/ns/activitystreams#Create" + ], + "https://www.w3.org/ns/activitystreams#actor": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5" + } + ], + "https://www.w3.org/ns/activitystreams#cc": [ + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ], + "https://www.w3.org/ns/activitystreams#object": [ + { + "@id": "https://woem.men/notes/9wallcddeegt0052", + "@type": [ + "https://www.w3.org/ns/activitystreams#Note" + ], + "https://www.w3.org/ns/activitystreams#attachment": [], + "https://www.w3.org/ns/activitystreams#attributedTo": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5" + } + ], + "https://www.w3.org/ns/activitystreams#cc": [ + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ], + "https://www.w3.org/ns/activitystreams#content": [ + { + "@value": "\u003cp\u003e\u003ca href=\"https://activitypub.academy/@dibona_tuladan\" class=\"u-url mention\"\u003e@dibona_tuladan@activitypub.academy\u003c/a\u003e test message with ping\u003c/p\u003e" + } + ], + "https://www.w3.org/ns/activitystreams#published": [ + { + "@type": "http://www.w3.org/2001/XMLSchema#dateTime", + "@value": "2024-07-29T13:37:21.121Z" + } + ], + "https://www.w3.org/ns/activitystreams#sensitive": [ + { + "@value": false + } + ], + "https://www.w3.org/ns/activitystreams#tag": [ + { + "@type": [ + "https://www.w3.org/ns/activitystreams#Mention" + ], + "https://www.w3.org/ns/activitystreams#href": [ + { + "@id": "https://activitypub.academy/users/dibona_tuladan" + } + ], + "https://www.w3.org/ns/activitystreams#name": [ + { + "@value": "@dibona_tuladan@activitypub.academy" + } + ] + } + ], + "https://www.w3.org/ns/activitystreams#to": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5/followers" + } + ] + } + ], + "https://www.w3.org/ns/activitystreams#published": [ + { + "@type": "http://www.w3.org/2001/XMLSchema#dateTime", + "@value": "2024-07-29T13:37:21.121Z" + } + ], + "https://www.w3.org/ns/activitystreams#to": [ + { + "@id": "https://woem.men/users/9n39zo1rfckr00q5/followers" + } + ] + } +] diff --git a/go.mod b/go.mod index ec68e0e..7a6ab93 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require github.com/piprate/json-gold v0.5.0 require ( github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect github.com/stretchr/testify v1.9.0 // indirect - gitlab.com/mstarongitlab/goutils v1.2.0 + gitlab.com/mstarongitlab/goutils v1.3.0 ) diff --git a/go.sum b/go.sum index 2e9b8c5..ca0c473 100644 --- a/go.sum +++ b/go.sum @@ -8,7 +8,7 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAm github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -gitlab.com/mstarongitlab/goutils v1.2.0 h1:hVpc2VikWkgmX7Gbey9I72eqgmg/6GcKZ4q+M9ZBd0E= -gitlab.com/mstarongitlab/goutils v1.2.0/go.mod h1:SvqfzFxgashuZPqR9kPwQ9gFA7I1yskZjhmGmY2pAow= +gitlab.com/mstarongitlab/goutils v1.3.0 h1:uuxPHjIU36lyJ8/z4T2xI32zOyh53Xj0Au8K12qkaJ4= +gitlab.com/mstarongitlab/goutils v1.3.0/go.mod h1:SvqfzFxgashuZPqR9kPwQ9gFA7I1yskZjhmGmY2pAow= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/nsActivitystreams.go b/nsActivitystreams.go index 231809e..61cd1f2 100644 --- a/nsActivitystreams.go +++ b/nsActivitystreams.go @@ -3,31 +3,71 @@ package goap import ( "time" + "gitlab.com/mstarongitlab/goutils/maputils" "gitlab.com/mstarongitlab/goutils/sliceutils" ) type ActorData struct { - IdType + FullIdType } func (actor *ActorData) GetSelfOrBase() (BaseApChain, bool) { - return actor.IdType.GetSelfOrBase() + return actor.FullIdType.GetSelfOrBase() } func (actor *ActorData) MarshalToMap() map[string]any { - return actor.IdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_ACTOR) + return actor.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_ACTOR) } -type ObjectData struct { - IdType +type AlsoKnownAsData struct { + Next BaseApChain + Urls []string } -func (object *ObjectData) GetSelfOrBase() (BaseApChain, bool) { - return object.IdType.Next, true +func (cc *AlsoKnownAsData) GetSelfOrBase() (BaseApChain, bool) { + return cc.Next, true } -func (object *ObjectData) MarshalToMap() map[string]any { - return object.IdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_OBJECT) +func (cc *AlsoKnownAsData) MarshalToMap() map[string]any { + return appendWithKey( + cc.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_ALSOKNOWNAS, + sliceutils.Map(cc.Urls, func(t string) map[string]any { + return map[string]any{KEY_ID: t} + }), + ) +} + +type AttachmentsData struct { + Next BaseApChain + Attachments []Attachment +} + +func (attachmentsdata *AttachmentsData) GetSelfOrBase() (BaseApChain, bool) { + return attachmentsdata.Next, true +} + +func (attachmentsdata *AttachmentsData) MarshalToMap() map[string]any { + return appendWithKey( + attachmentsdata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_ATTACHMENTS, + sliceutils.Map( + attachmentsdata.Attachments, + func(t Attachment) map[string]any { return t.Marshal() }, + ), + ) +} + +type AttributedToData struct { + FullIdType +} + +func (attributedtodata *AttributedToData) GetSelfOrBase() (BaseApChain, bool) { + return attributedtodata.FullIdType.Next, true +} + +func (attributedtodata *AttributedToData) MarshalToMap() map[string]any { + return attributedtodata.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_ATTRIBUTEDTO) } type CCData struct { @@ -40,22 +80,81 @@ func (cc *CCData) GetSelfOrBase() (BaseApChain, bool) { } func (cc *CCData) MarshalToMap() map[string]any { - return appendWithKey(cc.Next.MarshalToMap(), KEY_ACTIVITYSTREAMS_CC, strsToIds(cc.Targets)) + return appendWithKey( + cc.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_CC, + sliceutils.Map(cc.Targets, func(t string) map[string]any { + return map[string]any{KEY_ID: t} + }), + ) } -type ToData struct { +// Content + +type ContentData struct { Next BaseApChain - Targets []string + Content []ValueValue[string] } -func (cc *ToData) GetSelfOrBase() (BaseApChain, bool) { - return cc.Next, true +func (contentdata *ContentData) GetSelfOrBase() (BaseApChain, bool) { + return contentdata.Next, true } -func (cc *ToData) MarshalToMap() map[string]any { - return appendWithKey(cc.Next.MarshalToMap(), KEY_ACTIVITYSTREAMS_TO, strsToIds(cc.Targets)) +func (contentdata *ContentData) MarshalToMap() map[string]any { + return appendWithKey( + contentdata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_CONTENT, + sliceutils.Map(contentdata.Content, func(t ValueValue[string]) map[string]any { + return t.Marshal() + }), + ) } +type EndpointsData struct { + Next BaseApChain + Endpoints map[string]string +} + +func (endpointsdata *EndpointsData) GetSelfOrBase() (BaseApChain, bool) { + return endpointsdata.Next, true +} + +func (endpointsdata *EndpointsData) MarshalToMap() map[string]any { + m := endpointsdata.Next.MarshalToMap() + arr := []map[string]any{} + for k, v := range endpointsdata.Endpoints { + arr = append(arr, map[string]any{ + k: []map[string]any{{KEY_ID: v}}, + }) + } + m[KEY_ACTIVITYSTREAMS_ENDPOINTS] = arr + return m +} + +// Endpoints +// Followers +// Following +// Href +// Icon +// Image +// MediaType +// Name +// Outbox + +type ObjectData struct { + FullIdType +} + +func (object *ObjectData) GetSelfOrBase() (BaseApChain, bool) { + return object.FullIdType.Next, true +} + +func (object *ObjectData) MarshalToMap() map[string]any { + return object.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_OBJECT) +} + +// PrefferedUsername + type PublishedData struct { Next BaseApChain Timestamp time.Time @@ -73,9 +172,16 @@ func (publisheddata *PublishedData) MarshalToMap() map[string]any { return m } +// Public +// RestrictedFollow +// Replies +// SharedInbox +// Summary +// Sensitive + type TagData struct { Next BaseApChain - Tags []Tag + Tags []string } func (tagdata *TagData) GetSelfOrBase() (BaseApChain, bool) { @@ -83,10 +189,33 @@ func (tagdata *TagData) GetSelfOrBase() (BaseApChain, bool) { } 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 appendWithKey( + tagdata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_TAG, + sliceutils.Map(tagdata.Tags, func(t string) map[string]any { + return map[string]any{KEY_ID: t} + }), ) - return m } + +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, + sliceutils.Map(cc.Targets, func(t string) map[string]any { + return map[string]any{KEY_ID: t} + }), + ) +} + +// Url +// Updated diff --git a/variousTypes.go b/variousTypes.go index 1c89323..fdbb197 100644 --- a/variousTypes.go +++ b/variousTypes.go @@ -1,5 +1,7 @@ package goap +import "maps" + type PublicKey struct { Id string Owner string @@ -18,19 +20,14 @@ type Media struct { Url string } -type Tag struct { - Type string - Href string - Name string -} - type IdValue struct { Id string } type ValueValue[T any] struct { - Type *string - Value T + Type *string + Value T + OtherThings map[string]any } func (p PublicKey) Marshal() map[string]any { @@ -42,16 +39,9 @@ func (p PublicKey) Marshal() map[string]any { func (a Attachment) Marshal() map[string]any { return map[string]any{ - KEY_TYPE: []string{KEY_SCHEMA_PROPERTYVALUE}, - KEY_SCHEMA_VALUE: ValueValue[string]{Value: a.Value}.Marshal(), - } -} - -func (t Tag) Marshal() map[string]any { - return map[string]any{ - KEY_TYPE: t.Type, - KEY_ACTIVITYSTREAMS_NAME: t.Name, - KEY_ACTIVITYSTREAMS_HREF: IdValue{Id: t.Href}.Marshal(), + KEY_TYPE: []string{KEY_SCHEMA_PROPERTYVALUE}, + KEY_SCHEMA_VALUE: []map[string]any{ValueValue[string]{Value: a.Value}.Marshal()}, + KEY_ACTIVITYSTREAMS_NAME: []map[string]any{ValueValue[string]{Value: a.Name}.Marshal()}, } } @@ -62,9 +52,8 @@ func (i IdValue) Marshal() map[string]any { } func (v ValueValue[T]) Marshal() map[string]any { - m := map[string]any{ - KEY_VALUE: v.Value, - } + m := maps.Clone(v.OtherThings) + m[KEY_VALUE] = v.Value if v.Type != nil { m[KEY_TYPE] = *v.Type }