diff --git a/server/channels/app/platform/web_conn.go b/server/channels/app/platform/web_conn.go index 6b770b8726..4925f41439 100644 --- a/server/channels/app/platform/web_conn.go +++ b/server/channels/app/platform/web_conn.go @@ -171,10 +171,12 @@ func (ps *PlatformService) PopulateWebConnConfig(s *model.Session, cfg *WebConnC // NewWebConn returns a new WebConn instance. func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runner HookRunner) *WebConn { + userID := cfg.Session.UserId + session := cfg.Session if cfg.Session.UserId != "" { ps.Go(func() { - ps.SetStatusOnline(cfg.Session.UserId, false) - ps.UpdateLastActivityAtIfNeeded(cfg.Session) + ps.SetStatusOnline(userID, false) + ps.UpdateLastActivityAtIfNeeded(session) }) } @@ -232,9 +234,9 @@ func (ps *PlatformService) NewWebConn(cfg *WebConnConfig, suite SuiteIFace, runn wc.SetSessionExpiresAt(cfg.Session.ExpiresAt) wc.SetConnectionID(cfg.ConnectionID) - wc.Platform.Go(func() { - wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool { - hooks.OnWebSocketConnect(wc.GetConnectionID(), wc.UserId) + ps.Go(func() { + runner.RunMultiHook(func(hooks plugin.Hooks) bool { + hooks.OnWebSocketConnect(wc.GetConnectionID(), userID) return true }, plugin.OnWebSocketConnectID) }) @@ -334,9 +336,10 @@ func (wc *WebConn) Pump() { wc.Platform.HubUnregister(wc) close(wc.pumpFinished) + userID := wc.UserId wc.Platform.Go(func() { wc.HookRunner.RunMultiHook(func(hooks plugin.Hooks) bool { - hooks.OnWebSocketDisconnect(wc.GetConnectionID(), wc.UserId) + hooks.OnWebSocketDisconnect(wc.GetConnectionID(), userID) return true }, plugin.OnWebSocketDisconnectID) }) @@ -353,8 +356,9 @@ func (wc *WebConn) readPump() { return err } if wc.IsAuthenticated() { + userID := wc.UserId wc.Platform.Go(func() { - wc.Platform.SetStatusAwayIfNeeded(wc.UserId, false) + wc.Platform.SetStatusAwayIfNeeded(userID, false) }) } return nil diff --git a/server/channels/app/platform/web_hub.go b/server/channels/app/platform/web_hub.go index 341c2bf287..7193215f47 100644 --- a/server/channels/app/platform/web_hub.go +++ b/server/channels/app/platform/web_hub.go @@ -436,8 +436,9 @@ func (h *Hub) Start() { conns := connIndex.ForUser(webConn.UserId) if len(conns) == 0 || areAllInactive(conns) { + userID := webConn.UserId h.platform.Go(func() { - h.platform.SetStatusOffline(webConn.UserId, false) + h.platform.SetStatusOffline(userID, false) }) continue } @@ -452,8 +453,9 @@ func (h *Hub) Start() { } if h.platform.isUserAway(latestActivity) { + userID := webConn.UserId h.platform.Go(func() { - h.platform.SetStatusLastActivityAt(webConn.UserId, latestActivity) + h.platform.SetStatusLastActivityAt(userID, latestActivity) }) } case userID := <-h.invalidateUser: