From ed8fd6415c2e7dc6ce4cd2907aea10ffe9b4ba55 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Sun, 22 Dec 2019 03:04:45 +0200 Subject: Migrate some comments from Zhabogram; change queue behaviour --- xmpp/component.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'xmpp/component.go') 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() } -- cgit v1.2.3