forked from MirrorHub/mautrix-whatsapp
Delete connection and update JID map on remote logout
This commit is contained in:
parent
4fd07a2646
commit
7322f78d56
3 changed files with 9 additions and 9 deletions
|
@ -601,7 +601,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ce.User.Session = nil
|
ce.User.Session = nil
|
||||||
ce.User.removeFromJIDMap(StateLoggedOut)
|
ce.User.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut})
|
||||||
ce.User.DeleteConnection()
|
ce.User.DeleteConnection()
|
||||||
ce.User.DeleteSession()
|
ce.User.DeleteSession()
|
||||||
ce.Reply("Logged out successfully.")
|
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.")
|
ce.Reply("Nothing to purge: no session information stored and no active connection.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ce.User.removeFromJIDMap(StateLoggedOut)
|
ce.User.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut})
|
||||||
ce.User.DeleteConnection()
|
ce.User.DeleteConnection()
|
||||||
ce.User.DeleteSession()
|
ce.User.DeleteSession()
|
||||||
ce.Reply("Session information purged")
|
ce.Reply("Session information purged")
|
||||||
|
|
|
@ -148,7 +148,7 @@ func (prov *ProvisioningAPI) DeleteSession(w http.ResponseWriter, r *http.Reques
|
||||||
user.DeleteConnection()
|
user.DeleteConnection()
|
||||||
user.DeleteSession()
|
user.DeleteSession()
|
||||||
jsonResponse(w, http.StatusOK, Response{true, "Session information purged"})
|
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) {
|
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.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||||
user.removeFromJIDMap(StateLoggedOut)
|
user.removeFromJIDMap(BridgeState{StateEvent: StateLoggedOut})
|
||||||
user.DeleteSession()
|
user.DeleteSession()
|
||||||
jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."})
|
jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."})
|
||||||
}
|
}
|
||||||
|
|
10
user.go
10
user.go
|
@ -118,7 +118,7 @@ func (user *User) addToJIDMap() {
|
||||||
user.bridge.usersLock.Unlock()
|
user.bridge.usersLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) removeFromJIDMap(state BridgeStateEvent) {
|
func (user *User) removeFromJIDMap(state BridgeState) {
|
||||||
user.bridge.usersLock.Lock()
|
user.bridge.usersLock.Lock()
|
||||||
jidUser, ok := user.bridge.usersByUsername[user.JID.User]
|
jidUser, ok := user.bridge.usersByUsername[user.JID.User]
|
||||||
if ok && user == jidUser {
|
if ok && user == jidUser {
|
||||||
|
@ -126,7 +126,7 @@ func (user *User) removeFromJIDMap(state BridgeStateEvent) {
|
||||||
}
|
}
|
||||||
user.bridge.usersLock.Unlock()
|
user.bridge.usersLock.Unlock()
|
||||||
user.bridge.Metrics.TrackLoginState(user.JID, false)
|
user.bridge.Metrics.TrackLoginState(user.JID, false)
|
||||||
user.sendBridgeState(BridgeState{StateEvent: state})
|
user.sendBridgeState(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetAllUsers() []*User {
|
func (bridge *Bridge) GetAllUsers() []*User {
|
||||||
|
@ -547,8 +547,6 @@ func (user *User) HandleEvent(event interface{}) {
|
||||||
switch v := event.(type) {
|
switch v := event.(type) {
|
||||||
case *events.LoggedOut:
|
case *events.LoggedOut:
|
||||||
go user.handleLoggedOut(v.OnConnect, v.Reason)
|
go user.handleLoggedOut(v.OnConnect, v.Reason)
|
||||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
|
||||||
user.bridge.Metrics.TrackLoginState(user.JID, false)
|
|
||||||
case *events.Connected:
|
case *events.Connected:
|
||||||
user.bridge.Metrics.TrackConnectionState(user.JID, true)
|
user.bridge.Metrics.TrackConnectionState(user.JID, true)
|
||||||
user.bridge.Metrics.TrackLoginState(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) {
|
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.JID = types.EmptyJID
|
||||||
user.Update()
|
user.Update()
|
||||||
if onConnect {
|
if onConnect {
|
||||||
|
|
Loading…
Reference in a new issue