forked from lug/matterbridge
Update dependencies and build to go1.22 (#2113)
* Update dependencies and build to go1.22 * Fix api changes wrt to dependencies * Update golangci config
This commit is contained in:
34
vendor/go.mau.fi/whatsmeow/connectionevents.go
vendored
34
vendor/go.mau.fi/whatsmeow/connectionevents.go
vendored
@@ -7,7 +7,6 @@
|
||||
package whatsmeow
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
waBinary "go.mau.fi/whatsmeow/binary"
|
||||
@@ -17,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func (cli *Client) handleStreamError(node *waBinary.Node) {
|
||||
atomic.StoreUint32(&cli.isLoggedIn, 0)
|
||||
cli.isLoggedIn.Store(false)
|
||||
cli.clearResponseWaiters(node)
|
||||
code, _ := node.Attrs["code"].(string)
|
||||
conflict, _ := node.GetOptionalChildByTag("conflict")
|
||||
@@ -48,6 +47,16 @@ func (cli *Client) handleStreamError(node *waBinary.Node) {
|
||||
// This seems to happen when the server wants to restart or something.
|
||||
// The disconnection will be emitted as an events.Disconnected and then the auto-reconnect will do its thing.
|
||||
cli.Log.Warnf("Got 503 stream error, assuming automatic reconnect will handle it")
|
||||
case cli.RefreshCAT != nil && (code == events.ConnectFailureCATInvalid.NumberString() || code == events.ConnectFailureCATExpired.NumberString()):
|
||||
cli.Log.Infof("Got %s stream error, refreshing CAT before reconnecting...", code)
|
||||
cli.socketLock.RLock()
|
||||
defer cli.socketLock.RUnlock()
|
||||
err := cli.RefreshCAT()
|
||||
if err != nil {
|
||||
cli.Log.Errorf("Failed to refresh CAT: %v", err)
|
||||
cli.expectDisconnect()
|
||||
go cli.dispatchEvent(&events.CATRefreshError{Error: err})
|
||||
}
|
||||
default:
|
||||
cli.Log.Errorf("Unknown stream error: %s", node.XMLString())
|
||||
go cli.dispatchEvent(&events.StreamError{Code: code, Raw: node})
|
||||
@@ -89,9 +98,20 @@ func (cli *Client) handleConnectFailure(node *waBinary.Node) {
|
||||
willAutoReconnect = false
|
||||
case reason == events.ConnectFailureServiceUnavailable:
|
||||
// Auto-reconnect for 503s
|
||||
case reason == events.ConnectFailureCATInvalid || reason == events.ConnectFailureCATExpired:
|
||||
// Auto-reconnect when rotating CAT, lock socket to ensure refresh goes through before reconnect
|
||||
cli.socketLock.RLock()
|
||||
defer cli.socketLock.RUnlock()
|
||||
case reason == 500 && message == "biz vname fetch error":
|
||||
// These happen for business accounts randomly, also auto-reconnect
|
||||
}
|
||||
if reason == 403 {
|
||||
cli.Log.Debugf(
|
||||
"Message for 403 connect failure: %s / %s",
|
||||
ag.OptionalString("logout_message_header"),
|
||||
ag.OptionalString("logout_message_subtext"),
|
||||
)
|
||||
}
|
||||
if reason.IsLoggedOut() {
|
||||
cli.Log.Infof("Got %s connect failure, sending LoggedOut event and deleting session", reason)
|
||||
go cli.dispatchEvent(&events.LoggedOut{OnConnect: true, Reason: reason})
|
||||
@@ -108,6 +128,14 @@ func (cli *Client) handleConnectFailure(node *waBinary.Node) {
|
||||
} else if reason == events.ConnectFailureClientOutdated {
|
||||
cli.Log.Errorf("Client outdated (405) connect failure (client version: %s)", store.GetWAVersion().String())
|
||||
go cli.dispatchEvent(&events.ClientOutdated{})
|
||||
} else if reason == events.ConnectFailureCATInvalid || reason == events.ConnectFailureCATExpired {
|
||||
cli.Log.Infof("Got %d/%s connect failure, refreshing CAT before reconnecting...", int(reason), message)
|
||||
err := cli.RefreshCAT()
|
||||
if err != nil {
|
||||
cli.Log.Errorf("Failed to refresh CAT: %v", err)
|
||||
cli.expectDisconnect()
|
||||
go cli.dispatchEvent(&events.CATRefreshError{Error: err})
|
||||
}
|
||||
} else if willAutoReconnect {
|
||||
cli.Log.Warnf("Got %d/%s connect failure, assuming automatic reconnect will handle it", int(reason), message)
|
||||
} else {
|
||||
@@ -120,7 +148,7 @@ func (cli *Client) handleConnectSuccess(node *waBinary.Node) {
|
||||
cli.Log.Infof("Successfully authenticated")
|
||||
cli.LastSuccessfulConnect = time.Now()
|
||||
cli.AutoReconnectErrors = 0
|
||||
atomic.StoreUint32(&cli.isLoggedIn, 1)
|
||||
cli.isLoggedIn.Store(true)
|
||||
go func() {
|
||||
if dbCount, err := cli.Store.PreKeys.UploadedPreKeyCount(); err != nil {
|
||||
cli.Log.Errorf("Failed to get number of prekeys in database: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user