aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-11-18 22:01:45 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-11-18 22:01:45 +0300
commita09817976ee5cdb7d1bca25c80cdef3d1b7867f7 (patch)
tree9842e66eb52617220178ea57993260a06be218ac
parente4c9267347c4aebf3fab55ef9d90056f265ef6f0 (diff)
Retry sending presences for recovered sessions
-rw-r--r--xmpp/component.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/xmpp/component.go b/xmpp/component.go
index 55e7a7b..d82f4bb 100644
--- a/xmpp/component.go
+++ b/xmpp/component.go
@@ -15,6 +15,8 @@ import (
"gosrc.io/xmpp/stanza"
)
+const pollingInterval time.Duration = 1e7
+
var jid *xmpp.Jid
var tgConf config.TelegramConfig
var sessions map[string]telegram.Client
@@ -73,9 +75,17 @@ func heartbeat(component *xmpp.Component) {
probeType := SPType("probe")
for jid := range sessions {
- sendPresence(component, jid, probeType)
+ for {
+ err = sendPresence(component, jid, probeType)
+ if err == nil {
+ break
+ }
+ time.Sleep(pollingInterval)
+ }
}
+ log.Info("Starting heartbeat queue")
+
for {
for key, presence := range queue {
err = component.Send(presence)
@@ -183,7 +193,7 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
return presence
}
-func sendPresence(component *xmpp.Component, to string, args ...args.V) {
+func sendPresence(component *xmpp.Component, to string, args ...args.V) error {
var logFrom string
bareJid := jid.Bare()
if SPFrom.IsSet(args) {
@@ -210,8 +220,11 @@ func sendPresence(component *xmpp.Component, to string, args ...args.V) {
err := component.Send(presence)
if err != nil {
logPresence(err, &presence)
+ return err
}
} else {
queue[presence.From+presence.To] = &presence
}
+
+ return nil
}