|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|