|
|
|
@ -87,7 +87,7 @@ func (stateHandler *clientAuthorizer) Close() {
|
|
|
|
|
|
|
|
|
|
// Connect starts TDlib connection
|
|
|
|
|
func (c *Client) Connect() error {
|
|
|
|
|
if c.online {
|
|
|
|
|
if c.Online() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -113,8 +113,8 @@ func (c *Client) Connect() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.client = tdlibClient
|
|
|
|
|
c.online = true
|
|
|
|
|
c.locks.authorizationReady.Done()
|
|
|
|
|
c.listener = tdlibClient.GetListener()
|
|
|
|
|
|
|
|
|
|
go c.updateHandler()
|
|
|
|
|
|
|
|
|
@ -124,7 +124,7 @@ func (c *Client) Connect() error {
|
|
|
|
|
// Disconnect drops TDlib connection
|
|
|
|
|
func (c *Client) Disconnect() {
|
|
|
|
|
// already disconnected
|
|
|
|
|
if !c.online {
|
|
|
|
|
if !c.Online() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,14 +140,17 @@ func (c *Client) Disconnect() {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.client.Destroy()
|
|
|
|
|
c.online = false
|
|
|
|
|
_, err := c.client.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Couldn't close the Telegram instance: %#v", c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) interactor() {
|
|
|
|
|
for {
|
|
|
|
|
state, ok := <-c.authorizer.State
|
|
|
|
|
if !ok {
|
|
|
|
|
log.Error("Interactor is disconnected")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -192,8 +195,14 @@ func (c *Client) interactor() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in "+c.Session.Login))
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
case client.TypeAuthorizationStateClosed:
|
|
|
|
|
log.Warn("Closing the updates listener")
|
|
|
|
|
c.listener.Close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Online checks if the updates listener is alive
|
|
|
|
|
func (c *Client) Online() bool {
|
|
|
|
|
return c.listener != nil && c.listener.IsActive()
|
|
|
|
|
}
|
|
|
|
|