From 31a4522ee66e5b1d52055ea5fd093602bb7d243e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 17 Aug 2024 23:26:25 +0300 Subject: [PATCH] legacyprovision: log out other logins when logging into new one --- cmd/mautrix-signal/legacyprovision.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/mautrix-signal/legacyprovision.go b/cmd/mautrix-signal/legacyprovision.go index 8e8e7529..013d1bdb 100644 --- a/cmd/mautrix-signal/legacyprovision.go +++ b/cmd/mautrix-signal/legacyprovision.go @@ -17,6 +17,7 @@ package main import ( + "context" "encoding/json" "fmt" "net/http" @@ -27,6 +28,7 @@ import ( "github.com/gorilla/mux" "github.com/rs/zerolog" "maunium.net/go/mautrix" + "maunium.net/go/mautrix/bridge/status" "maunium.net/go/mautrix/bridgev2" "maunium.net/go/mautrix/id" @@ -188,10 +190,20 @@ func legacyProvLinkWaitAccount(w http.ResponseWriter, r *http.Request) { UUID: string(res.CompleteParams.UserLogin.ID), Number: res.CompleteParams.UserLogin.RemoteName, }) + go handleLoginComplete(r.Context(), login.User, res.CompleteParams.UserLogin) } login.Delete() } +func handleLoginComplete(ctx context.Context, user *bridgev2.User, newLogin *bridgev2.UserLogin) { + allLogins := user.GetCachedUserLogins() + 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) { // No-op for backwards compatibility JSONResponse(w, http.StatusOK, nil)