Retry sending presences for recovered sessions
This commit is contained in:
parent
e4c9267347
commit
a09817976e
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue