-
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
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
package activitypub
import (
"bytes"
"encoding/gob"
"errors"
"fmt"
"time"
)
func unmapActorProperties(mm map[string][]byte, a *Actor) error {
return errors.New("TODO unmapActorProperties")
}
func unmapIntransitiveActivityProperties(mm map[string][]byte, act *IntransitiveActivity) error {
return errors.New("TODO unmapIntransitiveActivityProperties")
}
func unmapActivityProperties(mm map[string][]byte, act *Activity) error {
return errors.New("TODO unmapActivityProperties")
}
func unmapLinkProperties(mm map[string][]byte, l *Link) error {
return errors.New("TODO unmapLinkProperties")
}
func unmapObjectProperties(mm map[string][]byte, o *Object) error {
var err error
if raw, ok := mm["id"]; ok {
if err = o.ID.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["type"]; ok {
if err = o.Type.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["name"]; ok {
if err = o.Name.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["attachment"]; ok {
if o.Attachment, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["attributedTo"]; ok {
if o.AttributedTo, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["audience"]; ok {
if o.Audience, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["content"]; ok {
if o.Content, err = gobDecodeNaturalLanguageValues(raw); err != nil {
return err
}
}
if raw, ok := mm["context"]; ok {
if o.Context, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["mediaType"]; ok {
if err = o.MediaType.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["endTime"]; ok {
if err = o.EndTime.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["generator"]; ok {
if o.Generator, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["icon"]; ok {
if o.Icon, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["image"]; ok {
if o.Image, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["inReplyTo"]; ok {
if o.InReplyTo, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["location"]; ok {
if o.Location, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["preview"]; ok {
if o.Preview, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["published"]; ok {
if err = o.Published.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["replies"]; ok {
if o.Replies, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["startTime"]; ok {
if err = o.StartTime.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["summary"]; ok {
if o.Summary, err = gobDecodeNaturalLanguageValues(raw); err != nil {
return err
}
}
if raw, ok := mm["tag"]; ok {
if o.Tag, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["updated"]; ok {
if err = o.Updated.GobDecode(raw); err != nil {
return err
}
}
if raw, ok := mm["url"]; ok {
if o.URL, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["to"]; ok {
if o.To, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["bto"]; ok {
if o.Bto, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["cc"]; ok {
if o.CC, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["bcc"]; ok {
if o.BCC, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["duration"]; ok {
if o.Duration, err = gobDecodeDuration(raw); err != nil {
return err
}
}
if raw, ok := mm["likes"]; ok {
if o.Likes, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["shares"]; ok {
if o.Shares, err = gobDecodeItem(raw); err != nil {
return err
}
}
if raw, ok := mm["source"]; ok {
if err := o.Source.GobDecode(raw); err != nil {
return err
}
}
return nil
}
func tryDecodeObject(ob *Object, data []byte) error {
if err := ob.GobDecode(data); err != nil {
return err
}
return nil
}
func tryDecodeItems(items *ItemCollection, data []byte) error {
tt := make([][]byte, 0)
g := gob.NewDecoder(bytes.NewReader(data))
if err := g.Decode(&tt); err != nil {
return err
}
for _, it := range tt {
ob, err := gobDecodeItem(it)
if err != nil {
return err
}
*items = append(*items, ob)
}
return nil
}
func tryDecodeIRIs(iris *IRIs, data []byte) error {
return iris.GobDecode(data)
}
func tryDecodeIRI(iri *IRI, data []byte) error {
return iri.GobDecode(data)
}
func gobDecodeDuration(data []byte) (time.Duration, error) {
var d time.Duration
err := gob.NewDecoder(bytes.NewReader(data)).Decode(&d)
return d, err
}
func gobDecodeNaturalLanguageValues(data []byte) (NaturalLanguageValues, error) {
n := make(NaturalLanguageValues, 0)
err := n.GobDecode(data)
return n, err
}
func gobDecodeItems(data []byte) (ItemCollection, error) {
items := make(ItemCollection, 0)
if err := tryDecodeItems(&items, data); err != nil {
return nil, err
}
return items, nil
}
func gobDecodeItem(data []byte) (Item, error) {
items := make(ItemCollection, 0)
if err := tryDecodeItems(&items, data); err == nil {
return items, nil
}
iris := make(IRIs, 0)
if err := tryDecodeIRIs(&iris, data); err == nil {
it := make(ItemCollection, len(iris))
for i, iri := range iris {
it[i] = iri
}
return it, nil
}
iri := IRI("")
if err := tryDecodeIRI(&iri, data); err == nil {
return iri, err
}
mm, err := gobDecodeObjectAsMap(data)
if err != nil {
return nil, err
}
typ := ObjectType
sTyp, isObject := mm["type"]
if isObject {
typ = ActivityVocabularyType(sTyp)
} else {
_, isObject = mm["id"]
}
if isObject {
it, err := GetItemByType(typ)
if err != nil {
return nil, err
}
switch it.GetType() {
case IRIType:
case "", ObjectType, ArticleType, AudioType, DocumentType, EventType, ImageType, NoteType, PageType, VideoType:
err = OnObject(it, func(ob *Object) error {
return unmapObjectProperties(mm, ob)
})
case LinkType, MentionType:
err = OnLink(it, func(l *Link) error {
return unmapLinkProperties(mm, l)
})
case ActivityType, AcceptType, AddType, AnnounceType, BlockType, CreateType, DeleteType, DislikeType,
FlagType, FollowType, IgnoreType, InviteType, JoinType, LeaveType, LikeType, ListenType, MoveType, OfferType,
RejectType, ReadType, RemoveType, TentativeRejectType, TentativeAcceptType, UndoType, UpdateType, ViewType:
err = OnActivity(it, func(act *Activity) error {
return unmapActivityProperties(mm, act)
})
case IntransitiveActivityType, ArriveType, TravelType:
err = OnIntransitiveActivity(it, func(act *IntransitiveActivity) error {
return unmapIntransitiveActivityProperties(mm, act)
})
case ActorType, ApplicationType, GroupType, OrganizationType, PersonType, ServiceType:
err = OnActor(it, func(a *Actor) error {
return unmapActorProperties(mm, a)
})
case CollectionType:
err = OnCollection(it, func(c *Collection) error {
return fmt.Errorf("TODO: Implement decode of %T", c)
})
case OrderedCollectionType:
err = OnOrderedCollection(it, func(c *OrderedCollection) error {
return fmt.Errorf("TODO: Implement decode of %T", c)
})
case CollectionPageType:
err = OnCollectionPage(it, func(p *CollectionPage) error {
return fmt.Errorf("TODO: Implement decode of %T", p)
})
case OrderedCollectionPageType:
err = OnOrderedCollectionPage(it, func(p *OrderedCollectionPage) error {
return fmt.Errorf("TODO: Implement decode of %T", p)
})
case PlaceType:
err = OnPlace(it, func(p *Place) error {
return fmt.Errorf("TODO: Implement decode of %T", p)
})
case ProfileType:
err = OnProfile(it, func(p *Profile) error {
return fmt.Errorf("TODO: Implement decode of %T", p)
})
case RelationshipType:
err = OnRelationship(it, func(r *Relationship) error {
return fmt.Errorf("TODO: Implement decode of %T", r)
})
case TombstoneType:
err = OnTombstone(it, func(t *Tombstone) error {
return fmt.Errorf("TODO: Implement decode of %T", t)
})
case QuestionType:
err = OnQuestion(it, func(q *Question) error {
return fmt.Errorf("TODO: Implement decode of %T", q)
})
}
return it, err
}
return nil, errors.New("unable to decode to any known ActivityPub types")
}
func gobDecodeObjectAsMap(data []byte) (map[string][]byte, error) {
mm := make(map[string][]byte)
g := gob.NewDecoder(bytes.NewReader(data))
if err := g.Decode(&mm); err != nil {
return nil, err
}
return mm, nil
}