From a09817976ee5cdb7d1bca25c80cdef3d1b7867f7 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Mon, 18 Nov 2019 21:01:45 +0200 Subject: [PATCH] Retry sending presences for recovered sessions --- xmpp/component.go | 17 +++++++++++++++-- 1 file 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 }