Delete connection and update JID map on remote logout

This commit is contained in:
Tulir Asokan 2022-03-10 22:20:10 +02:00
parent 4fd07a2646
commit 7322f78d56
3 changed files with 9 additions and 9 deletions

View file

@ -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")

View file

@ -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."})
}

10
user.go
View file

@ -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 {