responses.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package gomatrix
  2. // RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface.
  3. // See http://matrix.org/docs/spec/client_server/r0.2.0.html#api-standards
  4. type RespError struct {
  5. ErrCode string `json:"errcode"`
  6. Err string `json:"error"`
  7. }
  8. // Error returns the errcode and error message.
  9. func (e RespError) Error() string {
  10. return e.ErrCode + ": " + e.Err
  11. }
  12. // RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter
  13. type RespCreateFilter struct {
  14. FilterID string `json:"filter_id"`
  15. }
  16. // RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions
  17. type RespVersions struct {
  18. Versions []string `json:"versions"`
  19. }
  20. // RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join
  21. type RespJoinRoom struct {
  22. RoomID string `json:"room_id"`
  23. }
  24. // RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave
  25. type RespLeaveRoom struct{}
  26. // RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget
  27. type RespForgetRoom struct{}
  28. // RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
  29. type RespInviteUser struct{}
  30. // RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
  31. type RespKickUser struct{}
  32. // RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
  33. type RespBanUser struct{}
  34. // RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
  35. type RespUnbanUser struct{}
  36. // RespTyping is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid
  37. type RespTyping struct{}
  38. // RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680
  39. type RespJoinedRooms struct {
  40. JoinedRooms []string `json:"joined_rooms"`
  41. }
  42. // RespJoinedMembers is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680
  43. type RespJoinedMembers struct {
  44. Joined map[string]struct {
  45. DisplayName *string `json:"display_name"`
  46. AvatarURL *string `json:"avatar_url"`
  47. } `json:"joined"`
  48. }
  49. // RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages
  50. type RespMessages struct {
  51. Start string `json:"start"`
  52. Chunk []*Event `json:"chunk"`
  53. End string `json:"end"`
  54. }
  55. // RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
  56. type RespSendEvent struct {
  57. EventID string `json:"event_id"`
  58. }
  59. // RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload
  60. type RespMediaUpload struct {
  61. ContentURI string `json:"content_uri"`
  62. }
  63. // RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api
  64. type RespUserInteractive struct {
  65. Flows []struct {
  66. Stages []string `json:"stages"`
  67. } `json:"flows"`
  68. Params map[string]interface{} `json:"params"`
  69. Session string `json:"string"`
  70. Completed []string `json:"completed"`
  71. ErrCode string `json:"errcode"`
  72. Error string `json:"error"`
  73. }
  74. // HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName.
  75. func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool {
  76. for _, f := range r.Flows {
  77. if len(f.Stages) == 1 && f.Stages[0] == stageName {
  78. return true
  79. }
  80. }
  81. return false
  82. }
  83. // RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname
  84. type RespUserDisplayName struct {
  85. DisplayName string `json:"displayname"`
  86. }
  87. // RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register
  88. type RespRegister struct {
  89. AccessToken string `json:"access_token"`
  90. DeviceID string `json:"device_id"`
  91. HomeServer string `json:"home_server"`
  92. RefreshToken string `json:"refresh_token"`
  93. UserID string `json:"user_id"`
  94. }
  95. // RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login
  96. type RespLogin struct {
  97. AccessToken string `json:"access_token"`
  98. DeviceID string `json:"device_id"`
  99. HomeServer string `json:"home_server"`
  100. UserID string `json:"user_id"`
  101. }
  102. // RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout
  103. type RespLogout struct{}
  104. // RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
  105. type RespCreateRoom struct {
  106. RoomID string `json:"room_id"`
  107. }
  108. // RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync
  109. type RespSync struct {
  110. NextBatch string `json:"next_batch"`
  111. AccountData struct {
  112. Events []*Event `json:"events"`
  113. } `json:"account_data"`
  114. Presence struct {
  115. Events []*Event `json:"events"`
  116. } `json:"presence"`
  117. Rooms struct {
  118. Leave map[string]struct {
  119. State struct {
  120. Events []*Event `json:"events"`
  121. } `json:"state"`
  122. Timeline struct {
  123. Events []*Event `json:"events"`
  124. Limited bool `json:"limited"`
  125. PrevBatch string `json:"prev_batch"`
  126. } `json:"timeline"`
  127. } `json:"leave"`
  128. Join map[string]struct {
  129. State struct {
  130. Events []*Event `json:"events"`
  131. } `json:"state"`
  132. Timeline struct {
  133. Events []*Event `json:"events"`
  134. Limited bool `json:"limited"`
  135. PrevBatch string `json:"prev_batch"`
  136. } `json:"timeline"`
  137. Ephemeral struct {
  138. Events []*Event `json:"events"`
  139. } `json:"ephemeral"`
  140. AccountData struct {
  141. Events []*Event `json:"events"`
  142. } `json:"account_data"`
  143. } `json:"join"`
  144. Invite map[string]struct {
  145. State struct {
  146. Events []*Event `json:"events"`
  147. } `json:"invite_state"`
  148. } `json:"invite"`
  149. } `json:"rooms"`
  150. }
  151. type RespTurnServer struct {
  152. Username string `json:"username"`
  153. Password string `json:"password"`
  154. TTL int `json:"ttl"`
  155. URIs []string `json:"uris"`
  156. }