types.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. // ICQProfileManager defines methods for getting and setting ICQ user profile data.
  133. type ICQProfileManager interface {
  134. // User returns all attributes for a user.
  135. User(ctx context.Context, screenName state.IdentScreenName) (*state.User, error)
  136. // SetBasicInfo updates the user's basic ICQ profile info.
  137. SetBasicInfo(ctx context.Context, name state.IdentScreenName, data state.ICQBasicInfo) error
  138. // SetMoreInfo updates the user's additional ICQ info.
  139. SetMoreInfo(ctx context.Context, name state.IdentScreenName, data state.ICQMoreInfo) error
  140. // SetWorkInfo updates the user's work info.
  141. SetWorkInfo(ctx context.Context, name state.IdentScreenName, data state.ICQWorkInfo) error
  142. // SetUserNotes updates the user's notes.
  143. SetUserNotes(ctx context.Context, name state.IdentScreenName, data state.ICQUserNotes) error
  144. // SetInterests updates the user's interests.
  145. SetInterests(ctx context.Context, name state.IdentScreenName, data state.ICQInterests) error
  146. // SetAffiliations updates the user's affiliations.
  147. SetAffiliations(ctx context.Context, name state.IdentScreenName, data state.ICQAffiliations) error
  148. // SetPermissions updates the user's privacy permissions.
  149. SetPermissions(ctx context.Context, name state.IdentScreenName, data state.ICQPermissions) error
  150. // SetICQInfo updates all ICQ profile columns for the user in one operation.
  151. SetICQInfo(ctx context.Context, name state.IdentScreenName, info state.ICQInfo) error
  152. }
  153. type userWithPassword struct {
  154. ScreenName string `json:"screen_name"`
  155. Password string `json:"password,omitempty"`
  156. }
  157. type onlineUsers struct {
  158. Count int `json:"count"`
  159. Sessions []sessionHandle `json:"sessions"`
  160. }
  161. type userHandle struct {
  162. ID string `json:"id"`
  163. ScreenName string `json:"screen_name"`
  164. IsICQ bool `json:"is_icq"`
  165. SuspendedStatus string `json:"suspended_status"`
  166. IsBot bool `json:"is_bot"`
  167. }
  168. type aimChatUserHandle struct {
  169. ID string `json:"id"`
  170. ScreenName string `json:"screen_name"`
  171. }
  172. type userAccountHandle struct {
  173. ID string `json:"id"`
  174. ScreenName string `json:"screen_name"`
  175. Profile string `json:"profile"`
  176. EmailAddress string `json:"email_address"`
  177. RegStatus uint16 `json:"reg_status"`
  178. Confirmed bool `json:"confirmed"`
  179. IsICQ bool `json:"is_icq"`
  180. SuspendedStatus string `json:"suspended_status"`
  181. IsBot bool `json:"is_bot"`
  182. }
  183. type userAccountPatch struct {
  184. SuspendedStatusText *string `json:"suspended_status"`
  185. IsBot *bool `json:"is_bot"`
  186. }
  187. type sessionHandle struct {
  188. ID string `json:"id"`
  189. ScreenName string `json:"screen_name"`
  190. OnlineSeconds int `json:"online_seconds"`
  191. IsAway bool `json:"is_away"`
  192. AwayMessage string `json:"away_message"`
  193. IdleSeconds int `json:"idle_seconds"`
  194. IsInvisible bool `json:"is_invisible"`
  195. IsICQ bool `json:"is_icq"`
  196. InstanceCount int `json:"instance_count"`
  197. Instances []instanceHandle `json:"instances"`
  198. }
  199. type instanceHandle struct {
  200. Num int `json:"num"`
  201. IdleSeconds int `json:"idle_seconds"`
  202. IsAway bool `json:"is_away"`
  203. AwayMessage string `json:"away_message"`
  204. IsInvisible bool `json:"is_invisible"`
  205. RemoteAddr string `json:"remote_addr"`
  206. RemotePort int `json:"remote_port"`
  207. }
  208. type chatRoomCreate struct {
  209. Name string `json:"name"`
  210. }
  211. type chatRoomDelete struct {
  212. Names []string `json:"names"`
  213. }
  214. type chatRoom struct {
  215. Name string `json:"name"`
  216. CreateTime time.Time `json:"create_time"`
  217. CreatorID string `json:"creator_id,omitempty"`
  218. URL string `json:"url"`
  219. Participants []aimChatUserHandle `json:"participants"`
  220. }
  221. type instantMessage struct {
  222. From string `json:"from"`
  223. To string `json:"to"`
  224. Text string `json:"text"`
  225. }
  226. type directoryKeyword struct {
  227. ID uint8 `json:"id"`
  228. Name string `json:"name"`
  229. }
  230. type directoryCategory struct {
  231. ID uint8 `json:"id"`
  232. Name string `json:"name"`
  233. }
  234. type directoryCategoryCreate struct {
  235. Name string `json:"name"`
  236. }
  237. type directoryKeywordCreate struct {
  238. CategoryID uint8 `json:"category_id"`
  239. Name string `json:"name"`
  240. }
  241. type messageBody struct {
  242. Message string `json:"message"`
  243. }
  244. type feedbagGroupHandle struct {
  245. GroupID uint16 `json:"group_id"`
  246. GroupName string `json:"group_name"`
  247. }
  248. func feedbagGroupFromItem(item wire.FeedbagItem) feedbagGroupHandle {
  249. return feedbagGroupHandle{
  250. GroupID: item.GroupID,
  251. GroupName: item.Name,
  252. }
  253. }
  254. // Web API key management types
  255. type createWebAPIKeyRequest struct {
  256. AppName string `json:"app_name"`
  257. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  258. RateLimit int `json:"rate_limit,omitempty"`
  259. Capabilities []string `json:"capabilities,omitempty"`
  260. }
  261. type webAPIKeyResponse struct {
  262. DevID string `json:"dev_id"`
  263. DevKey string `json:"dev_key,omitempty"` // Only shown on creation
  264. AppName string `json:"app_name"`
  265. CreatedAt time.Time `json:"created_at"`
  266. LastUsed *time.Time `json:"last_used,omitempty"`
  267. IsActive bool `json:"is_active"`
  268. RateLimit int `json:"rate_limit"`
  269. AllowedOrigins []string `json:"allowed_origins,omitempty"`
  270. Capabilities []string `json:"capabilities,omitempty"`
  271. }
  272. // icqProfileHandle is the JSON representation of a full ICQ user profile.
  273. type icqProfileHandle struct {
  274. UIN uint32 `json:"uin"`
  275. BasicInfo icqBasicInfoHandle `json:"basic_info"`
  276. MoreInfo icqMoreInfoHandle `json:"more_info"`
  277. WorkInfo icqWorkInfoHandle `json:"work_info"`
  278. Notes string `json:"notes"`
  279. Interests icqInterestsHandle `json:"interests"`
  280. Affiliations icqAffiliationsHandle `json:"affiliations"`
  281. Permissions icqPermissionsHandle `json:"permissions"`
  282. }
  283. type icqBasicInfoHandle struct {
  284. Nickname string `json:"nickname"`
  285. FirstName string `json:"first_name"`
  286. LastName string `json:"last_name"`
  287. EmailAddress string `json:"email"`
  288. City string `json:"city"`
  289. State string `json:"state"`
  290. Phone string `json:"phone"`
  291. Fax string `json:"fax"`
  292. Address string `json:"address"`
  293. CellPhone string `json:"cell_phone"`
  294. ZIPCode string `json:"zip"`
  295. CountryCode uint16 `json:"country_code"`
  296. GMTOffset uint8 `json:"gmt_offset"`
  297. PublishEmail bool `json:"publish_email"`
  298. OriginCity string `json:"origin_city"`
  299. OriginState string `json:"origin_state"`
  300. // OriginCountryCode is the ICQ country code for the user's original home.
  301. OriginCountryCode uint16 `json:"origin_country_code"`
  302. }
  303. type icqMoreInfoHandle struct {
  304. Gender uint16 `json:"gender"`
  305. HomePageAddr string `json:"homepage"`
  306. BirthYear uint16 `json:"birth_year"`
  307. BirthMonth uint8 `json:"birth_month"`
  308. BirthDay uint8 `json:"birth_day"`
  309. Lang1 uint8 `json:"lang1"`
  310. Lang2 uint8 `json:"lang2"`
  311. Lang3 uint8 `json:"lang3"`
  312. }
  313. type icqWorkInfoHandle struct {
  314. Company string `json:"company"`
  315. Department string `json:"department"`
  316. Position string `json:"position"`
  317. OccupationCode uint16 `json:"occupation_code"`
  318. Address string `json:"address"`
  319. City string `json:"city"`
  320. State string `json:"state"`
  321. ZIPCode string `json:"zip"`
  322. CountryCode uint16 `json:"country_code"`
  323. Phone string `json:"phone"`
  324. Fax string `json:"fax"`
  325. WebPage string `json:"web_page"`
  326. }
  327. type icqInterestsHandle struct {
  328. Code1 uint16 `json:"code1"`
  329. Keyword1 string `json:"keyword1"`
  330. Code2 uint16 `json:"code2"`
  331. Keyword2 string `json:"keyword2"`
  332. Code3 uint16 `json:"code3"`
  333. Keyword3 string `json:"keyword3"`
  334. Code4 uint16 `json:"code4"`
  335. Keyword4 string `json:"keyword4"`
  336. }
  337. type icqAffiliationsHandle struct {
  338. PastCode1 uint16 `json:"past_code1"`
  339. PastKeyword1 string `json:"past_keyword1"`
  340. PastCode2 uint16 `json:"past_code2"`
  341. PastKeyword2 string `json:"past_keyword2"`
  342. PastCode3 uint16 `json:"past_code3"`
  343. PastKeyword3 string `json:"past_keyword3"`
  344. CurrentCode1 uint16 `json:"current_code1"`
  345. CurrentKeyword1 string `json:"current_keyword1"`
  346. CurrentCode2 uint16 `json:"current_code2"`
  347. CurrentKeyword2 string `json:"current_keyword2"`
  348. CurrentCode3 uint16 `json:"current_code3"`
  349. CurrentKeyword3 string `json:"current_keyword3"`
  350. }
  351. type icqPermissionsHandle struct {
  352. AuthRequired bool `json:"auth_required"`
  353. WebAware bool `json:"web_aware"`
  354. AllowSpam bool `json:"allow_spam"`
  355. }
  356. type updateWebAPIKeyRequest struct {
  357. AppName *string `json:"app_name,omitempty"`
  358. IsActive *bool `json:"is_active,omitempty"`
  359. RateLimit *int `json:"rate_limit,omitempty"`
  360. AllowedOrigins *[]string `json:"allowed_origins,omitempty"`
  361. Capabilities *[]string `json:"capabilities,omitempty"`
  362. }