presence_handler.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. package webapi
  2. import (
  3. "context"
  4. "fmt"
  5. "log/slog"
  6. "net/http"
  7. "strings"
  8. "time"
  9. "github.com/mk6i/open-oscar-server/state"
  10. "github.com/mk6i/open-oscar-server/wire"
  11. )
  12. // PresenceHandler handles Web AIM API presence-related endpoints.
  13. type PresenceHandler struct {
  14. SessionManager *SessionManager
  15. FeedbagService FeedbagService
  16. BuddyBroadcaster BuddyBroadcaster
  17. LocateService LocateService
  18. IconSource BuddyIconSource
  19. Logger *slog.Logger
  20. }
  21. // maxPresenceTargets caps how many screen names a single presence/get request
  22. // may query in target-list ("t=") mode.
  23. const maxPresenceTargets = 10
  24. // ProfileData is the getProfile payload.
  25. type ProfileData struct {
  26. ScreenName string `json:"screenName" xml:"screenName"`
  27. Profile string `json:"profile" xml:"profile"`
  28. LastUpdated int64 `json:"lastUpdated" xml:"lastUpdated"`
  29. }
  30. // SetStateData echoes the identity fields a setState changed.
  31. type SetStateData struct {
  32. AimID string `json:"aimId" xml:"aimId"`
  33. DisplayID string `json:"displayId" xml:"displayId"`
  34. State string `json:"state" xml:"state"`
  35. AwayMsg string `json:"awayMsg" xml:"awayMsg"`
  36. StatusMsg string `json:"statusMsg" xml:"statusMsg"`
  37. UserType string `json:"userType" xml:"userType"`
  38. OnlineTime int64 `json:"onlineTime" xml:"onlineTime"`
  39. }
  40. // PresenceData contains presence information.
  41. type PresenceData struct {
  42. Groups []BuddyGroupInfo `json:"groups,omitempty" xml:"groups>group,omitempty"`
  43. Users []BuddyPresenceInfo `json:"users,omitempty" xml:"users>user,omitempty"`
  44. }
  45. // BuddyGroupInfo represents a buddy group with its members.
  46. type BuddyGroupInfo struct {
  47. Name string `json:"name" xml:"name"`
  48. Buddies []BuddyPresenceInfo `json:"buddies" xml:"buddies>buddy"`
  49. }
  50. // BuddyPresenceInfo represents presence information for a buddy.
  51. //
  52. // AimID is the normalized screen name the web client keys users by; DisplayID
  53. // preserves the casing and spacing the user signed on with. The client renders
  54. // DisplayID and falls back to AimID when it is absent.
  55. type BuddyPresenceInfo struct {
  56. AimID string `json:"aimId" xml:"aimId"`
  57. DisplayID string `json:"displayId,omitempty" xml:"displayId,omitempty"`
  58. Friendly string `json:"friendly,omitempty" xml:"friendly,omitempty"` // Viewer's private alias, rendered in preference to DisplayID
  59. State string `json:"state" xml:"state"` // "online", "offline", "away", "idle"
  60. StatusMsg string `json:"statusMsg,omitempty" xml:"statusMsg,omitempty"`
  61. AwayMsg string `json:"awayMsg,omitempty" xml:"awayMsg,omitempty"`
  62. ProfileMsg string `json:"profileMsg,omitempty" xml:"profileMsg,omitempty"`
  63. IdleTime int `json:"idleTime,omitempty" xml:"idleTime,omitempty"`
  64. OnlineTime int64 `json:"onlineTime,omitempty" xml:"onlineTime,omitempty"`
  65. UserType string `json:"userType" xml:"userType"` // "aim", "icq", "admin"
  66. BuddyIcon string `json:"buddyIcon,omitempty" xml:"buddyIcon,omitempty"`
  67. }
  68. // GetPresence handles GET /presence/get requests.
  69. func (h *PresenceHandler) GetPresence(w http.ResponseWriter, r *http.Request, session *Session) {
  70. ctx := r.Context()
  71. aimsid := session.AimSID
  72. // Check if buddy list is requested
  73. getBuddyList := r.URL.Query().Get("bl") == "1"
  74. wantProfileMsg := r.URL.Query().Get("profileMsg") == "1"
  75. // Get target users if specified
  76. targetUsers := r.URL.Query().Get("t")
  77. // Create PresenceData struct to hold the response data
  78. presenceData := PresenceData{}
  79. if getBuddyList {
  80. // Retrieve buddy list from feedbag
  81. groups, err := h.getBuddyListGroups(ctx, session, wantProfileMsg)
  82. if err != nil {
  83. h.Logger.ErrorContext(ctx, "failed to get buddy list", "err", err.Error())
  84. // Return empty buddy list on error instead of failing
  85. groups = []BuddyGroupInfo{}
  86. }
  87. presenceData.Groups = groups
  88. } else if targetUsers != "" {
  89. // Get presence for specific users
  90. users := strings.Split(targetUsers, ",")
  91. if len(users) > maxPresenceTargets {
  92. SendError(w, r, http.StatusBadRequest, fmt.Sprintf("too many screen names requested (max %d)", maxPresenceTargets))
  93. return
  94. }
  95. presenceList := make([]BuddyPresenceInfo, 0, len(users))
  96. // The client's user-object merge deletes any alias it holds, so every
  97. // presence payload has to carry friendly for aliased buddies.
  98. aliases := session.Aliases(ctx)
  99. for _, user := range users {
  100. user = strings.TrimSpace(user)
  101. if user == "" {
  102. continue
  103. }
  104. info := h.getUserPresence(ctx, session.OSCARSession, session.BaseURL, state.DisplayScreenName(user), wantProfileMsg)
  105. info.Friendly = aliases[info.AimID]
  106. presenceList = append(presenceList, info)
  107. }
  108. presenceData.Users = presenceList
  109. } else {
  110. // No specific request, return empty data
  111. presenceData.Groups = []BuddyGroupInfo{}
  112. }
  113. // Send response in requested format
  114. SendOK(w, r, presenceData, h.Logger)
  115. h.Logger.DebugContext(ctx, "presence retrieved",
  116. "aimsid", aimsid,
  117. "buddy_list", getBuddyList,
  118. "targets", targetUsers,
  119. )
  120. }
  121. // getBuddyListGroups retrieves the buddy list organized by groups.
  122. func (h *PresenceHandler) getBuddyListGroups(ctx context.Context, session *Session, wantProfileMsg bool) ([]BuddyGroupInfo, error) {
  123. // Get feedbag items via the feedbag service
  124. frame := wire.SNACFrame{FoodGroup: wire.Feedbag, SubGroup: wire.FeedbagQuery}
  125. reply, err := h.FeedbagService.Query(ctx, session.OSCARSession, frame)
  126. if err != nil {
  127. return nil, err
  128. }
  129. body, ok := reply.Body.(wire.SNAC_0x13_0x06_FeedbagReply)
  130. if !ok {
  131. return nil, fmt.Errorf("unexpected feedbag reply body type %T", reply.Body)
  132. }
  133. items := body.Items
  134. // Organize items into groups, keyed by GroupID. Group rows store their
  135. // identity in GroupID (ItemID is 0 for every group), so a GroupID-keyed map
  136. // is the only way to associate buddies — which reference their group via
  137. // GroupID — with the right group.
  138. groupMap := make(map[uint16]*BuddyGroupInfo)
  139. // First pass: identify groups. Skip the root group (GroupID 0), which holds
  140. // the master group order rather than buddies.
  141. for _, item := range items {
  142. if item.ClassID != wire.FeedbagClassIdGroup || item.GroupID == 0 {
  143. continue
  144. }
  145. name := item.Name
  146. if name == "" {
  147. name = "Buddies" // Default group name
  148. }
  149. groupMap[item.GroupID] = &BuddyGroupInfo{
  150. Name: name,
  151. Buddies: []BuddyPresenceInfo{},
  152. }
  153. }
  154. // Second pass: add buddies to their group with presence info.
  155. for _, item := range items {
  156. if item.ClassID != wire.FeedbagClassIdBuddy || item.Name == "" {
  157. continue
  158. }
  159. group, exists := groupMap[item.GroupID]
  160. if !exists {
  161. // Orphan buddy whose group row is missing: synthesize a default
  162. // group for its GroupID so the buddy is not dropped.
  163. group = &BuddyGroupInfo{Name: "Buddies", Buddies: []BuddyPresenceInfo{}}
  164. groupMap[item.GroupID] = group
  165. }
  166. // UserInfoQuery performs the blocking check and online lookup; blocked or
  167. // offline buddies come back as "offline", preserving the list structure.
  168. presence := h.getUserPresence(ctx, session.OSCARSession, session.BaseURL, state.DisplayScreenName(item.Name), wantProfileMsg)
  169. group.Buddies = append(group.Buddies, presence)
  170. }
  171. // If no groups exist at all, return a single default group.
  172. if len(groupMap) == 0 {
  173. groupMap[0] = &BuddyGroupInfo{
  174. Name: "Buddies",
  175. Buddies: []BuddyPresenceInfo{},
  176. }
  177. }
  178. // Convert map to slice
  179. groups := make([]BuddyGroupInfo, 0, len(groupMap))
  180. for _, group := range groupMap {
  181. groups = append(groups, *group)
  182. }
  183. return groups, nil
  184. }
  185. // getUserPresence resolves a user's presence by issuing a locate UserInfoQuery
  186. // on behalf of the requesting OSCAR session (instance). UserInfoQuery performs
  187. // the OSCAR blocking check and online lookup internally: blocked and offline
  188. // users both come back as a locate error, which we surface as "offline".
  189. func (h *PresenceHandler) getUserPresence(ctx context.Context, instance *state.SessionInstance, baseURL string, target state.DisplayScreenName, wantProfileMsg bool) BuddyPresenceInfo {
  190. ident := target.IdentScreenName()
  191. // Default offline presence
  192. presence := BuddyPresenceInfo{
  193. AimID: ident.String(),
  194. DisplayID: target.String(),
  195. State: "offline",
  196. UserType: "aim",
  197. }
  198. // Determine user type
  199. if strings.HasPrefix(ident.String(), "admin") {
  200. presence.UserType = "admin"
  201. } else if isICQScreenName(ident.String()) {
  202. presence.UserType = "icq"
  203. }
  204. // The unauthenticated icon endpoint resolves presence without a session, so
  205. // there may be no OSCAR instance to query on behalf of.
  206. if instance == nil {
  207. return presence
  208. }
  209. reqType := wire.LocateTypeUnavailable // away message
  210. if wantProfileMsg {
  211. reqType |= wire.LocateTypeSig // profile text
  212. }
  213. reply, err := h.LocateService.UserInfoQuery(ctx, instance, wire.SNACFrame{},
  214. wire.SNAC_0x02_0x05_LocateUserInfoQuery{Type: uint16(reqType), ScreenName: ident.String()})
  215. if err != nil {
  216. h.Logger.WarnContext(ctx, "failed to query user info", "screenName", ident.String(), "error", err)
  217. return presence
  218. }
  219. info, ok := reply.Body.(wire.SNAC_0x02_0x06_LocateUserInfoReply)
  220. if !ok {
  221. // Locate error => user is blocked or offline.
  222. return presence
  223. }
  224. presence.State = "online"
  225. // Publish the icon only now that locate has confirmed the user is online and
  226. // has not blocked the caller. Offline and blocking users return above without
  227. // an icon, so neither their icon nor its activity-revealing hash leaks to a
  228. // caller they are otherwise invisible to.
  229. presence.BuddyIcon = h.IconSource.PublishedURL(ctx, baseURL, ident)
  230. // The locate reply carries the screen name as the user formatted it, which
  231. // beats whatever casing the caller happened to pass in.
  232. if info.ScreenName != "" {
  233. presence.DisplayID = info.ScreenName
  234. }
  235. if tod, ok := info.Uint32BE(wire.OServiceUserInfoSignonTOD); ok {
  236. presence.OnlineTime = int64(tod)
  237. }
  238. if info.IsAway() {
  239. presence.State = "away"
  240. } else if status, ok := info.Uint32BE(wire.OServiceUserInfoStatus); ok && status&wire.OServiceUserStatusDND != 0 {
  241. presence.State = "dnd"
  242. }
  243. if idle, ok := info.Uint16BE(wire.OServiceUserInfoIdleTime); ok && idle > 0 {
  244. presence.State = "idle"
  245. presence.IdleTime = int(idle)
  246. }
  247. if msg, ok := info.LocateInfo.String(wire.LocateTLVTagsInfoUnavailableData); ok {
  248. presence.AwayMsg = msg
  249. }
  250. if wantProfileMsg {
  251. if prof, ok := info.LocateInfo.String(wire.LocateTLVTagsInfoSigData); ok {
  252. presence.ProfileMsg = prof
  253. }
  254. }
  255. return presence
  256. }
  257. // isICQScreenName checks if a screen name is an ICQ number.
  258. func isICQScreenName(screenName string) bool {
  259. if len(screenName) == 0 {
  260. return false
  261. }
  262. for _, r := range screenName {
  263. if r < '0' || r > '9' {
  264. return false
  265. }
  266. }
  267. return true
  268. }
  269. // SetState handles GET /presence/setState requests to update user's presence state.
  270. func (h *PresenceHandler) SetState(w http.ResponseWriter, r *http.Request, session *Session) {
  271. ctx := r.Context()
  272. stateParam := r.URL.Query().Get("state")
  273. if stateParam == "" {
  274. stateParam = r.URL.Query().Get("view")
  275. }
  276. awayMsg := r.URL.Query().Get("awayMsg")
  277. if awayMsg == "" {
  278. awayMsg = r.URL.Query().Get("away")
  279. }
  280. oscarSession := session.OSCARSession
  281. // Map web state to OSCAR status bits
  282. var statusBitmask uint32
  283. switch stateParam {
  284. case "online":
  285. statusBitmask = 0x0000 // Clear all status bits
  286. oscarSession.SetAwayMessage("")
  287. oscarSession.ClearUserInfoFlag(wire.OServiceUserFlagUnavailable)
  288. case "away":
  289. statusBitmask = wire.OServiceUserStatusAway
  290. oscarSession.SetUserInfoFlag(wire.OServiceUserFlagUnavailable)
  291. if awayMsg != "" {
  292. oscarSession.SetAwayMessage(awayMsg)
  293. }
  294. case "invisible":
  295. statusBitmask = wire.OServiceUserStatusInvisible
  296. case "dnd":
  297. statusBitmask = wire.OServiceUserStatusDND
  298. default:
  299. SendError(w, r, http.StatusBadRequest, "invalid state parameter")
  300. return
  301. }
  302. // Update OSCAR session status
  303. oscarSession.SetUserStatusBitmask(statusBitmask)
  304. // Broadcast presence update
  305. if statusBitmask&wire.OServiceUserStatusInvisible != 0 {
  306. // User going invisible - broadcast departure
  307. if err := h.BuddyBroadcaster.BroadcastBuddyDeparted(ctx, oscarSession.IdentScreenName()); err != nil {
  308. h.Logger.ErrorContext(ctx, "failed to broadcast buddy departed", "err", err.Error())
  309. }
  310. } else {
  311. // User visible - broadcast arrival/update
  312. if err := h.BuddyBroadcaster.BroadcastBuddyArrived(ctx, oscarSession.IdentScreenName(), oscarSession.Session().TLVUserInfo()); err != nil {
  313. h.Logger.ErrorContext(ctx, "failed to broadcast buddy arrived", "err", err.Error())
  314. }
  315. }
  316. // Notify the user's own client so its status indicator re-renders. The AIM
  317. // client updates its self-presence badge only from "myInfo" events; the
  318. // "presence" broadcast above drives buddy dots, not the user's own state.
  319. // Without this, changing to Busy/Away leaves the user still showing as
  320. // available in their own UI.
  321. h.pushMyInfo(session, stateParam, awayMsg, "")
  322. h.Logger.InfoContext(ctx, "presence state updated",
  323. "screenName", session.ScreenName.String(),
  324. "state", stateParam,
  325. "hasAwayMsg", awayMsg != "",
  326. )
  327. // Send success response
  328. SendOK(w, r, &SetStateData{
  329. AimID: session.ScreenName.IdentScreenName().String(),
  330. DisplayID: session.ScreenName.String(),
  331. State: stateParam,
  332. AwayMsg: awayMsg,
  333. StatusMsg: "",
  334. UserType: "aim",
  335. OnlineTime: time.Now().Unix(),
  336. }, h.Logger)
  337. }
  338. // SetStatus handles GET /presence/setStatus requests to update user's status message.
  339. func (h *PresenceHandler) SetStatus(w http.ResponseWriter, r *http.Request, session *Session) {
  340. ctx := r.Context()
  341. // Get the status message
  342. statusMsg := r.URL.Query().Get("statusMsg")
  343. statusCode := r.URL.Query().Get("statusCode")
  344. // Store status message in session (this would normally be stored in a profile/status service)
  345. // For now, we'll broadcast it as part of presence
  346. oscarSession := session.OSCARSession
  347. // In OSCAR, status messages are typically part of the profile
  348. // We'll need to extend this based on the actual implementation
  349. // Broadcast presence update with new status
  350. if err := h.BuddyBroadcaster.BroadcastBuddyArrived(ctx, oscarSession.IdentScreenName(), oscarSession.Session().TLVUserInfo()); err != nil {
  351. h.Logger.ErrorContext(ctx, "failed to broadcast status update", "err", err.Error())
  352. }
  353. // Notify the user's own client so its status message re-renders. Preserve the
  354. // current presence state so a status-only change does not flip the self badge.
  355. h.pushMyInfo(session, currentWebState(oscarSession), oscarSession.Session().AwayMessage(), statusMsg)
  356. h.Logger.InfoContext(ctx, "status message updated",
  357. "screenName", session.ScreenName.String(),
  358. "statusMsg", statusMsg,
  359. "statusCode", statusCode,
  360. )
  361. // Send success response
  362. SendOK(w, r, nil, h.Logger)
  363. }
  364. // SetProfile handles GET /presence/setProfile requests to update user's profile.
  365. func (h *PresenceHandler) SetProfile(w http.ResponseWriter, r *http.Request, session *Session) {
  366. ctx := r.Context()
  367. // Get the profile content
  368. profileText := r.URL.Query().Get("profile")
  369. // Limit profile size (4KB max)
  370. if len(profileText) > 4096 {
  371. SendError(w, r, http.StatusBadRequest, "profile too large (max 4KB)")
  372. return
  373. }
  374. instance := session.OSCARSession
  375. // Save profile via OSCAR LocateService.
  376. setInfo := wire.SNAC_0x02_0x04_LocateSetInfo{
  377. TLVRestBlock: wire.TLVRestBlock{
  378. TLVList: wire.TLVList{
  379. wire.NewTLVBE(wire.LocateTLVTagsInfoSigData, profileText),
  380. },
  381. },
  382. }
  383. if err := h.LocateService.SetInfo(ctx, instance, setInfo); err != nil {
  384. h.Logger.ErrorContext(ctx, "failed to set profile", "err", err.Error())
  385. SendError(w, r, http.StatusInternalServerError, "failed to save profile")
  386. return
  387. }
  388. h.Logger.InfoContext(ctx, "profile updated",
  389. "screenName", session.ScreenName.String(),
  390. "profileSize", len(profileText),
  391. )
  392. // Send success response
  393. SendOK(w, r, nil, h.Logger)
  394. }
  395. // GetProfile handles GET /presence/getProfile requests to retrieve user's profile.
  396. func (h *PresenceHandler) GetProfile(w http.ResponseWriter, r *http.Request, session *Session) {
  397. ctx := r.Context()
  398. // Get target screen name (optional - defaults to self)
  399. targetSN := r.URL.Query().Get("sn")
  400. if targetSN == "" {
  401. targetSN = session.ScreenName.String()
  402. }
  403. // Retrieve profile via OSCAR LocateService.
  404. var profileText string
  405. instance := session.OSCARSession
  406. reply, err := h.LocateService.UserInfoQuery(ctx, instance, wire.SNACFrame{},
  407. wire.SNAC_0x02_0x05_LocateUserInfoQuery{Type: uint16(wire.LocateTypeSig), ScreenName: targetSN})
  408. if err != nil {
  409. h.Logger.WarnContext(ctx, "failed to get profile", "err", err.Error())
  410. } else if info, ok := reply.Body.(wire.SNAC_0x02_0x06_LocateUserInfoReply); ok {
  411. if prof, ok := info.LocateInfo.String(wire.LocateTLVTagsInfoSigData); ok {
  412. profileText = prof
  413. }
  414. }
  415. // Send response
  416. responseData := &ProfileData{ScreenName: targetSN, Profile: profileText}
  417. SendOK(w, r, responseData, h.Logger)
  418. }
  419. // Icon handles GET /presence/icon requests for presence icons.
  420. func (h *PresenceHandler) Icon(w http.ResponseWriter, r *http.Request) {
  421. // Get parameters
  422. name := r.URL.Query().Get("name")
  423. size := r.URL.Query().Get("size")
  424. iconType := r.URL.Query().Get("type")
  425. if name == "" {
  426. SendError(w, r, http.StatusBadRequest, "missing name parameter")
  427. return
  428. }
  429. // Default values
  430. if size == "" {
  431. size = "32"
  432. }
  433. if iconType == "" {
  434. iconType = "aim"
  435. }
  436. // For now, redirect to a placeholder icon
  437. // In production, this would redirect to actual icon storage/CDN
  438. var iconURL string
  439. // If it's an email lookup, extract username
  440. if strings.Contains(name, "@") {
  441. parts := strings.Split(name, "@")
  442. if len(parts) > 0 {
  443. name = parts[0]
  444. }
  445. }
  446. // Resolve the target's presence via OSCAR LocateService, querying on behalf
  447. // of the caller's session. This endpoint is unauthenticated, so fall back to
  448. // the offline icon when no valid session is supplied.
  449. var instance *state.SessionInstance
  450. if aimsid := r.URL.Query().Get("aimsid"); aimsid != "" {
  451. if session, err := h.SessionManager.GetSession(r.Context(), aimsid); err == nil {
  452. instance = session.OSCARSession
  453. }
  454. }
  455. // This endpoint serves a presence state badge, not the user's buddy icon, so
  456. // it has no use for a buddy icon URL.
  457. switch h.getUserPresence(r.Context(), instance, "", state.DisplayScreenName(name), false).State {
  458. case "away":
  459. iconURL = "/static/icons/away_" + iconType + "_" + size + ".png"
  460. case "idle":
  461. iconURL = "/static/icons/idle_" + iconType + "_" + size + ".png"
  462. case "offline":
  463. iconURL = "/static/icons/offline_" + iconType + "_" + size + ".png"
  464. default:
  465. iconURL = "/static/icons/online_" + iconType + "_" + size + ".png"
  466. }
  467. // Redirect to icon URL
  468. http.Redirect(w, r, iconURL, http.StatusFound)
  469. }
  470. // currentWebState maps an OSCAR session's presence flags to the web state string
  471. // the AIM client expects ("online", "away", "idle", "invisible").
  472. func currentWebState(instance *state.SessionInstance) string {
  473. sess := instance.Session()
  474. switch {
  475. case sess.Invisible():
  476. return "invisible"
  477. case sess.Away():
  478. return "away"
  479. case instance.Idle():
  480. return "idle"
  481. default:
  482. return "online"
  483. }
  484. }
  485. // pushMyInfo queues a "myInfo" event on the user's own session so the AIM client
  486. // re-renders its self-presence badge. The client binds its identity-badge render
  487. // to "myInfo" events only, so state changes made via setState/setStatus are
  488. // invisible in the user's own UI unless a myInfo event is delivered.
  489. func (h *PresenceHandler) pushMyInfo(session *Session, webState, awayMsg, statusMsg string) {
  490. if !session.IsSubscribedTo("myInfo") && !session.IsSubscribedTo("presence") {
  491. return
  492. }
  493. // buddyIcon is omitted here (empty) so the client's merge preserves the icon it
  494. // already holds; a setState/setStatus does not change the icon. Icon changes
  495. // arrive on their own myInfo via the pump's MyInfoRefresher.
  496. myInfo := buildMyInfo(session.ScreenName, webState, "")
  497. myInfo.AwayMsg = awayMsg
  498. myInfo.StatusMsg = statusMsg
  499. session.EventQueue.Push(EventType("myInfo"), myInfo)
  500. }