types.go 7.4 KB

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