types.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "time"
  6. "github.com/mk6i/retro-aim-server/state"
  7. "github.com/mk6i/retro-aim-server/wire"
  8. )
  9. // AccountManager defines methods for managing user account attributes
  10. // such as email, confirmation status, registration status, and suspension.
  11. type AccountManager interface {
  12. // ConfirmStatus returns whether a user account has been confirmed.
  13. ConfirmStatus(ctx context.Context, screenName state.IdentScreenName) (bool, error)
  14. // EmailAddress looks up a user's email address by screen name.
  15. EmailAddress(ctx context.Context, screenName state.IdentScreenName) (*mail.Address, error)
  16. // RegStatus looks up a user's registration status by screen name.
  17. // It returns one of the following values:
  18. // - wire.AdminInfoRegStatusFullDisclosure
  19. // - wire.AdminInfoRegStatusLimitDisclosure
  20. // - wire.AdminInfoRegStatusNoDisclosure
  21. RegStatus(ctx context.Context, screenName state.IdentScreenName) (uint16, error)
  22. // UpdateSuspendedStatus updates the suspension status of a user account.
  23. UpdateSuspendedStatus(ctx context.Context, suspendedStatus uint16, screenName state.IdentScreenName) error
  24. // SetBotStatus updates the flag that indicates whether the user is a bot.
  25. SetBotStatus(ctx context.Context, isBot bool, screenName state.IdentScreenName) error
  26. }
  27. // BARTAssetManager defines methods for managing BART (Buddy ART) assets.
  28. type BARTAssetManager interface {
  29. // BARTItem retrieves a BART asset by its hash.
  30. BARTItem(ctx context.Context, hash []byte) ([]byte, error)
  31. // InsertBARTItem inserts a BART asset.
  32. InsertBARTItem(ctx context.Context, hash []byte, blob []byte, itemType uint16) error
  33. // ListBARTItems returns BART assets filtered by type.
  34. ListBARTItems(ctx context.Context, itemType uint16) ([]state.BARTItem, error)
  35. // DeleteBARTItem deletes a BART asset by hash.
  36. DeleteBARTItem(ctx context.Context, hash []byte) error
  37. }
  38. // ChatRoomCreator defines a method for creating a new chat room.
  39. type ChatRoomCreator interface {
  40. // CreateChatRoom creates a new chat room.
  41. CreateChatRoom(ctx context.Context, chatRoom *state.ChatRoom) error
  42. }
  43. // ChatRoomRetriever defines a method for retrieving all chat rooms
  44. // under a specific exchange.
  45. type ChatRoomRetriever interface {
  46. // AllChatRooms returns all chat rooms associated with the given exchange ID.
  47. AllChatRooms(ctx context.Context, exchange uint16) ([]state.ChatRoom, error)
  48. }
  49. // ChatRoomDeleter defines a method for deleting chat rooms.
  50. type ChatRoomDeleter interface {
  51. // DeleteChatRooms deletes chat rooms by their names under a specific exchange.
  52. DeleteChatRooms(ctx context.Context, exchange uint16, names []string) error
  53. }
  54. // ChatSessionRetriever defines a method for retrieving all sessions
  55. // associated with a specific chat room.
  56. type ChatSessionRetriever interface {
  57. // AllSessions returns all active sessions in the chat room identified by cookie.
  58. AllSessions(cookie string) []*state.Session
  59. }
  60. // DirectoryManager defines methods for managing interest categories and keywords
  61. // used in user profiles and directory listings.
  62. type DirectoryManager interface {
  63. // Categories returns all existing directory categories.
  64. Categories(ctx context.Context) ([]state.Category, error)
  65. // CreateCategory adds a new directory category.
  66. CreateCategory(ctx context.Context, name string) (state.Category, error)
  67. // CreateKeyword adds a new keyword to the specified category.
  68. CreateKeyword(ctx context.Context, name string, categoryID uint8) (state.Keyword, error)
  69. // DeleteCategory removes a directory category by ID.
  70. DeleteCategory(ctx context.Context, categoryID uint8) error
  71. // DeleteKeyword removes a keyword by ID.
  72. DeleteKeyword(ctx context.Context, id uint8) error
  73. // KeywordsByCategory returns all keywords under the specified category.
  74. KeywordsByCategory(ctx context.Context, categoryID uint8) ([]state.Keyword, error)
  75. }
  76. // FeedBagRetriever defines methods for retrieving buddy list metadata.
  77. type FeedBagRetriever interface {
  78. // BuddyIconMetadata retrieves a user's buddy icon metadata. It returns nil
  79. // if the user does not have a buddy icon.
  80. BuddyIconMetadata(ctx context.Context, screenName state.IdentScreenName) (*wire.BARTID, error)
  81. }
  82. // MessageRelayer defines a method for sending a SNAC message to a specific screen name.
  83. type MessageRelayer interface {
  84. // RelayToScreenName sends the given SNAC message to the specified screen name.
  85. RelayToScreenName(ctx context.Context, screenName state.IdentScreenName, msg wire.SNACMessage)
  86. }
  87. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  88. type ProfileRetriever interface {
  89. // Profile returns the user's profile information for the given screen name.
  90. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  91. }
  92. // SessionRetriever defines methods for retrieving active sessions,
  93. // either all of them or by screen name.
  94. type SessionRetriever interface {
  95. // AllSessions returns all active user sessions.
  96. AllSessions() []*state.Session
  97. // RetrieveSession returns the session associated with the given screen name,
  98. // or nil if no active session exists.
  99. RetrieveSession(screenName state.IdentScreenName) *state.Session
  100. }
  101. // UserManager defines methods for accessing and inserting AIM user records.
  102. type UserManager interface {
  103. // AllUsers returns all registered users.
  104. AllUsers(ctx context.Context) ([]state.User, error)
  105. // DeleteUser removes a user from the system by screen name.
  106. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  107. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  108. // if a user with the same screen name already exists.
  109. InsertUser(ctx context.Context, u state.User) error
  110. // SetUserPassword sets the user's password hashes and auth key.
  111. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  112. // User returns all attributes for a user.
  113. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  114. }
  115. type userWithPassword struct {
  116. ScreenName string `json:"screen_name"`
  117. Password string `json:"password,omitempty"`
  118. }
  119. type onlineUsers struct {
  120. Count int `json:"count"`
  121. Sessions []sessionHandle `json:"sessions"`
  122. }
  123. type userHandle struct {
  124. ID string `json:"id"`
  125. ScreenName string `json:"screen_name"`
  126. IsICQ bool `json:"is_icq"`
  127. SuspendedStatus string `json:"suspended_status"`
  128. IsBot bool `json:"is_bot"`
  129. }
  130. type aimChatUserHandle struct {
  131. ID string `json:"id"`
  132. ScreenName string `json:"screen_name"`
  133. }
  134. type userAccountHandle struct {
  135. ID string `json:"id"`
  136. ScreenName string `json:"screen_name"`
  137. Profile string `json:"profile"`
  138. EmailAddress string `json:"email_address"`
  139. RegStatus uint16 `json:"reg_status"`
  140. Confirmed bool `json:"confirmed"`
  141. IsICQ bool `json:"is_icq"`
  142. SuspendedStatus string `json:"suspended_status"`
  143. IsBot bool `json:"is_bot"`
  144. }
  145. type userAccountPatch struct {
  146. SuspendedStatusText *string `json:"suspended_status"`
  147. IsBot *bool `json:"is_bot"`
  148. }
  149. type sessionHandle struct {
  150. ID string `json:"id"`
  151. ScreenName string `json:"screen_name"`
  152. OnlineSeconds float64 `json:"online_seconds"`
  153. AwayMessage string `json:"away_message"`
  154. IdleSeconds float64 `json:"idle_seconds"`
  155. IsICQ bool `json:"is_icq"`
  156. RemoteAddr string `json:"remote_addr,omitempty"`
  157. RemotePort uint16 `json:"remote_port,omitempty"`
  158. }
  159. type chatRoomCreate struct {
  160. Name string `json:"name"`
  161. }
  162. type chatRoomDelete struct {
  163. Names []string `json:"names"`
  164. }
  165. type chatRoom struct {
  166. Name string `json:"name"`
  167. CreateTime time.Time `json:"create_time"`
  168. CreatorID string `json:"creator_id,omitempty"`
  169. URL string `json:"url"`
  170. Participants []aimChatUserHandle `json:"participants"`
  171. }
  172. type instantMessage struct {
  173. From string `json:"from"`
  174. To string `json:"to"`
  175. Text string `json:"text"`
  176. }
  177. type directoryKeyword struct {
  178. ID uint8 `json:"id"`
  179. Name string `json:"name"`
  180. }
  181. type directoryCategory struct {
  182. ID uint8 `json:"id"`
  183. Name string `json:"name"`
  184. }
  185. type directoryCategoryCreate struct {
  186. Name string `json:"name"`
  187. }
  188. type directoryKeywordCreate struct {
  189. CategoryID uint8 `json:"category_id"`
  190. Name string `json:"name"`
  191. }
  192. type messageBody struct {
  193. Message string `json:"message"`
  194. }
  195. // Web API key management types
  196. type createWebAPIKeyRequest struct {
  197. AppName string `json:"app_name"`
  198. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  199. RateLimit int `json:"rate_limit,omitempty"`
  200. Capabilities []string `json:"capabilities,omitempty"`
  201. }
  202. type webAPIKeyResponse struct {
  203. DevID string `json:"dev_id"`
  204. DevKey string `json:"dev_key,omitempty"` // Only shown on creation
  205. AppName string `json:"app_name"`
  206. CreatedAt time.Time `json:"created_at"`
  207. LastUsed *time.Time `json:"last_used,omitempty"`
  208. IsActive bool `json:"is_active"`
  209. RateLimit int `json:"rate_limit"`
  210. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  211. Capabilities []string `json:"capabilities,omitempty"`
  212. }
  213. type updateWebAPIKeyRequest struct {
  214. AppName *string `json:"app_name,omitempty"`
  215. IsActive *bool `json:"is_active,omitempty"`
  216. RateLimit *int `json:"rate_limit,omitempty"`
  217. AllowedOrigins *[]string `json:"allowed_origins,omitempty"`
  218. Capabilities *[]string `json:"capabilities,omitempty"`
  219. }