diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-01 02:34:04 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-01 02:34:04 +0300 |
commit | 462a537021f471579877eceb1dd6c47154d8052d (patch) | |
tree | 82fb230b04cba5758fc22dea2d8aa5b119eced5e | |
parent | d36f4449c94b942d1795ae4865b77b7fde43b35b (diff) |
Fix subscriptions after logging in
-rw-r--r-- | telegram/connect.go | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/telegram/connect.go b/telegram/connect.go index 9937970..7221453 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -117,9 +117,31 @@ func (c *Client) Connect() error { c.client = tdlibClient c.locks.authorizationReady.Done() - c.online = true + + // stage 3: if a client is succesfully created, AuthorizationStateReady is already reached + log.Warn("Authorization successful!") + + c.me, err = c.client.GetMe() + if err != nil { + log.Error("Could not retrieve me info") + } else if c.Session.Login == "" { + c.Session.Login = c.me.PhoneNumber + } go c.updateHandler() + c.online = true + + _, err = c.client.GetChats(&client.GetChatsRequest{ + OffsetOrder: client.JsonInt64(math.MaxInt64), + Limit: chatsLimit, + }) + if err != nil { + log.Errorf("Could not retrieve chats: %v", err) + } + + gateway.SendPresence(c.xmpp, c.jid, gateway.SPType("subscribe")) + gateway.SendPresence(c.xmpp, c.jid, gateway.SPType("subscribed")) + gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in as: "+c.Session.Login)) return nil } @@ -179,32 +201,6 @@ func (c *Client) interactor() { case client.TypeAuthorizationStateWaitPassword: log.Warn("Waiting for 2FA password...") gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", c.xmpp) - // stage 3: auth completed - case client.TypeAuthorizationStateReady: - var err error - - c.locks.authorizationReady.Wait() - - log.Warn("Authorization successful!") - - c.me, err = c.client.GetMe() - if err != nil { - log.Error("Could not retrieve me info") - } else if c.Session.Login == "" { - c.Session.Login = c.me.PhoneNumber - } - - _, err = c.client.GetChats(&client.GetChatsRequest{ - OffsetOrder: client.JsonInt64(math.MaxInt64), - Limit: chatsLimit, - }) - if err != nil { - log.Errorf("Could not retrieve chats: %v", err) - } - - gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in "+c.Session.Login)) - - return } } } |