diff options
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/connectionevents.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/connectionevents.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/connectionevents.go b/vendor/go.mau.fi/whatsmeow/connectionevents.go index c1a6e764..82a39184 100644 --- a/vendor/go.mau.fi/whatsmeow/connectionevents.go +++ b/vendor/go.mau.fi/whatsmeow/connectionevents.go @@ -33,7 +33,7 @@ func (cli *Client) handleStreamError(node *waBinary.Node) { case code == "401" && conflictType == "device_removed": cli.expectDisconnect() cli.Log.Infof("Got device removed stream error, sending LoggedOut event and deleting session") - go cli.dispatchEvent(&events.LoggedOut{OnConnect: false}) + go cli.dispatchEvent(&events.LoggedOut{OnConnect: false, Reason: events.ConnectFailureLoggedOut}) err := cli.Store.Delete() if err != nil { cli.Log.Warnf("Failed to delete store after device_removed error: %v", err) @@ -77,17 +77,30 @@ func (cli *Client) handleIB(node *waBinary.Node) { func (cli *Client) handleConnectFailure(node *waBinary.Node) { ag := node.AttrGetter() - reason := ag.String("reason") - if reason == "401" { - cli.expectDisconnect() - cli.Log.Infof("Got 401 connect failure, sending LoggedOut event and deleting session") - go cli.dispatchEvent(&events.LoggedOut{OnConnect: true}) + reason := events.ConnectFailureReason(ag.Int("reason")) + cli.expectDisconnect() + 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}) err := cli.Store.Delete() if err != nil { - cli.Log.Warnf("Failed to delete store after 401 failure: %v", err) + cli.Log.Warnf("Failed to delete store after %d failure: %v", int(reason), err) + } + } else if reason == events.ConnectFailureTempBanned { + cli.Log.Warnf("Temporary ban connect failure: %s", node.XMLString()) + expiryTimeUnix := ag.Int64("expire") + var expiryTime time.Time + if expiryTimeUnix > 0 { + expiryTime = time.Unix(expiryTimeUnix, 0) } + go cli.dispatchEvent(&events.TemporaryBan{ + Code: events.TempBanReason(ag.Int("code")), + Expire: expiryTime, + }) + } else if reason == events.ConnectFailureClientOutdated { + cli.Log.Errorf("Client outdated (405) connect failure") + go cli.dispatchEvent(&events.ClientOutdated{}) } else { - cli.expectDisconnect() cli.Log.Warnf("Unknown connect failure: %s", node.XMLString()) go cli.dispatchEvent(&events.ConnectFailure{Reason: reason, Raw: node}) } |