Reconnect fix
This commit is contained in:
parent
10aae376f7
commit
05a9aca537
|
@ -146,6 +146,7 @@ func (c *Client) Disconnect() {
|
|||
_, err := c.client.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Couldn't close the Telegram instance: %v; %#v", err, c)
|
||||
c.forceClose()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,11 +199,14 @@ func (c *Client) interactor() {
|
|||
}
|
||||
|
||||
gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in "+c.Session.Login))
|
||||
case client.TypeAuthorizationStateClosed:
|
||||
log.Warn("Closing the updates listener")
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) forceClose() {
|
||||
c.listener.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Online checks if the updates listener is alive
|
||||
|
|
|
@ -90,6 +90,12 @@ func (c *Client) updateHandler() {
|
|||
}
|
||||
c.updateFile(typedUpdate)
|
||||
log.Debugf("%#v", typedUpdate.File)
|
||||
case client.TypeUpdateAuthorizationState:
|
||||
typedUpdate, ok := update.(*client.UpdateAuthorizationState)
|
||||
if !ok {
|
||||
uhOh()
|
||||
}
|
||||
c.updateAuthorizationState(typedUpdate)
|
||||
default:
|
||||
// log only handled types
|
||||
continue
|
||||
|
@ -242,3 +248,13 @@ func (c *Client) updateFile(update *client.UpdateFile) {
|
|||
log.Errorf("Error creating symlink: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) updateAuthorizationState(update *client.UpdateAuthorizationState) {
|
||||
switch update.AuthorizationState.AuthorizationStateType() {
|
||||
case client.TypeAuthorizationStateClosing:
|
||||
log.Warn("Closing the updates listener")
|
||||
case client.TypeAuthorizationStateClosed:
|
||||
log.Warn("Closed the updates listener")
|
||||
c.forceClose()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue