Retry sending presences for recovered sessions
This commit is contained in:
parent
e4c9267347
commit
a09817976e
|
@ -15,6 +15,8 @@ import (
|
||||||
"gosrc.io/xmpp/stanza"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pollingInterval time.Duration = 1e7
|
||||||
|
|
||||||
var jid *xmpp.Jid
|
var jid *xmpp.Jid
|
||||||
var tgConf config.TelegramConfig
|
var tgConf config.TelegramConfig
|
||||||
var sessions map[string]telegram.Client
|
var sessions map[string]telegram.Client
|
||||||
|
@ -73,9 +75,17 @@ func heartbeat(component *xmpp.Component) {
|
||||||
probeType := SPType("probe")
|
probeType := SPType("probe")
|
||||||
|
|
||||||
for jid := range sessions {
|
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 {
|
||||||
for key, presence := range queue {
|
for key, presence := range queue {
|
||||||
err = component.Send(presence)
|
err = component.Send(presence)
|
||||||
|
@ -183,7 +193,7 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
|
||||||
return 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
|
var logFrom string
|
||||||
bareJid := jid.Bare()
|
bareJid := jid.Bare()
|
||||||
if SPFrom.IsSet(args) {
|
if SPFrom.IsSet(args) {
|
||||||
|
@ -210,8 +220,11 @@ func sendPresence(component *xmpp.Component, to string, args ...args.V) {
|
||||||
err := component.Send(presence)
|
err := component.Send(presence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logPresence(err, &presence)
|
logPresence(err, &presence)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
queue[presence.From+presence.To] = &presence
|
queue[presence.From+presence.To] = &presence
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue