|
|
|
@ -5,6 +5,7 @@ import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strconv"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"dev.narayana.im/narayana/telegabber/config"
|
|
|
|
|
"dev.narayana.im/narayana/telegabber/persistence"
|
|
|
|
@ -39,12 +40,12 @@ func stringToLogConstant(c string) int32 {
|
|
|
|
|
|
|
|
|
|
// Client stores the metadata for lazily invoked TDlib instance
|
|
|
|
|
type Client struct {
|
|
|
|
|
client *client.Client
|
|
|
|
|
authorizer *clientAuthorizer
|
|
|
|
|
parameters *client.TdlibParameters
|
|
|
|
|
logVerbosity client.Option
|
|
|
|
|
me *client.User
|
|
|
|
|
listener *client.Listener
|
|
|
|
|
client *client.Client
|
|
|
|
|
authorizer *clientAuthorizer
|
|
|
|
|
parameters *client.TdlibParameters
|
|
|
|
|
options []client.Option
|
|
|
|
|
me *client.User
|
|
|
|
|
listener *client.Listener
|
|
|
|
|
|
|
|
|
|
xmpp *xmpp.Component
|
|
|
|
|
jid string
|
|
|
|
@ -61,9 +62,17 @@ type clientLocks struct {
|
|
|
|
|
|
|
|
|
|
// NewClient instantiates a Telegram App
|
|
|
|
|
func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component, session *persistence.Session) (*Client, error) {
|
|
|
|
|
logVerbosity := client.WithLogVerbosity(&client.SetLogVerbosityLevelRequest{
|
|
|
|
|
var options []client.Option
|
|
|
|
|
|
|
|
|
|
options = append(options, client.WithLogVerbosity(&client.SetLogVerbosityLevelRequest{
|
|
|
|
|
NewVerbosityLevel: stringToLogConstant(conf.Loglevel),
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
if conf.Tdlib.Client.CatchTimeout != 0 {
|
|
|
|
|
options = append(options, client.WithCatchTimeout(
|
|
|
|
|
time.Duration(conf.Tdlib.Client.CatchTimeout)*time.Second,
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apiID, err := strconv.Atoi(conf.Tdlib.Client.APIID)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -103,7 +112,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
|
|
|
|
|
chats: map[int64]*client.Chat{},
|
|
|
|
|
users: map[int32]*client.User{},
|
|
|
|
|
},
|
|
|
|
|
logVerbosity: logVerbosity,
|
|
|
|
|
locks: clientLocks{},
|
|
|
|
|
options: options,
|
|
|
|
|
locks: clientLocks{},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|