aboutsummaryrefslogtreecommitdiff
path: root/xmpp/component.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/component.go')
-rw-r--r--xmpp/component.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/xmpp/component.go b/xmpp/component.go
index bc81126..d1c71ae 100644
--- a/xmpp/component.go
+++ b/xmpp/component.go
@@ -46,6 +46,7 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
return nil, nil, err
}
+ // probe all known sessions
err = loadSessions(conf.Db, component)
if err != nil {
return nil, nil, err
@@ -71,7 +72,9 @@ func heartbeat(component *xmpp.Component) {
log.Info("Starting heartbeat queue")
+ // status updater thread
for {
+ time.Sleep(60e9)
for key, presence := range gateway.Queue {
err = component.Send(presence)
if err != nil {
@@ -80,7 +83,6 @@ func heartbeat(component *xmpp.Component) {
delete(gateway.Queue, key)
}
}
- time.Sleep(60e9)
}
}
@@ -124,10 +126,12 @@ func getTelegramInstance(jid string, savedSession *persistence.Session, componen
func Close(component *xmpp.Component) {
log.Error("Disconnecting...")
+ // close all sessions
for _, session := range sessions {
session.Disconnect()
}
+ // save sessions
db.Transaction(func() bool {
for jid, session := range sessions {
db.Data.Sessions[jid] = *session.Session
@@ -136,5 +140,6 @@ func Close(component *xmpp.Component) {
return true
}, persistence.SessionMarshaller)
+ // close stream
component.Disconnect()
}