types.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. // BuddyIconRetriever defines a method for retrieving a buddy icon image by its hash.
  28. type BuddyIconRetriever interface {
  29. // BuddyIcon retrieves a buddy icon image by its md5 hash.
  30. BuddyIcon(ctx context.Context, itemHash []byte) ([]byte, error)
  31. }
  32. // ChatRoomCreator defines a method for creating a new chat room.
  33. type ChatRoomCreator interface {
  34. // CreateChatRoom creates a new chat room.
  35. CreateChatRoom(ctx context.Context, chatRoom *state.ChatRoom) error
  36. }
  37. // ChatRoomRetriever defines a method for retrieving all chat rooms
  38. // under a specific exchange.
  39. type ChatRoomRetriever interface {
  40. // AllChatRooms returns all chat rooms associated with the given exchange ID.
  41. AllChatRooms(ctx context.Context, exchange uint16) ([]state.ChatRoom, error)
  42. }
  43. // ChatSessionRetriever defines a method for retrieving all sessions
  44. // associated with a specific chat room.
  45. type ChatSessionRetriever interface {
  46. // AllSessions returns all active sessions in the chat room identified by cookie.
  47. AllSessions(cookie string) []*state.Session
  48. }
  49. // DirectoryManager defines methods for managing interest categories and keywords
  50. // used in user profiles and directory listings.
  51. type DirectoryManager interface {
  52. // Categories returns all existing directory categories.
  53. Categories(ctx context.Context) ([]state.Category, error)
  54. // CreateCategory adds a new directory category.
  55. CreateCategory(ctx context.Context, name string) (state.Category, error)
  56. // CreateKeyword adds a new keyword to the specified category.
  57. CreateKeyword(ctx context.Context, name string, categoryID uint8) (state.Keyword, error)
  58. // DeleteCategory removes a directory category by ID.
  59. DeleteCategory(ctx context.Context, categoryID uint8) error
  60. // DeleteKeyword removes a keyword by ID.
  61. DeleteKeyword(ctx context.Context, id uint8) error
  62. // KeywordsByCategory returns all keywords under the specified category.
  63. KeywordsByCategory(ctx context.Context, categoryID uint8) ([]state.Keyword, error)
  64. }
  65. // FeedBagRetriever defines methods for retrieving buddy list metadata.
  66. type FeedBagRetriever interface {
  67. // BuddyIconMetadata retrieves a user's buddy icon metadata. It returns nil
  68. // if the user does not have a buddy icon.
  69. BuddyIconMetadata(ctx context.Context, screenName state.IdentScreenName) (*wire.BARTID, error)
  70. }
  71. // MessageRelayer defines a method for sending a SNAC message to a specific screen name.
  72. type MessageRelayer interface {
  73. // RelayToScreenName sends the given SNAC message to the specified screen name.
  74. RelayToScreenName(ctx context.Context, screenName state.IdentScreenName, msg wire.SNACMessage)
  75. }
  76. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  77. type ProfileRetriever interface {
  78. // Profile returns the free-form profile body for the given screen name.
  79. Profile(ctx context.Context, screenName state.IdentScreenName) (string, error)
  80. }
  81. // SessionRetriever defines methods for retrieving active sessions,
  82. // either all of them or by screen name.
  83. type SessionRetriever interface {
  84. // AllSessions returns all active user sessions.
  85. AllSessions() []*state.Session
  86. // RetrieveSession returns the session associated with the given screen name,
  87. // or nil if no active session exists.
  88. RetrieveSession(screenName state.IdentScreenName) *state.Session
  89. }
  90. // UserManager defines methods for accessing and inserting AIM user records.
  91. type UserManager interface {
  92. // AllUsers returns all registered users.
  93. AllUsers(ctx context.Context) ([]state.User, error)
  94. // DeleteUser removes a user from the system by screen name.
  95. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  96. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  97. // if a user with the same screen name already exists.
  98. InsertUser(ctx context.Context, u state.User) error
  99. // SetUserPassword sets the user's password hashes and auth key.
  100. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  101. // User returns all attributes for a user.
  102. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  103. }
  104. type userWithPassword struct {
  105. ScreenName string `json:"screen_name"`
  106. Password string `json:"password,omitempty"`
  107. }
  108. type onlineUsers struct {
  109. Count int `json:"count"`
  110. Sessions []sessionHandle `json:"sessions"`
  111. }
  112. type userHandle struct {
  113. ID string `json:"id"`
  114. ScreenName string `json:"screen_name"`
  115. IsICQ bool `json:"is_icq"`
  116. SuspendedStatus string `json:"suspended_status"`
  117. IsBot bool `json:"is_bot"`
  118. }
  119. type aimChatUserHandle struct {
  120. ID string `json:"id"`
  121. ScreenName string `json:"screen_name"`
  122. }
  123. type userAccountHandle struct {
  124. ID string `json:"id"`
  125. ScreenName string `json:"screen_name"`
  126. Profile string `json:"profile"`
  127. EmailAddress string `json:"email_address"`
  128. RegStatus uint16 `json:"reg_status"`
  129. Confirmed bool `json:"confirmed"`
  130. IsICQ bool `json:"is_icq"`
  131. SuspendedStatus string `json:"suspended_status"`
  132. IsBot bool `json:"is_bot"`
  133. }
  134. type userAccountPatch struct {
  135. SuspendedStatusText *string `json:"suspended_status"`
  136. IsBot *bool `json:"is_bot"`
  137. }
  138. type sessionHandle struct {
  139. ID string `json:"id"`
  140. ScreenName string `json:"screen_name"`
  141. OnlineSeconds float64 `json:"online_seconds"`
  142. AwayMessage string `json:"away_message"`
  143. IdleSeconds float64 `json:"idle_seconds"`
  144. IsICQ bool `json:"is_icq"`
  145. RemoteAddr string `json:"remote_addr,omitempty"`
  146. RemotePort uint16 `json:"remote_port,omitempty"`
  147. }
  148. type chatRoomCreate struct {
  149. Name string `json:"name"`
  150. }
  151. type chatRoom struct {
  152. Name string `json:"name"`
  153. CreateTime time.Time `json:"create_time"`
  154. CreatorID string `json:"creator_id,omitempty"`
  155. URL string `json:"url"`
  156. Participants []aimChatUserHandle `json:"participants"`
  157. }
  158. type instantMessage struct {
  159. From string `json:"from"`
  160. To string `json:"to"`
  161. Text string `json:"text"`
  162. }
  163. type directoryKeyword struct {
  164. ID uint8 `json:"id"`
  165. Name string `json:"name"`
  166. }
  167. type directoryCategory struct {
  168. ID uint8 `json:"id"`
  169. Name string `json:"name"`
  170. }
  171. type directoryCategoryCreate struct {
  172. Name string `json:"name"`
  173. }
  174. type directoryKeywordCreate struct {
  175. CategoryID uint8 `json:"category_id"`
  176. Name string `json:"name"`
  177. }
  178. type messageBody struct {
  179. Message string `json:"message"`
  180. }