-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasvocab_base_types.go
279 lines (240 loc) · 12.2 KB
/
asvocab_base_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package astreams
import (
"sort"
"time"
)
// ObjectOrLink is a wrapper type that represents any valid ActivityStreams 2.0 object or link
// Single objects are still presented as slices, but with a single element
type ObjectOrLink []ObjectLinker
// ObjectOrLinkOrString is a type that can either represent simple string URL(s) or an Object/Link slice
type ObjectOrLinkOrString struct {
Target ObjectOrLink
URL []string
}
// StringWithOrderedCollectionPage can store a string URL pointing to an OrderedCollectionPage, which can itself be stored in the struct
type StringWithOrderedCollectionPage struct {
OrdCollectionPage OrderedCollectionPage
URL string
}
// StringWithOrderedCollection can store a string URL pointing to an OrderedCollection, which can itself be stored in the struct
type StringWithOrderedCollection struct {
OrdCollection OrderedCollection
URL string
}
// StringWithCollectionPage can store a string URL pointing to a CollectionPage, which can itself be stored in the struct
type StringWithCollectionPage struct {
CollectionPage CollectionPage
URL string
}
// StringWithCollection can store a string URL pointing to a Collection, which can itself be stored in the struct
type StringWithCollection struct {
Collection Collection
URL string
}
// Icons is a type representing the possible ActivityPub icon values
type Icons struct {
Icons []Icon
URL string
}
// https://www.w3.org/TR/activitystreams-vocabulary
// Object represents the base ActivityStreams Object and all of its properties
// Most of the other types extend Object
type Object struct {
AlsoKnownAs *ObjectOrLinkOrString `json:"alsoKnownAs,omitempty"`
ASContext any `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
AtID string `json:"@id,omitempty"`
AtType string `json:"@type,omitempty"`
Attachment *ObjectOrLinkOrString `json:"attachment,omitempty"`
AttributedTo *ObjectOrLinkOrString `json:"attributedTo,omitempty"`
Audience *ObjectOrLinkOrString `json:"audience,omitempty"`
Bcc *ObjectOrLinkOrString `json:"bcc,omitempty"`
Bto *ObjectOrLinkOrString `json:"bto,omitempty"`
Cc *ObjectOrLinkOrString `json:"cc,omitempty"`
Content string `json:"content,omitempty"` // needs to be parsed safely ie by https://golang.org/pkg/html/template
ContentMap map[string]string `json:"contentMap,omitempty"`
Context *ObjectOrLinkOrString `json:"context,omitempty"`
Conversation string `json:"conversation,omitempty"`
Duration string `json:"duration,omitempty"` // xsd:duration
EndTime *time.Time `json:"endTime,omitempty"`
Generator *ObjectOrLinkOrString `json:"generator,omitempty"`
Icon *ObjectOrLinkOrString `json:"icon,omitempty"`
ID string `json:"id,omitempty"`
Image *ObjectOrLinkOrString `json:"image,omitempty"`
InReplyTo *ObjectOrLinkOrString `json:"inReplyTo,omitempty"`
Likes *ObjectOrLinkOrString `json:"likes,omitempty"`
Location *ObjectOrLinkOrString `json:"location,omitempty"`
MediaType string `json:"mediaType,omitempty"`
MovedTo *ObjectOrLinkOrString `json:"movedTo,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
Replies *OrderedCollection `json:"replies,omitempty"`
Schema string `json:"schema,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
Shares *ObjectOrLinkOrString `json:"shares,omitempty"`
Source *ObjectOrLinkOrString `json:"source,omitempty"`
StartTime *time.Time `json:"startTime,omitempty"`
Summary string `json:"summary,omitempty"`
SummaryMap map[string]string `json:"summaryMap,omitempty"`
Tag *ObjectOrLinkOrString `json:"tag,omitempty"`
To *ObjectOrLinkOrString `json:"to,omitempty"`
Type string `json:"type"`
Updated *time.Time `json:"updated,omitempty"`
URL *ObjectOrLinkOrString `json:"url,omitempty"`
}
// Link represents the base ActivityStreams Link and all of its properties
// Other Link types extend it
type Link struct {
ASContext any `json:"@context,omitempty"`
ASLanguage string `json:"@language,omitempty"`
Height int `json:"height,omitempty"`
Href string `json:"href,omitempty"`
Hreflang string `json:"hreflang,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Name string `json:"name,omitempty"`
NameMap map[string]string `json:"nameMap,omitempty"`
Preview *ObjectOrLinkOrString `json:"preview,omitempty"`
Published *time.Time `json:"published,omitempty"`
Rel []string `json:"rel,omitempty"`
Type string `json:"type"`
Value string `json:"value,omitempty"`
Width int `json:"width,omitempty"`
}
type Location struct {
Object
Altitude int `json:"altitude,omitempty"`
Latitude float32 `json:"latitude,omitempty"`
Longitude float32 `json:"longitude,omitempty"`
Units string `json:"units,omitempty"`
}
type Endpoints struct {
OauthAuthorizationEndpoint string `json:"oauthAuthorizationEndpoint,omitempty"`
OauthTokenEndpoint string `json:"oauthTokenEndpoint,omitempty"`
ProvideClientKey string `json:"provideClientKey,omitempty"`
ProxyUrl string `json:"proxyUrl,omitempty"`
SharedInbox *StringWithOrderedCollection `json:"sharedInbox,omitempty"`
SignClientKey string `json:"signClientKey,omitempty"`
}
type Icon struct {
Object
Height int `json:"height"`
Width int `json:"width"`
}
type Actor struct {
Object
Devices *StringWithCollection `json:"devices,omitempty"`
Discoverable *bool `json:"discoverable,omitempty"`
Endpoints *Endpoints `json:"endpoints,omitempty"`
Featured *StringWithOrderedCollection `json:"featured,omitempty"`
FeaturedTags *StringWithCollection `json:"featuredTags,omitempty"`
Followers *StringWithOrderedCollection `json:"followers,omitempty"`
Following *StringWithOrderedCollection `json:"following,omitempty"`
Inbox *StringWithOrderedCollection `json:"inbox,omitempty"`
Indexable *bool `json:"indexable,omitempty"`
Liked *StringWithOrderedCollection `json:"liked,omitempty"`
ManuallyApprovesFollowers *bool `json:"manuallyApprovesFollowers,omitempty"`
Memorial *bool `json:"memorial,omitempty"`
Outbox *StringWithOrderedCollection `json:"outbox,omitempty"`
PreferredUsername string `json:"preferredUsername,omitempty"`
PublicKey *PublicKey `json:"publicKey,omitempty"`
Streams *ObjectOrLinkOrString `json:"streams,omitempty"`
}
type PublicKey struct {
ID string `json:"id"`
Owner string `json:"owner"`
PublicKeyPem string `json:"publicKeyPem"`
}
type Activity struct {
Object
Actor *ObjectOrLinkOrString `json:"actor,omitempty"`
ActivityObject *ObjectOrLinkOrString `json:"object,omitempty"` // the 'object' property of Activity
Instrument *ObjectOrLinkOrString `json:"instrument,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Target *ObjectOrLinkOrString `json:"target,omitempty"`
}
type IntransitiveActivity struct {
Object
Actor *ObjectOrLinkOrString `json:"actor,omitempty"`
Instrument *ObjectOrLinkOrString `json:"instrument,omitempty"`
Origin *ObjectOrLinkOrString `json:"origin,omitempty"`
Result *ObjectOrLinkOrString `json:"result,omitempty"`
Target *ObjectOrLinkOrString `json:"target,omitempty"`
}
type CollectionPage struct {
Collection
Next *ObjectOrLinkOrString `json:"next,omitempty"`
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Prev *ObjectOrLinkOrString `json:"prev,omitempty"`
}
type Collection struct {
Object
Current *StringWithCollectionPage `json:"current,omitempty"`
First *StringWithCollectionPage `json:"first,omitempty"`
Items *ObjectOrLinkOrString `json:"items,omitempty"`
Last *StringWithCollectionPage `json:"last,omitempty"`
TotalItems int `json:"totalItems,omitempty"`
}
// OrderedCollectionPage implements https://golang.org/pkg/sort/#Interface
type OrderedCollectionPage struct {
OrderedCollection
Next *ObjectOrLinkOrString `json:"next,omitempty"`
PartOf *ObjectOrLinkOrString `json:"partOf,omitempty"`
Prev *ObjectOrLinkOrString `json:"prev,omitempty"`
StartIndex uint `json:"startIndex,omitempty"`
}
// OrderedCollection implements https://golang.org/pkg/sort/#Interface
type OrderedCollection struct {
Object
Current *StringWithOrderedCollectionPage `json:"current,omitempty"`
First *StringWithOrderedCollectionPage `json:"first,omitempty"`
Last *StringWithOrderedCollectionPage `json:"last,omitempty"`
OrderedItems *ObjectOrLinkOrString `json:"orderedItems"`
TotalItems int `json:"totalItems"`
}
func (oc OrderedCollection) Len() int {
if len(oc.OrderedItems.URL) > 0 {
return len(oc.OrderedItems.URL)
}
return len(oc.OrderedItems.Target)
}
func (oc OrderedCollection) Less(i, j int) bool {
if len(oc.OrderedItems.Target) > 0 {
if oc.OrderedItems.Target[i].IsObject() && oc.OrderedItems.Target[j].IsObject() {
return oc.OrderedItems.Target[j].GetObject().Published.Before(*oc.OrderedItems.Target[i].GetObject().Published)
} else if oc.OrderedItems.Target[i].IsObject() && oc.OrderedItems.Target[j].IsLink() {
return oc.OrderedItems.Target[j].GetObject().Published.Before(*oc.OrderedItems.Target[i].GetLink().Published)
} else if oc.OrderedItems.Target[i].IsLink() && oc.OrderedItems.Target[j].IsLink() {
return oc.OrderedItems.Target[j].GetLink().Published.Before(*oc.OrderedItems.Target[i].GetLink().Published)
} else if oc.OrderedItems.Target[i].IsLink() && oc.OrderedItems.Target[j].IsObject() {
return oc.OrderedItems.Target[j].GetLink().Published.Before(*oc.OrderedItems.Target[i].GetObject().Published)
}
}
return false
}
func (oc OrderedCollection) Swap(i, j int) {
if len(oc.OrderedItems.URL) > 0 {
oc.OrderedItems.URL[i], oc.OrderedItems.URL[j] = oc.OrderedItems.URL[j], oc.OrderedItems.URL[i]
} else {
oc.OrderedItems.Target[i], oc.OrderedItems.Target[j] = oc.OrderedItems.Target[j], oc.OrderedItems.Target[i]
}
}
// SortByUpdated sorts OrderedCollection objects by Updated rather than Published date
func (oc OrderedCollection) SortByUpdated() {
sort.Slice(oc.OrderedItems.Target, func(i, j int) bool {
if len(oc.OrderedItems.Target) > 0 {
if oc.OrderedItems.Target[i].IsObject() && oc.OrderedItems.Target[j].IsObject() {
return oc.OrderedItems.Target[j].GetObject().Updated.Before(*oc.OrderedItems.Target[i].GetObject().Updated)
} else if oc.OrderedItems.Target[i].IsObject() && oc.OrderedItems.Target[j].IsLink() {
return oc.OrderedItems.Target[j].GetObject().Updated.Before(*oc.OrderedItems.Target[i].GetLink().Published)
} else if oc.OrderedItems.Target[i].IsLink() && oc.OrderedItems.Target[j].IsLink() {
return oc.OrderedItems.Target[j].GetLink().Published.Before(*oc.OrderedItems.Target[i].GetLink().Published)
} else if oc.OrderedItems.Target[i].IsLink() && oc.OrderedItems.Target[j].IsObject() {
return oc.OrderedItems.Target[j].GetLink().Published.Before(*oc.OrderedItems.Target[i].GetObject().Updated)
}
}
return false
})
}