Add hacky sleep before sending set active session request
This commit is contained in:
parent
eccbb9910e
commit
0f4f00295c
2 changed files with 9 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -74,6 +75,8 @@ type Client struct {
|
||||||
|
|
||||||
conversationsFetchedOnce bool
|
conversationsFetchedOnce bool
|
||||||
|
|
||||||
|
hackyDelaySetActive atomic.Bool
|
||||||
|
|
||||||
AuthData *AuthData
|
AuthData *AuthData
|
||||||
cfg *gmproto.Config
|
cfg *gmproto.Config
|
||||||
|
|
||||||
|
@ -160,6 +163,11 @@ func (c *Client) Connect() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) postConnect() {
|
func (c *Client) postConnect() {
|
||||||
|
// For some reason SetActiveSession fails if it's called immediately after reconnecting after a google login,
|
||||||
|
// so hackily delay it a few seconds to make it work.
|
||||||
|
if c.hackyDelaySetActive.CompareAndSwap(true, false) {
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
}
|
||||||
c.Logger.Debug().Msg("Sending get updates request")
|
c.Logger.Debug().Msg("Sending get updates request")
|
||||||
err := c.SetActiveSession()
|
err := c.SetActiveSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -300,6 +300,7 @@ func (c *Client) DoGaiaPairing(ctx context.Context, emojiCallback func(string))
|
||||||
c.AuthData.PairingID = ps.UUID
|
c.AuthData.PairingID = ps.UUID
|
||||||
c.triggerEvent(&events.PairSuccessful{PhoneID: c.AuthData.Mobile.GetSourceID()})
|
c.triggerEvent(&events.PairSuccessful{PhoneID: c.AuthData.Mobile.GetSourceID()})
|
||||||
|
|
||||||
|
c.hackyDelaySetActive.Store(true)
|
||||||
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,
|
||||||
// the phone won't recognize the session the bridge will get unpaired.
|
// the phone won't recognize the session the bridge will get unpaired.
|
||||||
|
|
Loading…
Reference in a new issue