diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-27 01:14:06 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-11-27 01:14:06 +0300 |
commit | bcf222b53db2199cb6c784ac8c5b7105d794b6c9 (patch) | |
tree | 5ac884ce721f16defe68e7d41cc7173b38e6809b /telegram/connect.go | |
parent | 9a292fba943529e7465c24cd3283d097fcb05764 (diff) |
Fetch user info and chats on successful authorization
Diffstat (limited to 'telegram/connect.go')
-rw-r--r-- | telegram/connect.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/telegram/connect.go b/telegram/connect.go index 4f509d2..4fe262c 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -2,6 +2,7 @@ package telegram import ( "github.com/pkg/errors" + "math" "dev.narayana.im/narayana/telegabber/xmpp/gateway" @@ -9,6 +10,8 @@ import ( "github.com/zelenin/go-tdlib/client" ) +const chatsLimit int32 = 999 + type clientAuthorizer struct { TdlibParameters chan *client.TdlibParameters PhoneNumber chan string @@ -108,6 +111,7 @@ func (c *Client) Connect() error { c.client = tdlibClient c.online = true + c.ready <- true go updateHandler(c.client) @@ -153,8 +157,29 @@ func (c *Client) interactor() { log.Warn("Waiting for 2FA password...") gateway.SendMessage(c.jid, "", "Please, enter 2FA passphrase via /password 12345", c.xmpp) case client.TypeAuthorizationStateReady: + var err error + + <-c.ready + log.Warn("Authorization successful!") - // TODO + + 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.Error("Could not retrieve chats") + } + + gateway.SendPresence(c.xmpp, nil, c.jid, gateway.SPStatus("Logged in "+c.Session.Login)) + return } } |