types.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "time"
  6. "github.com/mk6i/open-oscar-server/state"
  7. "github.com/mk6i/open-oscar-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. // BuddyBroadcaster defines a method for broadcasting presence updates.
  39. type BuddyBroadcaster interface {
  40. // BroadcastVisibility sends presence updates to the specified filter list.
  41. // If sendDepartures is true, departure events are sent as well.
  42. BroadcastVisibility(ctx context.Context, you *state.SessionInstance, filter []state.IdentScreenName, sendDepartures bool) error
  43. }
  44. // ChatRoomCreator defines a method for creating a new chat room.
  45. type ChatRoomCreator interface {
  46. // CreateChatRoom creates a new chat room.
  47. CreateChatRoom(ctx context.Context, chatRoom *state.ChatRoom) error
  48. }
  49. // ChatRoomRetriever defines a method for retrieving all chat rooms
  50. // under a specific exchange.
  51. type ChatRoomRetriever interface {
  52. // AllChatRooms returns all chat rooms associated with the given exchange ID.
  53. AllChatRooms(ctx context.Context, exchange uint16) ([]state.ChatRoom, error)
  54. }
  55. // ChatRoomDeleter defines a method for deleting chat rooms.
  56. type ChatRoomDeleter interface {
  57. // DeleteChatRooms deletes chat rooms by their names under a specific exchange.
  58. DeleteChatRooms(ctx context.Context, exchange uint16, names []string) error
  59. }
  60. // ChatSessionRetriever defines a method for retrieving all sessions
  61. // associated with a specific chat room.
  62. type ChatSessionRetriever interface {
  63. // AllSessions returns all active sessions in the chat room identified by cookie.
  64. AllSessions(cookie string) []*state.Session
  65. }
  66. // DirectoryManager defines methods for managing interest categories and keywords
  67. // used in user profiles and directory listings.
  68. type DirectoryManager interface {
  69. // Categories returns all existing directory categories.
  70. Categories(ctx context.Context) ([]state.Category, error)
  71. // CreateCategory adds a new directory category.
  72. CreateCategory(ctx context.Context, name string) (state.Category, error)
  73. // CreateKeyword adds a new keyword to the specified category.
  74. CreateKeyword(ctx context.Context, name string, categoryID uint8) (state.Keyword, error)
  75. // DeleteCategory removes a directory category by ID.
  76. DeleteCategory(ctx context.Context, categoryID uint8) error
  77. // DeleteKeyword removes a keyword by ID.
  78. DeleteKeyword(ctx context.Context, id uint8) error
  79. // KeywordsByCategory returns all keywords under the specified category.
  80. KeywordsByCategory(ctx context.Context, categoryID uint8) ([]state.Keyword, error)
  81. }
  82. // FeedBagRetriever defines methods for retrieving buddy list metadata.
  83. type FeedBagRetriever interface {
  84. // BuddyIconMetadata retrieves a user's buddy icon metadata. It returns nil
  85. // if the user does not have a buddy icon.
  86. BuddyIconMetadata(ctx context.Context, screenName state.IdentScreenName) (*wire.BARTID, error)
  87. }
  88. // FeedbagManager defines methods for managing feedbag (buddy list) entries.
  89. // This interface matches foodgroup.FeedbagManager and is implemented by state.SQLiteUserStore.
  90. type FeedbagManager interface {
  91. // Feedbag retrieves all feedbag items for a user.
  92. Feedbag(ctx context.Context, screenName state.IdentScreenName) ([]wire.FeedbagItem, error)
  93. // FeedbagUpsert inserts or updates feedbag items.
  94. FeedbagUpsert(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  95. // FeedbagDelete deletes feedbag items.
  96. FeedbagDelete(ctx context.Context, screenName state.IdentScreenName, items []wire.FeedbagItem) error
  97. }
  98. // MessageRelayer defines a method for sending a SNAC message to a specific screen name.
  99. type MessageRelayer interface {
  100. // RelayToScreenName sends the given SNAC message to the specified screen name.
  101. RelayToScreenName(ctx context.Context, screenName state.IdentScreenName, msg wire.SNACMessage)
  102. }
  103. // ProfileRetriever defines a method for retrieving a user's free-form profile.
  104. type ProfileRetriever interface {
  105. // Profile returns the user's profile information for the given screen name.
  106. Profile(ctx context.Context, screenName state.IdentScreenName) (state.UserProfile, error)
  107. }
  108. // SessionRetriever defines methods for retrieving active sessions,
  109. // either all of them or by screen name.
  110. type SessionRetriever interface {
  111. // AllSessions returns all active user sessions.
  112. AllSessions() []*state.Session
  113. // RetrieveSession returns the session associated with the given screen name,
  114. // or nil if no active session exists. Returns the Session object if there
  115. // are active instances with complete signon.
  116. RetrieveSession(screenName state.IdentScreenName) *state.Session
  117. }
  118. // UserManager defines methods for accessing and inserting AIM user records.
  119. type UserManager interface {
  120. // AllUsers returns all registered users.
  121. AllUsers(ctx context.Context) ([]state.User, error)
  122. // DeleteUser removes a user from the system by screen name.
  123. DeleteUser(ctx context.Context, screenName state.IdentScreenName) error
  124. // InsertUser inserts a new user into the system. Return state.ErrDupUser
  125. // if a user with the same screen name already exists.
  126. InsertUser(ctx context.Context, u state.User) error
  127. // SetUserPassword sets the user's password hashes and auth key.
  128. SetUserPassword(ctx context.Context, screenName state.IdentScreenName, newPassword string) error
  129. // User returns all attributes for a user.
  130. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  131. }
  132. type userWithPassword struct {
  133. ScreenName string `json:"screen_name"`
  134. Password string `json:"password,omitempty"`
  135. }
  136. type onlineUsers struct {
  137. Count int `json:"count"`
  138. Sessions []sessionHandle `json:"sessions"`
  139. }
  140. type userHandle struct {
  141. ID string `json:"id"`
  142. ScreenName string `json:"screen_name"`
  143. IsICQ bool `json:"is_icq"`
  144. SuspendedStatus string `json:"suspended_status"`
  145. IsBot bool `json:"is_bot"`
  146. }
  147. type aimChatUserHandle struct {
  148. ID string `json:"id"`
  149. ScreenName string `json:"screen_name"`
  150. }
  151. type userAccountHandle struct {
  152. ID string `json:"id"`
  153. ScreenName string `json:"screen_name"`
  154. Profile string `json:"profile"`
  155. EmailAddress string `json:"email_address"`
  156. RegStatus uint16 `json:"reg_status"`
  157. Confirmed bool `json:"confirmed"`
  158. IsICQ bool `json:"is_icq"`
  159. SuspendedStatus string `json:"suspended_status"`
  160. IsBot bool `json:"is_bot"`
  161. }
  162. type userAccountPatch struct {
  163. SuspendedStatusText *string `json:"suspended_status"`
  164. IsBot *bool `json:"is_bot"`
  165. }
  166. type sessionHandle struct {
  167. ID string `json:"id"`
  168. ScreenName string `json:"screen_name"`
  169. OnlineSeconds int `json:"online_seconds"`
  170. IsAway bool `json:"is_away"`
  171. AwayMessage string `json:"away_message"`
  172. IdleSeconds int `json:"idle_seconds"`
  173. IsInvisible bool `json:"is_invisible"`
  174. IsICQ bool `json:"is_icq"`
  175. InstanceCount int `json:"instance_count"`
  176. Instances []instanceHandle `json:"instances"`
  177. }
  178. type instanceHandle struct {
  179. Num int `json:"num"`
  180. IdleSeconds int `json:"idle_seconds"`
  181. IsAway bool `json:"is_away"`
  182. AwayMessage string `json:"away_message"`
  183. IsInvisible bool `json:"is_invisible"`
  184. RemoteAddr string `json:"remote_addr"`
  185. RemotePort int `json:"remote_port"`
  186. }
  187. type chatRoomCreate struct {
  188. Name string `json:"name"`
  189. }
  190. type chatRoomDelete struct {
  191. Names []string `json:"names"`
  192. }
  193. type chatRoom struct {
  194. Name string `json:"name"`
  195. CreateTime time.Time `json:"create_time"`
  196. CreatorID string `json:"creator_id,omitempty"`
  197. URL string `json:"url"`
  198. Participants []aimChatUserHandle `json:"participants"`
  199. }
  200. type instantMessage struct {
  201. From string `json:"from"`
  202. To string `json:"to"`
  203. Text string `json:"text"`
  204. }
  205. type directoryKeyword struct {
  206. ID uint8 `json:"id"`
  207. Name string `json:"name"`
  208. }
  209. type directoryCategory struct {
  210. ID uint8 `json:"id"`
  211. Name string `json:"name"`
  212. }
  213. type directoryCategoryCreate struct {
  214. Name string `json:"name"`
  215. }
  216. type directoryKeywordCreate struct {
  217. CategoryID uint8 `json:"category_id"`
  218. Name string `json:"name"`
  219. }
  220. type messageBody struct {
  221. Message string `json:"message"`
  222. }
  223. // Web API key management types
  224. type createWebAPIKeyRequest struct {
  225. AppName string `json:"app_name"`
  226. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  227. RateLimit int `json:"rate_limit,omitempty"`
  228. Capabilities []string `json:"capabilities,omitempty"`
  229. }
  230. type webAPIKeyResponse struct {
  231. DevID string `json:"dev_id"`
  232. DevKey string `json:"dev_key,omitempty"` // Only shown on creation
  233. AppName string `json:"app_name"`
  234. CreatedAt time.Time `json:"created_at"`
  235. LastUsed *time.Time `json:"last_used,omitempty"`
  236. IsActive bool `json:"is_active"`
  237. RateLimit int `json:"rate_limit"`
  238. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  239. Capabilities []string `json:"capabilities,omitempty"`
  240. }
  241. type updateWebAPIKeyRequest struct {
  242. AppName *string `json:"app_name,omitempty"`
  243. IsActive *bool `json:"is_active,omitempty"`
  244. RateLimit *int `json:"rate_limit,omitempty"`
  245. AllowedOrigins *[]string `json:"allowed_origins,omitempty"`
  246. Capabilities *[]string `json:"capabilities,omitempty"`
  247. }