Debian Codegraph @

responses.go

raw
1 package mautrix
2
3 import (
4 "maunium.net/go/mautrix/event"
5 "maunium.net/go/mautrix/id"
6 )
7
8 // RespWhoami is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3accountwhoami
9 type RespWhoami struct {
10 UserID id.UserID `json:"user_id"`
11 DeviceID id.DeviceID `json:"device_id"`
12 }
13
14 // RespCreateFilter is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3useruseridfilter
15 type RespCreateFilter struct {
16 FilterID string `json:"filter_id"`
17 }
18
19 // RespJoinRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidjoin
20 type RespJoinRoom struct {
21 RoomID id.RoomID `json:"room_id"`
22 }
23
24 // RespLeaveRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidleave
25 type RespLeaveRoom struct{}
26
27 // RespForgetRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidforget
28 type RespForgetRoom struct{}
29
30 // RespInviteUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidinvite
31 type RespInviteUser struct{}
32
33 // RespKickUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidkick
34 type RespKickUser struct{}
35
36 // RespBanUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidban
37 type RespBanUser struct{}
38
39 // RespUnbanUser is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidunban
40 type RespUnbanUser struct{}
41
42 // RespTyping is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidtypinguserid
43 type RespTyping struct{}
44
45 // RespPresence is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3presenceuseridstatus
46 type RespPresence struct {
47 Presence event.Presence `json:"presence"`
48 LastActiveAgo int `json:"last_active_ago"`
49 StatusMsg string `json:"status_msg"`
50 CurrentlyActive bool `json:"currently_active"`
51 }
52
53 // RespJoinedRooms is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3joined_rooms
54 type RespJoinedRooms struct {
55 JoinedRooms []id.RoomID `json:"joined_rooms"`
56 }
57
58 // RespJoinedMembers is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidjoined_members
59 type RespJoinedMembers struct {
60 Joined map[id.UserID]struct {
61 DisplayName *string `json:"display_name"`
62 AvatarURL *string `json:"avatar_url"`
63 } `json:"joined"`
64 }
65
66 // RespMessages is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidmessages
67 type RespMessages struct {
68 Start string `json:"start"`
69 Chunk []*event.Event `json:"chunk"`
70 State []*event.Event `json:"state"`
71 End string `json:"end"`
72 }
73
74 // RespContext is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3roomsroomidcontexteventid
75 type RespContext struct {
76 End string `json:"end"`
77 Event *event.Event `json:"event"`
78 EventsAfter []*event.Event `json:"events_after"`
79 EventsBefore []*event.Event `json:"events_before"`
80 Start string `json:"start"`
81 State []*event.Event `json:"state"`
82 }
83
84 // RespSendEvent is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid
85 type RespSendEvent struct {
86 EventID id.EventID `json:"event_id"`
87 }
88
89 // RespMediaUpload is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixmediav3upload
90 type RespMediaUpload struct {
91 ContentURI id.ContentURI `json:"content_uri"`
92 }
93
94 // RespCreateMXC is the JSON response for /_matrix/media/v3/create as specified in https://github.com/matrix-org/matrix-spec-proposals/pull/2246
95 type RespCreateMXC struct {
96 ContentURI id.ContentURI `json:"content_uri"`
97 UnusedExpiresAt int `json:"unused_expires_at,omitempty"`
98 }
99
100 // RespPreviewURL is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixmediav3preview_url
101 type RespPreviewURL struct {
102 CanonicalURL string `json:"og:url,omitempty"`
103 Title string `json:"og:title,omitempty"`
104 Type string `json:"og:type,omitempty"`
105 Description string `json:"og:description,omitempty"`
106
107 ImageURL id.ContentURIString `json:"og:image,omitempty"`
108
109 ImageSize int `json:"matrix:image:size,omitempty"`
110 ImageWidth int `json:"og:image:width,omitempty"`
111 ImageHeight int `json:"og:image:height,omitempty"`
112 ImageType string `json:"og:image:type,omitempty"`
113 }
114
115 // RespUserInteractive is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#user-interactive-authentication-api
116 type RespUserInteractive struct {
117 Flows []struct {
118 Stages []AuthType `json:"stages"`
119 } `json:"flows"`
120 Params map[AuthType]interface{} `json:"params"`
121 Session string `json:"session"`
122 Completed []string `json:"completed"`
123
124 ErrCode string `json:"errcode"`
125 Error string `json:"error"`
126 }
127
128 // HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName.
129 func (r RespUserInteractive) HasSingleStageFlow(stageName AuthType) bool {
130 for _, f := range r.Flows {
131 if len(f.Stages) == 1 && f.Stages[0] == stageName {
132 return true
133 }
134 }
135 return false
136 }
137
138 // RespUserDisplayName is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3profileuseriddisplayname
139 type RespUserDisplayName struct {
140 DisplayName string `json:"displayname"`
141 }
142
143 // RespRegister is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3register
144 type RespRegister struct {
145 AccessToken string `json:"access_token"`
146 DeviceID id.DeviceID `json:"device_id"`
147 HomeServer string `json:"home_server"`
148 RefreshToken string `json:"refresh_token"`
149 UserID id.UserID `json:"user_id"`
150 }
151
152 type LoginFlow struct {
153 Type AuthType `json:"type"`
154 }
155
156 // RespLoginFlows is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3login
157 type RespLoginFlows struct {
158 Flows []LoginFlow `json:"flows"`
159 }
160
161 func (rlf *RespLoginFlows) FirstFlowOfType(flowTypes ...AuthType) *LoginFlow {
162 for _, flow := range rlf.Flows {
163 for _, flowType := range flowTypes {
164 if flow.Type == flowType {
165 return &flow
166 }
167 }
168 }
169 return nil
170 }
171
172 func (rlf *RespLoginFlows) HasFlow(flowType ...AuthType) bool {
173 return rlf.FirstFlowOfType(flowType...) != nil
174 }
175
176 // RespLogin is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3login
177 type RespLogin struct {
178 AccessToken string `json:"access_token"`
179 DeviceID id.DeviceID `json:"device_id"`
180 UserID id.UserID `json:"user_id"`
181 WellKnown *ClientWellKnown `json:"well_known"`
182 }
183
184 // RespLogout is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3logout
185 type RespLogout struct{}
186
187 // RespCreateRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3createroom
188 type RespCreateRoom struct {
189 RoomID id.RoomID `json:"room_id"`
190 }
191
192 type RespMembers struct {
193 Chunk []*event.Event `json:"chunk"`
194 }
195
196 type LazyLoadSummary struct {
197 Heroes []id.UserID `json:"m.heroes,omitempty"`
198 JoinedMemberCount *int `json:"m.joined_member_count,omitempty"`
199 InvitedMemberCount *int `json:"m.invited_member_count,omitempty"`
200 }
201
202 // RespSync is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3sync
203 type RespSync struct {
204 NextBatch string `json:"next_batch"`
205
206 AccountData struct {
207 Events []*event.Event `json:"events"`
208 } `json:"account_data"`
209 Presence struct {
210 Events []*event.Event `json:"events"`
211 } `json:"presence"`
212 ToDevice struct {
213 Events []*event.Event `json:"events"`
214 } `json:"to_device"`
215
216 DeviceLists DeviceLists `json:"device_lists"`
217 DeviceOTKCount OTKCount `json:"device_one_time_keys_count"`
218
219 Rooms struct {
220 Leave map[id.RoomID]SyncLeftRoom `json:"leave"`
221 Join map[id.RoomID]SyncJoinedRoom `json:"join"`
222 Invite map[id.RoomID]SyncInvitedRoom `json:"invite"`
223 } `json:"rooms"`
224 }
225
226 type DeviceLists struct {
227 Changed []id.UserID `json:"changed"`
228 Left []id.UserID `json:"left"`
229 }
230
231 type OTKCount struct {
232 Curve25519 int `json:"curve25519"`
233 SignedCurve25519 int `json:"signed_curve25519"`
234
235 // For appservice OTK counts only: the user ID in question
236 UserID id.UserID `json:"-"`
237 DeviceID id.DeviceID `json:"-"`
238 }
239
240 type SyncLeftRoom struct {
241 Summary LazyLoadSummary `json:"summary"`
242 State struct {
243 Events []*event.Event `json:"events"`
244 } `json:"state"`
245 Timeline struct {
246 Events []*event.Event `json:"events"`
247 Limited bool `json:"limited"`
248 PrevBatch string `json:"prev_batch"`
249 } `json:"timeline"`
250 }
251
252 type SyncJoinedRoom struct {
253 Summary LazyLoadSummary `json:"summary"`
254 State struct {
255 Events []*event.Event `json:"events"`
256 } `json:"state"`
257 Timeline struct {
258 Events []*event.Event `json:"events"`
259 Limited bool `json:"limited"`
260 PrevBatch string `json:"prev_batch"`
261 } `json:"timeline"`
262 Ephemeral struct {
263 Events []*event.Event `json:"events"`
264 } `json:"ephemeral"`
265 AccountData struct {
266 Events []*event.Event `json:"events"`
267 } `json:"account_data"`
268 }
269
270 type SyncInvitedRoom struct {
271 Summary LazyLoadSummary `json:"summary"`
272 State struct {
273 Events []*event.Event `json:"events"`
274 } `json:"invite_state"`
275 }
276
277 type RespTurnServer struct {
278 Username string `json:"username"`
279 Password string `json:"password"`
280 TTL int `json:"ttl"`
281 URIs []string `json:"uris"`
282 }
283
284 type RespAliasCreate struct{}
285 type RespAliasDelete struct{}
286 type RespAliasResolve struct {
287 RoomID id.RoomID `json:"room_id"`
288 Servers []string `json:"servers"`
289 }
290 type RespAliasList struct {
291 Aliases []id.RoomAlias `json:"aliases"`
292 }
293
294 type RespUploadKeys struct {
295 OneTimeKeyCounts OTKCount `json:"one_time_key_counts"`
296 }
297
298 type RespQueryKeys struct {
299 Failures map[string]interface{} `json:"failures"`
300 DeviceKeys map[id.UserID]map[id.DeviceID]DeviceKeys `json:"device_keys"`
301 MasterKeys map[id.UserID]CrossSigningKeys `json:"master_keys"`
302 SelfSigningKeys map[id.UserID]CrossSigningKeys `json:"self_signing_keys"`
303 UserSigningKeys map[id.UserID]CrossSigningKeys `json:"user_signing_keys"`
304 }
305
306 type RespClaimKeys struct {
307 Failures map[string]interface{} `json:"failures"`
308 OneTimeKeys map[id.UserID]map[id.DeviceID]map[id.KeyID]OneTimeKey `json:"one_time_keys"`
309 }
310
311 type RespUploadSignatures struct {
312 Failures map[string]interface{} `json:"failures"`
313 }
314
315 type RespKeyChanges struct {
316 Changed []id.UserID `json:"changed"`
317 Left []id.UserID `json:"left"`
318 }
319
320 type RespSendToDevice struct{}
321
322 // RespDevicesInfo is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devices
323 type RespDevicesInfo struct {
324 Devices []RespDeviceInfo `json:"devices"`
325 }
326
327 // RespDeviceInfo is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3devicesdeviceid
328 type RespDeviceInfo struct {
329 DeviceID id.DeviceID `json:"device_id"`
330 DisplayName string `json:"display_name"`
331 LastSeenIP string `json:"last_seen_ip"`
332 LastSeenTS int64 `json:"last_seen_ts"`
333 }
334
335 type RespBatchSend struct {
336 StateEventIDs []id.EventID `json:"state_event_ids"`
337 EventIDs []id.EventID `json:"event_ids"`
338
339 InsertionEventID id.EventID `json:"insertion_event_id"`
340 BatchEventID id.EventID `json:"batch_event_id"`
341 BaseInsertionEventID id.EventID `json:"base_insertion_event_id"`
342
343 NextBatchID id.BatchID `json:"next_batch_id"`
344 }