aboutsummaryrefslogtreecommitdiff
path: root/telegram/connect.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/connect.go')
-rw-r--r--telegram/connect.go11
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
}