From dbe87fafa8fb3c38d6cb22ac335cc76b70b607a6 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Fri, 29 Nov 2019 02:51:41 +0200 Subject: Handle updates of user status --- telegram/connect.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'telegram/connect.go') 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 } -- cgit v1.2.3