aboutsummaryrefslogtreecommitdiff
path: root/activitypub/structs.go
blob: c42d1759f6bc08674b5f0723d27e958d587f9d58 (plain)
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
package activitypub

import (
	"time"

	"encoding/json"
	"html/template"
)

type AtContextRaw struct {
	Context json.RawMessage `json:"@context,omitempty"`
}

type ActivityRaw struct {
	AtContextRaw
	Type      string          `json:"type,omitempty"`
	Id        string          `json:"id,omitempty"`
	Name      string          `json:"name,omitempty"`
	Summary   string          `json:"summary,omitempty"`
	Auth      string          `json:"auth,omitempty"`
	ToRaw     json.RawMessage `json:"to,omitempty"`
	BtoRaw    json.RawMessage `json:"bto,omitempty"`
	CcRaw     json.RawMessage `json:"cc,omitempty"`
	Published time.Time       `json:"published,omitempty"`
	ActorRaw  json.RawMessage `json:"actor,omitempty"`
	ObjectRaw json.RawMessage `json:"object,omitempty"`
}

type AtContext struct {
	Context string `json:"@context,omitempty"`
}

type AtContextArray struct {
	Context []interface{} `json:"@context,omitempty"`
}

type AtContextString struct {
	Context string `json:"@context,omitempty"`
}

type ActorString struct {
	Actor string `json:"actor,omitempty"`
}

type ObjectArray struct {
	Object []ObjectBase `json:"object,omitempty"`
}

type Object struct {
	Object *ObjectBase `json:"object,omitempty"`
}

type ObjectString struct {
	Object string `json:"object,omitempty"`
}

type ToArray struct {
	To []string `json:"to,omitempty"`
}

type ToString struct {
	To string `json:"to,omitempty"`
}

type CcArray struct {
	Cc []string `json:"cc,omitempty"`
}

type CcOjectString struct {
	Cc string `json:"cc,omitempty"`
}

type Actor struct {
	Type              string       `json:"type,omitempty"`
	Id                string       `json:"id,omitempty"`
	Inbox             string       `json:"inbox,omitempty"`
	Outbox            string       `json:"outbox,omitempty"`
	Following         string       `json:"following,omitempty"`
	Followers         string       `json:"followers,omitempty"`
	Name              string       `json:"name,omitempty"`
	PreferredUsername string       `json:"preferredUsername,omitempty"`
	PublicKey         PublicKeyPem `json:"publicKey,omitempty"`
	Summary           string       `json:"summary,omitempty"`
	AuthRequirement   []string     `json:"authrequirement,omitempty"`
	Restricted        bool         `json:"restricted"`
}

type PublicKeyPem struct {
	Id           string `json:"id,omitempty"`
	Owner        string `json:"owner,omitempty"`
	PublicKeyPem string `json:"publicKeyPem,omitempty"`
}

type Activity struct {
	AtContext
	Type      string     `json:"type,omitempty"`
	Id        string     `json:"id,omitempty"`
	Actor     *Actor     `json:"actor,omitempty"`
	Name      string     `json:"name,omitempty"`
	Summary   string     `json:"summary,omitempty"`
	Auth      string     `json:"auth,omitempty"`
	To        []string   `json:"to,omitempty"`
	Bto       []string   `json:"bto,omitempty"`
	Cc        []string   `json:"cc,omitempty"`
	Published time.Time  `json:"published,omitempty"`
	Object    ObjectBase `json:"object,omitempty"`
}

type ObjectBase struct {
	Type         string            `json:"type,omitempty"`
	Id           string            `json:"id,omitempty"`
	Name         string            `json:"name,omitempty"`
	Option       []string          `json:"option,omitempty"`
	Alias        string            `json:"alias,omitempty"`
	AttributedTo string            `json:"attributedTo,omitempty"`
	TripCode     string            `json:"tripcode,omitempty"`
	Actor        string            `json:"actor,omitempty"`
	Audience     string            `json:"audience,omitempty"`
	ContentHTML  template.HTML     `json:"contenthtml,omitempty"`
	Content      string            `json:"content,omitempty"`
	EndTime      string            `json:"endTime,omitempty"`
	Generator    string            `json:"generator,omitempty"`
	Icon         string            `json:"icon,omitempty"`
	Image        string            `json:"image,omitempty"`
	InReplyTo    []ObjectBase      `json:"inReplyTo,omitempty"`
	Location     string            `json:"location,omitempty"`
	Preview      *NestedObjectBase `json:"preview,omitempty"`
	Published    time.Time         `json:"published,omitempty"`
	Updated      time.Time         `json:"updated,omitempty"`
	Object       *NestedObjectBase `json:"object,omitempty"`
	Attachment   []ObjectBase      `json:"attachment,omitempty"`
	Replies      CollectionBase    `json:"replies,omitempty"`
	StartTime    string            `json:"startTime,omitempty"`
	Summary      string            `json:"summary,omitempty"`
	Tag          []ObjectBase      `json:"tag,omitempty"`
	Wallet       []CryptoCur       `json:"wallet,omitempty"`
	Deleted      string            `json:"deleted,omitempty"`
	Url          []ObjectBase      `json:"url,omitempty"`
	Href         string            `json:"href,omitempty"`
	To           []string          `json:"to,omitempty"`
	Bto          []string          `json:"bto,omitempty"`
	Cc           []string          `json:"cc,omitempty"`
	Bcc          string            `json:"Bcc,omitempty"`
	MediaType    string            `json:"mediatype,omitempty"`
	Duration     string            `json:"duration,omitempty"`
	Size         int64             `json:"size,omitempty"`
	Sensitive    bool              `json:"sensitive,omitempty"`
	Sticky       bool              `json:"sticky,omitempty"`
	Locked       bool              `json:"locked,omitempty"`
}

type CryptoCur struct {
	Type    string `json:"type,omitempty"`
	Address string `json:"address,omitempty"`
}

type NestedObjectBase struct {
	AtContext
	Type         string          `json:"type,omitempty"`
	Id           string          `json:"id,omitempty"`
	Name         string          `json:"name,omitempty"`
	Alias        string          `json:"alias,omitempty"`
	AttributedTo string          `json:"attributedTo,omitempty"`
	TripCode     string          `json:"tripcode,omitempty"`
	Actor        string          `json:"actor,omitempty"`
	Audience     string          `json:"audience,omitempty"`
	ContentHTML  template.HTML   `json:"contenthtml,omitempty"`
	Content      string          `json:"content,omitempty"`
	EndTime      string          `json:"endTime,omitempty"`
	Generator    string          `json:"generator,omitempty"`
	Icon         string          `json:"icon,omitempty"`
	Image        string          `json:"image,omitempty"`
	InReplyTo    []ObjectBase    `json:"inReplyTo,omitempty"`
	Location     string          `json:"location,omitempty"`
	Preview      ObjectBase      `json:"preview,omitempty"`
	Published    time.Time       `json:"published,omitempty"`
	Attachment   []ObjectBase    `json:"attachment,omitempty"`
	Replies      *CollectionBase `json:"replies,omitempty"`
	StartTime    string          `json:"startTime,omitempty"`
	Summary      string          `json:"summary,omitempty"`
	Tag          []ObjectBase    `json:"tag,omitempty"`
	Updated      time.Time       `json:"updated,omitempty"`
	Deleted      string          `json:"deleted,omitempty"`
	Url          []ObjectBase    `json:"url,omitempty"`
	Href         string          `json:"href,omitempty"`
	To           []string        `json:"to,omitempty"`
	Bto          []string        `json:"bto,omitempty"`
	Cc           []string        `json:"cc,omitempty"`
	Bcc          string          `json:"Bcc,omitempty"`
	MediaType    string          `json:"mediatype,omitempty"`
	Duration     string          `json:"duration,omitempty"`
	Size         int64           `json:"size,omitempty"`
}

type CollectionBase struct {
	Actor        Actor        `json:"actor,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	Type         string       `json:"type,omitempty"`
	TotalItems   int          `json:"totalItems,omitempty"`
	TotalImgs    int          `json:"totalImgs,omitempty"`
	OrderedItems []ObjectBase `json:"orderedItems,omitempty"`
	Items        []ObjectBase `json:"items,omitempty"`
}

type Collection struct {
	AtContext
	CollectionBase
}

type ObjectBaseSortDesc []ObjectBase

func (a ObjectBaseSortDesc) Len() int           { return len(a) }
func (a ObjectBaseSortDesc) Less(i, j int) bool { return a[i].Updated.After(a[j].Updated) }
func (a ObjectBaseSortDesc) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type ObjectBaseSortAsc []ObjectBase

func (a ObjectBaseSortAsc) Len() int           { return len(a) }
func (a ObjectBaseSortAsc) Less(i, j int) bool { return a[i].Published.Before(a[j].Published) }
func (a ObjectBaseSortAsc) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }