Catch timeout setting

This commit is contained in:
bodqhrohro 2019-12-16 03:02:53 +02:00
parent 3918686f21
commit 10aae376f7
4 changed files with 23 additions and 12 deletions

View file

@ -14,6 +14,7 @@
:application_version: '2.0' :application_version: '2.0'
:use_chat_info_database: false :use_chat_info_database: false
:use_secret_chats: true :use_secret_chats: true
:catch_timeout: 60
:xmpp: :xmpp:
:loglevel: :warn :loglevel: :warn

View file

@ -54,6 +54,7 @@ type TelegramTdlibClientConfig struct {
ApplicationVersion string `yaml:":application_version"` ApplicationVersion string `yaml:":application_version"`
UseChatInfoDatabase bool `yaml:":use_chat_info_database"` UseChatInfoDatabase bool `yaml:":use_chat_info_database"`
UseSecretChats bool `yaml:":use_secret_chats"` UseSecretChats bool `yaml:":use_secret_chats"`
CatchTimeout int64 `yaml:":catch_timeout"`
} }
// ReadConfig reads the specified config file, validates it and returns a struct // ReadConfig reads the specified config file, validates it and returns a struct

View file

@ -5,6 +5,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"sync" "sync"
"time"
"dev.narayana.im/narayana/telegabber/config" "dev.narayana.im/narayana/telegabber/config"
"dev.narayana.im/narayana/telegabber/persistence" "dev.narayana.im/narayana/telegabber/persistence"
@ -42,7 +43,7 @@ type Client struct {
client *client.Client client *client.Client
authorizer *clientAuthorizer authorizer *clientAuthorizer
parameters *client.TdlibParameters parameters *client.TdlibParameters
logVerbosity client.Option options []client.Option
me *client.User me *client.User
listener *client.Listener listener *client.Listener
@ -61,9 +62,17 @@ type clientLocks struct {
// NewClient instantiates a Telegram App // NewClient instantiates a Telegram App
func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component, session *persistence.Session) (*Client, error) { 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), 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) apiID, err := strconv.Atoi(conf.Tdlib.Client.APIID)
if err != nil { if err != nil {
@ -103,7 +112,7 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
chats: map[int64]*client.Chat{}, chats: map[int64]*client.Chat{},
users: map[int32]*client.User{}, users: map[int32]*client.User{},
}, },
logVerbosity: logVerbosity, options: options,
locks: clientLocks{}, locks: clientLocks{},
}, nil }, nil
} }

View file

@ -110,7 +110,7 @@ func (c *Client) Connect() error {
c.authorizer.TdlibParameters <- c.parameters c.authorizer.TdlibParameters <- c.parameters
tdlibClient, err := client.NewClient(c.authorizer, c.logVerbosity) tdlibClient, err := client.NewClient(c.authorizer, c.options...)
if err != nil { if err != nil {
return errors.Wrap(err, "Couldn't initialize a Telegram client instance") return errors.Wrap(err, "Couldn't initialize a Telegram client instance")
} }
@ -145,7 +145,7 @@ func (c *Client) Disconnect() {
_, err := c.client.Close() _, err := c.client.Close()
if err != nil { if err != nil {
log.Fatalf("Couldn't close the Telegram instance: %#v", c) log.Errorf("Couldn't close the Telegram instance: %v; %#v", err, c)
} }
} }