diff --git a/commands.go b/commands.go index 4abf2b3..a6465ac 100644 --- a/commands.go +++ b/commands.go @@ -601,7 +601,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { return } ce.User.Session = nil - ce.User.removeFromJIDMap(StateLoggedOut) + ce.User.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut}) ce.User.DeleteConnection() ce.User.DeleteSession() ce.Reply("Logged out successfully.") @@ -658,7 +658,7 @@ func (handler *CommandHandler) CommandDeleteSession(ce *CommandEvent) { ce.Reply("Nothing to purge: no session information stored and no active connection.") return } - ce.User.removeFromJIDMap(StateLoggedOut) + ce.User.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut}) ce.User.DeleteConnection() ce.User.DeleteSession() ce.Reply("Session information purged") diff --git a/provisioning.go b/provisioning.go index 1df0f65..622f4c4 100644 --- a/provisioning.go +++ b/provisioning.go @@ -148,7 +148,7 @@ func (prov *ProvisioningAPI) DeleteSession(w http.ResponseWriter, r *http.Reques user.DeleteConnection() user.DeleteSession() jsonResponse(w, http.StatusOK, Response{true, "Session information purged"}) - user.removeFromJIDMap(StateLoggedOut) + user.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut}) } func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request) { @@ -434,7 +434,7 @@ func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) { } user.bridge.Metrics.TrackConnectionState(user.JID, false) - user.removeFromJIDMap(StateLoggedOut) + user.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut}) user.DeleteSession() jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."}) } diff --git a/user.go b/user.go index 51536cc..01a323e 100644 --- a/user.go +++ b/user.go @@ -118,7 +118,7 @@ func (user *User) addToJIDMap() { user.bridge.usersLock.Unlock() } -func (user *User) removeFromJIDMap(state BridgeStateEvent) { +func (user *User) removeFromJIDMap(state BridgeState) { user.bridge.usersLock.Lock() jidUser, ok := user.bridge.usersByUsername[user.JID.User] if ok && user == jidUser { @@ -126,7 +126,7 @@ func (user *User) removeFromJIDMap(state BridgeStateEvent) { } user.bridge.usersLock.Unlock() user.bridge.Metrics.TrackLoginState(user.JID, false) - user.sendBridgeState(BridgeState{StateEvent: state}) + user.sendBridgeState(state) } func (bridge *Bridge) GetAllUsers() []*User { @@ -547,8 +547,6 @@ func (user *User) HandleEvent(event interface{}) { switch v := event.(type) { case *events.LoggedOut: go user.handleLoggedOut(v.OnConnect, v.Reason) - user.bridge.Metrics.TrackConnectionState(user.JID, false) - user.bridge.Metrics.TrackLoginState(user.JID, false) case *events.Connected: user.bridge.Metrics.TrackConnectionState(user.JID, true) user.bridge.Metrics.TrackLoginState(user.JID, true) @@ -877,7 +875,9 @@ func (user *User) UpdateDirectChats(chats map[id.UserID][]id.RoomID) { } func (user *User) handleLoggedOut(onConnect bool, reason events.ConnectFailureReason) { - user.sendBridgeState(BridgeState{StateEvent: StateBadCredentials, Error: WALoggedOut, Message: reason.String()}) + user.removeFromJIDMap(BridgeState{StateEvent: StateBadCredentials, Error: WALoggedOut, Message: reason.String()}) + user.DeleteConnection() + user.Session = nil user.JID = types.EmptyJID user.Update() if onConnect {