diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-04 18:55:15 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-04 18:55:15 +0300 |
commit | 354a4acd19d5376477275588d3e170df6a688697 (patch) | |
tree | 380de3d9b7fe1868760068f2a63717c5e3d5633b /xmpp | |
parent | 3ce5081800ebf1ca92d32f1a051db4671b5105d3 (diff) |
Fix session restoring
Diffstat (limited to 'xmpp')
-rw-r--r-- | xmpp/component.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/xmpp/component.go b/xmpp/component.go index 57d9c7b..bc81126 100644 --- a/xmpp/component.go +++ b/xmpp/component.go @@ -13,11 +13,9 @@ import ( "gosrc.io/xmpp" ) -const pollingInterval time.Duration = 1e7 - var tgConf config.TelegramConfig var sessions map[string]*telegram.Client -var db persistence.SessionsYamlDB +var db *persistence.SessionsYamlDB // NewComponent starts a new component and wraps it in // a stream manager that you should start yourself @@ -53,9 +51,9 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea return nil, nil, err } - sm := xmpp.NewStreamManager(component, nil) - - go heartbeat(component) + sm := xmpp.NewStreamManager(component, func(s xmpp.Sender) { + go heartbeat(component) + }) return sm, component, nil } @@ -65,12 +63,9 @@ func heartbeat(component *xmpp.Component) { probeType := gateway.SPType("probe") for jid := range sessions { - for { - err = gateway.SendPresence(component, jid, probeType) - if err == nil { - break - } - time.Sleep(pollingInterval) + err = gateway.SendPresence(component, jid, probeType) + if err != nil { + log.Error(err) } } |