diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-29 03:51:41 +0300 |
commit | dbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 (patch) | |
tree | 784f16c7e27444c03b865e1f4c03aadac1f18bf8 /telegram/connect.go | |
parent | bcf222b53db2199cb6c784ac8c5b7105d794b6c9 (diff) |
Handle updates of user status
Diffstat (limited to 'telegram/connect.go')
-rw-r--r-- | telegram/connect.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/telegram/connect.go b/telegram/connect.go index 4fe262c..f1b3dc5 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -100,6 +100,8 @@ func (c *Client) Connect() error { Password: make(chan string, 1), } + c.locks.authorizationReady.Add(1) + go c.interactor() c.authorizer.TdlibParameters <- c.parameters @@ -111,9 +113,9 @@ func (c *Client) Connect() error { c.client = tdlibClient c.online = true - c.ready <- true + c.locks.authorizationReady.Done() - go updateHandler(c.client) + go c.updateHandler() return nil } @@ -141,6 +143,7 @@ func (c *Client) interactor() { stateType := state.AuthorizationStateType() log.Infof("Telegram authorization state: %#v", stateType) + log.Debugf("%#v", state) switch stateType { case client.TypeAuthorizationStateWaitPhoneNumber: @@ -159,7 +162,7 @@ func (c *Client) interactor() { case client.TypeAuthorizationStateReady: var err error - <-c.ready + c.locks.authorizationReady.Wait() log.Warn("Authorization successful!") @@ -178,7 +181,7 @@ func (c *Client) interactor() { log.Error("Could not retrieve chats") } - gateway.SendPresence(c.xmpp, nil, c.jid, gateway.SPStatus("Logged in "+c.Session.Login)) + gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in "+c.Session.Login)) return } |