Skip to content

Commit

Permalink
legacyprovision: logout other logins when making new one
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 11, 2024
1 parent 25f13a3 commit e7d0842
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/mautrix-whatsapp/legacyprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.mau.fi/util/exhttp"
"go.mau.fi/whatsmeow/types"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/bridge/status"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/matrix"
"maunium.net/go/mautrix/id"
Expand Down Expand Up @@ -189,10 +190,19 @@ func legacyProvLogin(w http.ResponseWriter, r *http.Request) {
"platform": step.CompleteParams.UserLogin.Client.(*connector.WhatsAppClient).Device.Platform,
"phone": step.CompleteParams.UserLogin.RemoteProfile.Phone,
})
go handleLoginComplete(context.WithoutCancel(ctx), user, step.CompleteParams.UserLogin)
}
break
}
}
func handleLoginComplete(ctx context.Context, user *bridgev2.User, newLogin *bridgev2.UserLogin) {
allLogins := user.GetUserLogins()
for _, login := range allLogins {
if login.ID != newLogin.ID {
login.Delete(ctx, status.BridgeState{StateEvent: status.StateLoggedOut, Reason: "LOGIN_OVERRIDDEN"}, bridgev2.DeleteOpts{})
}
}
}

func legacyProvLogout(w http.ResponseWriter, r *http.Request) {
user := m.Matrix.Provisioning.GetUser(r)
Expand Down

0 comments on commit e7d0842

Please sign in to comment.