Fix incorrect bridge state after logging out

This commit is contained in:
Tulir Asokan 2021-10-29 22:03:00 +03:00
parent b9d918a1d1
commit 745dd1cd63
3 changed files with 6 additions and 1 deletions

View file

@ -626,6 +626,7 @@ func (handler *CommandHandler) CommandDisconnect(ce *CommandEvent) {
}
ce.User.DeleteConnection()
ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
ce.User.sendBridgeState(BridgeState{StateEvent: StateBadCredentials, Error: WANotConnected})
}
const cmdPingHelp = `ping - Check your connection to WhatsApp.`

View file

@ -134,6 +134,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)
}
func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request) {
@ -147,6 +148,7 @@ func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request)
}
user.DeleteConnection()
jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp"})
user.sendBridgeState(BridgeState{StateEvent: StateBadCredentials, Error: WANotConnected})
}
func (prov *ProvisioningAPI) Reconnect(w http.ResponseWriter, r *http.Request) {
@ -163,6 +165,7 @@ func (prov *ProvisioningAPI) Reconnect(w http.ResponseWriter, r *http.Request) {
}
} else {
user.DeleteConnection()
user.sendBridgeState(BridgeState{StateEvent: StateTransientDisconnect, Error: WANotConnected})
user.Connect()
jsonResponse(w, http.StatusAccepted, Response{true, "Restarted connection to WhatsApp"})
}
@ -230,6 +233,8 @@ func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) {
})
return
}
} else {
user.Session = nil
}
user.DeleteConnection()
}

View file

@ -273,7 +273,6 @@ func (user *User) DeleteConnection() {
user.connLock.Lock()
defer user.connLock.Unlock()
user.unlockedDeleteConnection()
user.sendBridgeState(BridgeState{StateEvent: StateBadCredentials, Error: WANotConnected})
}
func (user *User) HasSession() bool {