Skip to content

Commit

Permalink
legacyprovision: log out other logins when logging into new one
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 17, 2024
1 parent 39b408d commit 31a4522
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/mautrix-signal/legacyprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31a4522

Please sign in to comment.