|
|
|
@ -24,6 +24,9 @@ type clientAuthorizer struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.AuthorizationState) error {
|
|
|
|
|
if stateHandler.isClosed {
|
|
|
|
|
return errors.New("Channel is closed")
|
|
|
|
|
}
|
|
|
|
|
stateHandler.State <- state
|
|
|
|
|
|
|
|
|
|
switch state.AuthorizationStateType() {
|
|
|
|
@ -84,6 +87,9 @@ func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.Auth
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (stateHandler *clientAuthorizer) Close() {
|
|
|
|
|
if stateHandler.isClosed {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
stateHandler.isClosed = true
|
|
|
|
|
close(stateHandler.TdlibParameters)
|
|
|
|
|
close(stateHandler.PhoneNumber)
|
|
|
|
@ -191,11 +197,7 @@ func (c *Client) Disconnect(resource string, quit bool) bool {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.client.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Couldn't close the Telegram instance: %v; %#v", err, c)
|
|
|
|
|
}
|
|
|
|
|
c.forceClose()
|
|
|
|
|
c.close()
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
@ -242,6 +244,24 @@ func (c *Client) forceClose() {
|
|
|
|
|
c.authorizer = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) close() {
|
|
|
|
|
if c.authorizer != nil && !c.authorizer.isClosed {
|
|
|
|
|
c.authorizer.Close()
|
|
|
|
|
}
|
|
|
|
|
if c.client != nil {
|
|
|
|
|
_, err := c.client.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("Couldn't close the Telegram instance: %v; %#v", err, c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
c.forceClose()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) cancelAuth() {
|
|
|
|
|
c.close()
|
|
|
|
|
c.Session.Login = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Online checks if the updates listener is alive
|
|
|
|
|
func (c *Client) Online() bool {
|
|
|
|
|
return c.online
|
|
|
|
|