diff --git a/constants.go b/constants.go index a10b348..ac7e969 100644 --- a/constants.go +++ b/constants.go @@ -38,14 +38,13 @@ const ( 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_IMAGE = "https://www.w3.org/ns/activitystreams#image" // Account banner + KEY_ACTIVITYSTREAMS_IMAGE_ATTRIBUTE = "https://www.w3.org/ns/activitystreams#image" // Account banner 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_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 @@ -67,6 +66,7 @@ const ( KEY_ACTIVITYSTREAMS_HASHTAG = "https://www.w3.org/ns/activitystreams#Hashtag" // Object is a hashtag 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 + KEY_ACTIVITYSTREAMS_IMAGE_TYPE = "https://www.w3.org/ns/activitystreams#Image" // Object is of type Image // Collection things KEY_ACTIVITYSTREAMS_FIRST = "https://www.w3.org/ns/activitystreams#first" // First page in a collection @@ -78,6 +78,7 @@ const ( 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? + KEY_ACTIVITYSTREAMS_PUBLIC = "https://www.w3.org/ns/activitystreams#Public" // Note target ) const ( diff --git a/nsActivitystreams.go b/nsActivitystreams.go index 61cd1f2..ddc2297 100644 --- a/nsActivitystreams.go +++ b/nsActivitystreams.go @@ -131,15 +131,125 @@ func (endpointsdata *EndpointsData) MarshalToMap() map[string]any { return m } -// Endpoints -// Followers -// Following -// Href -// Icon -// Image -// MediaType -// Name -// Outbox +type FollowersData struct { + FullIdType +} + +func (attributedtodata *FollowersData) GetSelfOrBase() (BaseApChain, bool) { + return attributedtodata.FullIdType.Next, true +} + +func (attributedtodata *FollowersData) MarshalToMap() map[string]any { + return attributedtodata.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_FOLLOWERS) +} + +type FollowingData struct { + FullIdType +} + +func (attributedtodata *FollowingData) GetSelfOrBase() (BaseApChain, bool) { + return attributedtodata.FullIdType.Next, true +} + +func (attributedtodata *FollowingData) MarshalToMap() map[string]any { + return attributedtodata.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_FOLLOWING) +} + +type HrefData struct { + FullIdType +} + +func (attributedtodata *HrefData) GetSelfOrBase() (BaseApChain, bool) { + return attributedtodata.FullIdType.Next, true +} + +func (attributedtodata *HrefData) MarshalToMap() map[string]any { + return attributedtodata.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_HREF) +} + +type IconData struct { + Next BaseApChain + Media Media +} + +func (icondata *IconData) GetSelfOrBase() (BaseApChain, bool) { + return icondata.Next, true +} + +func (icondata *IconData) MarshalToMap() map[string]any { + return appendWithKey( + icondata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_ICON, + []map[string]any{icondata.Media.Marshal()}, + ) +} + +type ImageData struct { + Next BaseApChain + Media Media +} + +func (icondata *ImageData) GetSelfOrBase() (BaseApChain, bool) { + return icondata.Next, true +} + +func (icondata *ImageData) MarshalToMap() map[string]any { + return appendWithKey( + icondata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_IMAGE_ATTRIBUTE, + []map[string]any{icondata.Media.Marshal()}, + ) +} + +type MediaTypeData struct { + Next BaseApChain + Type string +} + +func (mediatypedata *MediaTypeData) GetSelfOrBase() (BaseApChain, bool) { + return mediatypedata.Next, true +} + +func (mediatypedata *MediaTypeData) MarshalToMap() map[string]any { + return appendWithKey( + mediatypedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_MEDIATYPE, + ValueValue[string]{ + Value: mediatypedata.Type, + Type: nil, + OtherThings: map[string]any{}, + }.Marshal(), + ) +} + +type NameData struct { + Next BaseApChain + Name ValueValue[string] +} + +func (namedata *NameData) GetSelfOrBase() (BaseApChain, bool) { + return namedata.Next, true +} + +func (namedata *NameData) MarshalToMap() map[string]any { + return appendWithKey( + namedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_NAME, + []map[string]any{namedata.Name.Marshal()}, + ) +} + +type OutboxData struct { + FullIdType +} + +func (attributedtodata *OutboxData) GetSelfOrBase() (BaseApChain, bool) { + return attributedtodata.FullIdType.Next, true +} + +func (attributedtodata *OutboxData) MarshalToMap() map[string]any { + return attributedtodata.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_HREF) +} type ObjectData struct { FullIdType @@ -153,7 +263,22 @@ func (object *ObjectData) MarshalToMap() map[string]any { return object.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_OBJECT) } -// PrefferedUsername +type PreferredNameData struct { + Next BaseApChain + Name ValueValue[string] +} + +func (namedata *PreferredNameData) GetSelfOrBase() (BaseApChain, bool) { + return namedata.Next, true +} + +func (namedata *PreferredNameData) MarshalToMap() map[string]any { + return appendWithKey( + namedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_PREFFEREDUSERNAME, + []map[string]any{namedata.Name.Marshal()}, + ) +} type PublishedData struct { Next BaseApChain @@ -164,20 +289,86 @@ 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 } -// Public -// RestrictedFollow -// Replies -// SharedInbox -// Summary -// Sensitive +type RestrictedFollowData struct { + Next BaseApChain + Value ValueValue[bool] +} + +func (namedata *RestrictedFollowData) GetSelfOrBase() (BaseApChain, bool) { + return namedata.Next, true +} + +func (namedata *RestrictedFollowData) MarshalToMap() map[string]any { + return appendWithKey( + namedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_RESTRICTED_FOLLOW, + []map[string]any{namedata.Value.Marshal()}, + ) +} + +type RepliesData struct { + FullIdType +} + +func (object *RepliesData) GetSelfOrBase() (BaseApChain, bool) { + return object.FullIdType.Next, true +} + +func (object *RepliesData) MarshalToMap() map[string]any { + return object.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_REPLIES) +} + +type SharedInboxData struct { + FullIdType +} + +func (object *SharedInboxData) GetSelfOrBase() (BaseApChain, bool) { + return object.FullIdType.Next, true +} + +func (object *SharedInboxData) MarshalToMap() map[string]any { + return object.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_SHAREDINBOX) +} + +type SummaryData struct { + Next BaseApChain + Name ValueValue[string] +} + +func (namedata *SummaryData) GetSelfOrBase() (BaseApChain, bool) { + return namedata.Next, true +} + +func (namedata *SummaryData) MarshalToMap() map[string]any { + return appendWithKey( + namedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_SUMMARY, + []map[string]any{namedata.Name.Marshal()}, + ) +} + +type SensitiveData struct { + Next BaseApChain + Name ValueValue[bool] +} + +func (namedata *SensitiveData) GetSelfOrBase() (BaseApChain, bool) { + return namedata.Next, true +} + +func (namedata *SensitiveData) MarshalToMap() map[string]any { + return appendWithKey( + namedata.Next.MarshalToMap(), + KEY_ACTIVITYSTREAMS_SENSITIVE, + []map[string]any{namedata.Name.Marshal()}, + ) +} type TagData struct { Next BaseApChain @@ -218,4 +409,30 @@ func (cc *ToData) MarshalToMap() map[string]any { } // Url +type UrlData struct { + FullIdType +} + +func (object *UrlData) GetSelfOrBase() (BaseApChain, bool) { + return object.FullIdType.Next, true +} + +func (object *UrlData) MarshalToMap() map[string]any { + return object.FullIdType.MarshalToMapWithName(KEY_ACTIVITYSTREAMS_SHAREDINBOX) +} + // Updated +type UpdatedData struct { + Next BaseApChain + Timestamp time.Time +} + +func (publisheddata *UpdatedData) GetSelfOrBase() (BaseApChain, bool) { + return publisheddata.Next, true +} + +func (publisheddata *UpdatedData) MarshalToMap() map[string]any { + m := publisheddata.Next.MarshalToMap() + m[KEY_ACTIVITYSTREAMS_PUBLISHED] = timeToXmlTime(publisheddata.Timestamp) + return m +} diff --git a/variousTypes.go b/variousTypes.go index fdbb197..49ec517 100644 --- a/variousTypes.go +++ b/variousTypes.go @@ -16,8 +16,9 @@ type Attachment struct { type Media struct { Type string - MediaType string + MediaType *string Url string + Sensitive *bool } type IdValue struct { @@ -59,3 +60,18 @@ func (v ValueValue[T]) Marshal() map[string]any { } return m } + +func (m Media) Marshal() map[string]any { + t := map[string]any{ + KEY_TYPE: []string{m.Type}, + KEY_ACTIVITYSTREAMS_URL: []map[string]any{IdValue{Id: m.Url}.Marshal()}, + } + if m.MediaType != nil { + t[KEY_ACTIVITYSTREAMS_MEDIATYPE] = []map[string]any{{KEY_VALUE: *m.MediaType}} + } + if m.Sensitive != nil { + t[KEY_ACTIVITYSTREAMS_SENSITIVE] = []map[string]any{{KEY_VALUE: *m.Sensitive}} + } + + return t +}