Properly set phone ID when pairing with google account

This commit is contained in:
Tulir Asokan 2024-02-23 22:52:04 +02:00
parent 2ca85cf2bd
commit 6c4d8d8744
4 changed files with 7 additions and 6 deletions

View file

@ -9,5 +9,6 @@ type QR struct {
} }
type PairSuccessful struct { type PairSuccessful struct {
*gmproto.PairedData PhoneID string
QRData *gmproto.PairedData
} }

View file

@ -58,7 +58,7 @@ func (c *Client) completePairing(data *gmproto.PairedData) {
c.AuthData.Mobile = data.Mobile c.AuthData.Mobile = data.Mobile
c.AuthData.Browser = data.Browser c.AuthData.Browser = data.Browser
c.triggerEvent(&events.PairSuccessful{PairedData: data}) c.triggerEvent(&events.PairSuccessful{PhoneID: data.GetMobile().GetSourceID(), QRData: data})
go func() { go func() {
// Sleep for a bit to let the phone save the pair data. If we reconnect too quickly, // Sleep for a bit to let the phone save the pair data. If we reconnect too quickly,

View file

@ -297,7 +297,7 @@ func (c *Client) DoGaiaPairing(emojiCallback func(string)) error {
c.AuthData.RequestCrypto.AESKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("client")) c.AuthData.RequestCrypto.AESKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("client"))
c.AuthData.RequestCrypto.HMACKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("server")) c.AuthData.RequestCrypto.HMACKey = doHKDF(ps.NextKey, encryptionKeyInfo, []byte("server"))
c.AuthData.PairingID = ps.UUID c.AuthData.PairingID = ps.UUID
c.triggerEvent(&events.PairSuccessful{}) c.triggerEvent(&events.PairSuccessful{PhoneID: c.AuthData.Mobile.GetSourceID()})
go func() { go func() {
// Sleep for a bit to let the phone save the pair data. If we reconnect too quickly, // Sleep for a bit to let the phone save the pair data. If we reconnect too quickly,

View file

@ -698,14 +698,14 @@ func (user *User) syncHandleEvent(event any) {
} }
case *events.PairSuccessful: case *events.PairSuccessful:
user.Session = user.Client.AuthData user.Session = user.Client.AuthData
if user.PhoneID != "" && user.PhoneID != v.GetMobile().GetSourceID() { if user.PhoneID != "" && user.PhoneID != v.PhoneID {
user.zlog.Warn(). user.zlog.Warn().
Str("old_phone_id", user.PhoneID). Str("old_phone_id", user.PhoneID).
Str("new_phone_id", v.GetMobile().GetSourceID()). Str("new_phone_id", v.PhoneID).
Msg("Phone ID changed, resetting state") Msg("Phone ID changed, resetting state")
user.ResetState() user.ResetState()
} }
user.PhoneID = v.GetMobile().GetSourceID() user.PhoneID = v.PhoneID
err := user.Update(context.TODO()) err := user.Update(context.TODO())
if err != nil { if err != nil {
user.zlog.Err(err).Msg("Failed to update session in database") user.zlog.Err(err).Msg("Failed to update session in database")