diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-22 04:04:45 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-22 04:04:45 +0300 |
commit | ed8fd6415c2e7dc6ce4cd2907aea10ffe9b4ba55 (patch) | |
tree | 43d7fe245e99eb043648647815f5a9b08dffa936 /xmpp/component.go | |
parent | 915b7fe1de6bf8f726a596b000956ae14ecbf2a2 (diff) |
Migrate some comments from Zhabogram; change queue behaviour
Diffstat (limited to 'xmpp/component.go')
-rw-r--r-- | xmpp/component.go | 7 |
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() } |