aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-16 04:02:53 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-16 04:02:53 +0300
commit10aae376f7dae843a5472cfc5c7083b4c032021d (patch)
treec5356518819df8f3863599a456602a0a4bcedae4
parent3918686f211a3eac60916a81423c64240ad1988a (diff)
Catch timeout setting
-rw-r--r--config.yml.example1
-rw-r--r--config/config.go1
-rw-r--r--telegram/client.go29
-rw-r--r--telegram/connect.go4
4 files changed, 23 insertions, 12 deletions
diff --git a/config.yml.example b/config.yml.example
index 5179508..1be5b61 100644
--- a/config.yml.example
+++ b/config.yml.example
@@ -14,6 +14,7 @@
:application_version: '2.0'
:use_chat_info_database: false
:use_secret_chats: true
+ :catch_timeout: 60
:xmpp:
:loglevel: :warn
diff --git a/config/config.go b/config/config.go
index bcd493e..dad6706 100644
--- a/config/config.go
+++ b/config/config.go
@@ -54,6 +54,7 @@ type TelegramTdlibClientConfig struct {
ApplicationVersion string `yaml:":application_version"`
UseChatInfoDatabase bool `yaml:":use_chat_info_database"`
UseSecretChats bool `yaml:":use_secret_chats"`
+ CatchTimeout int64 `yaml:":catch_timeout"`
}
// ReadConfig reads the specified config file, validates it and returns a struct
diff --git a/telegram/client.go b/telegram/client.go
index 5e9dd9f..133f1e6 100644
--- a/telegram/client.go
+++ b/telegram/client.go
@@ -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
}
diff --git a/telegram/connect.go b/telegram/connect.go
index 8988528..3827bcc 100644
--- a/telegram/connect.go
+++ b/telegram/connect.go
@@ -110,7 +110,7 @@ func (c *Client) Connect() error {
c.authorizer.TdlibParameters <- c.parameters
- tdlibClient, err := client.NewClient(c.authorizer, c.logVerbosity)
+ tdlibClient, err := client.NewClient(c.authorizer, c.options...)
if err != nil {
return errors.Wrap(err, "Couldn't initialize a Telegram client instance")
}
@@ -145,7 +145,7 @@ func (c *Client) Disconnect() {
_, err := c.client.Close()
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)
}
}