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
|
package mastodon
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"within.website/x/web/mastosan"
)
// types copied from here: https://github.com/McKael/madon/blob/master/types.go
// MastodonDate is a custom type for the timestamps returned by some API calls
// It is used, for example, by 'v1/instance/activity' and 'v2/search'.
// The date returned by those Mastodon API calls is a string containing a
// timestamp in seconds
type MastodonDate struct {
time.Time
}
// UnmarshalJSON handles deserialization for custom MastodonDate type
func (act *MastodonDate) UnmarshalJSON(b []byte) error {
s, err := strconv.ParseInt(strings.Trim(string(b), "\""), 10, 64)
if err != nil {
return err
}
if s == 0 {
act.Time = time.Unix(0, 0)
return nil
}
act.Time = time.Unix(s, 0)
return nil
}
// MarshalJSON handles serialization for custom MastodonDate type
func (act *MastodonDate) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%d\"", act.Unix())), nil
}
// DomainName is a domain name string, as returned by the domain_blocks API
type DomainName string
// InstancePeer is a peer name, as returned by the instance/peers API
type InstancePeer string
// Account represents a Mastodon account entity
type Account struct {
ID string `json:"id"`
Username string `json:"username"`
Acct string `json:"acct"`
DisplayName string `json:"display_name"`
Note string `json:"note"`
URL string `json:"url"`
Avatar string `json:"avatar"`
AvatarStatic string `json:"avatar_static"`
Header string `json:"header"`
HeaderStatic string `json:"header_static"`
Locked bool `json:"locked"`
CreatedAt time.Time `json:"created_at"`
FollowersCount int64 `json:"followers_count"`
FollowingCount int64 `json:"following_count"`
StatusesCount int64 `json:"statuses_count"`
Moved *Account `json:"moved"`
Bot bool `json:"bot"`
Emojis []Emoji `json:"emojis"`
Fields *[]Field `json:"fields"`
Source *SourceParams `json:"source"`
}
// Announcement is a single server announcement.
type Announcement struct {
ID string `json:"id"`
Content string `json:"content"`
StartsAt *time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at"`
AllDay bool `json:"all_day"`
PublishedAt time.Time `json:"published_at"`
UpdatedAt *time.Time `json:"updated_at"`
Read bool `json:"read"`
// TODO(Xe): handle mentions, status, tags, emojis, reactions
}
// Application represents a Mastodon application entity
type Application struct {
Name string `json:"name"`
Website string `json:"website"`
}
// Attachment represents a Mastodon media attachment entity
type Attachment struct {
ID string `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
RemoteURL *string `json:"remote_url"`
PreviewURL string `json:"preview_url"`
TextURL *string `json:"text_url"`
Meta *struct {
Original struct {
Size string `json:"size"`
Aspect float64 `json:"aspect"`
Width int `json:"width"`
Height int `json:"height"`
} `json:"original"`
Small struct {
Size string `json:"size"`
Aspect float64 `json:"aspect"`
Width int `json:"width"`
Height int `json:"height"`
} `json:"small"`
} `json:"meta"`
Description *string `json:"description"`
}
// Card represents a Mastodon preview card entity
type Card struct {
URL string `json:"url"`
Title string `json:"title"`
Description string `json:"description"`
Image string `json:"image"`
Type *string `json:"type"`
AuthorName *string `json:"author_name"`
AuthorURL *string `json:"author_url"`
ProviderName *string `json:"provider_name"`
ProviderURL *string `json:"provider_url"`
EmbedURL *string `json:"embed_url"`
HTML *string `json:"html"`
Width *int `json:"width"`
Height *int `json:"height"`
}
// Context represents a Mastodon context entity
type Context struct {
Ancestors []Status `json:"ancestors"`
Descendants []Status `json:"descendants"`
}
// Conversation represents a conversation with "direct message" visibility.
type Conversation struct {
ID string `json:"id"`
Unread bool `json:"unread"`
Accounts []Account `json:"accounts"`
LastStatus *Status `json:"status"`
}
// Emoji represents a Mastodon emoji entity
type Emoji struct {
ShortCode string `json:"shortcode"`
URL string `json:"url"`
StaticURL string `json:"static_url"`
VisibleInPicker bool `json:"visible_in_picker"`
}
// EmojiReaction represents an emoji reaction to an announcement.
type EmojiReaction struct {
Name string `json:"name"`
Count int `json:"count"`
AnnouncementID string `json:"announcement_id"`
}
// Error represents a Mastodon error entity
type Error struct {
Text string `json:"error"`
}
// Instance represents a Mastodon instance entity
type Instance struct {
URI string `json:"uri"`
Title string `json:"title"`
Description string `json:"description"`
Email string `json:"email"`
Version string `json:"version"`
URLs struct {
SteamingAPI string `json:"streaming_api"`
} `json:"urls"`
Stats struct {
UserCount int64 `json:"user_count"`
StatusCount int64 `json:"status_count"`
DomainCount int64 `json:"domain_count"`
} `json:"stats"`
Thumbnail *string `json:"thumbnail"`
Languages []string `json:"languages"`
ContactAccount *Account `json:"contact_account"`
}
// List represents a Mastodon list entity
type List struct {
ID string `json:"id"`
Title string `json:"title"`
}
// Mention represents a Mastodon mention entity
type Mention struct {
ID string `json:"id"`
URL string `json:"url"`
Username string `json:"username"`
Acct string `json:"acct"`
}
// Notification represents a Mastodon notification entity
type Notification struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
Account *Account `json:"account"`
Status *Status `json:"status"`
}
// Relationship represents a Mastodon relationship entity
type Relationship struct {
ID string `json:"id"`
Following bool `json:"following"`
//ShowingReblogs bool `json:"showing_reblogs"` // Incoherent type
FollowedBy bool `json:"followed_by"`
Blocking bool `json:"blocking"`
Muting bool `json:"muting"`
Requested bool `json:"requested"`
DomainBlocking bool `jsin:"domain_blocking"`
MutingNotifications bool `json:"muting_notifications"`
ShowingReblogs bool `json:"showing_reblogs"`
Endorsed bool `json:"endorsed"`
}
// Report represents a Mastodon report entity
type Report struct {
ID string `json:"id"`
ActionTaken string `json:"action_taken"`
}
// Results represents a Mastodon search results entity
type Results struct {
Accounts []Account `json:"accounts"`
Statuses []Status `json:"statuses"`
Hashtags []Tag `json:"hashtags"`
}
// Status represents a Mastodon status entity
type Status struct {
ID string `json:"id"`
URI string `json:"uri"`
URL string `json:"url"`
Account *Account `json:"account"`
InReplyToID *string `json:"in_reply_to_id"`
InReplyToAccountID *string `json:"in_reply_to_account_id"`
Reblog *Status `json:"reblog"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
ReblogsCount int64 `json:"reblogs_count"`
FavouritesCount int64 `json:"favourites_count"`
RepliesCount int64 `json:"replies_count"`
Reblogged bool `json:"reblogged"`
Favourited bool `json:"favourited"`
Muted bool `json:"muted"`
Pinned bool `json:"pinned"`
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
MediaAttachments []Attachment `json:"media_attachments"`
Mentions []Mention `json:"mentions"`
Tags []Tag `json:"tags"`
Emojis []Emoji `json:"emojis"`
Application *Application `json:"application"`
Language *string `json:"language"`
}
// ContentText attempts to convert the Status content to plain text using package
// mastosan.
func (s Status) ContentText(ctx context.Context) (string, error) {
return mastosan.Text(ctx, s.Content)
}
// Tag represents a Mastodon tag entity
type Tag struct {
Name string `json:"name"`
URL string `json:"url"`
History []struct {
Day MastodonDate `json:"day"`
Uses int64 `json:"uses,string"`
Accounts int64 `json:"accounts,string"`
} `json:"history"`
}
// WeekActivity represents a Mastodon instance activity "week" entity
type WeekActivity struct {
Week MastodonDate `json:"week"`
Statuses int64 `json:"statuses,string"`
Logins int64 `json:"logins,string"`
Registrations int64 `json:"registrations,string"`
}
// Field is a single field structure
// (Used for the verify_credentials endpoint)
type Field struct {
Name string `json:"name"`
Value string `json:"value"`
}
// SourceParams is a source params structure
type SourceParams struct { // Used for verify_credentials
Privacy *string `json:"privacy,omitempty"`
Language *string `json:"language,omitempty"`
Sensitive *bool `json:"sensitive,omitempty"`
Note *string `json:"note,omitempty"`
Fields *[]Field `json:"fields,omitempty"`
}
|