aboutsummaryrefslogtreecommitdiff
path: root/xmpp/component.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/component.go')
-rw-r--r--xmpp/component.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/xmpp/component.go b/xmpp/component.go
index 0f23d50..f0c481d 100644
--- a/xmpp/component.go
+++ b/xmpp/component.go
@@ -7,6 +7,7 @@ import (
"sync"
"time"
+ "dev.narayana.im/narayana/telegabber/badger"
"dev.narayana.im/narayana/telegabber/config"
"dev.narayana.im/narayana/telegabber/persistence"
"dev.narayana.im/narayana/telegabber/telegram"
@@ -38,7 +39,7 @@ var sizeRegex = regexp.MustCompile("\\A([0-9]+) ?([KMGTPE]?B?)\\z")
// NewComponent starts a new component and wraps it in
// a stream manager that you should start yourself
-func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.StreamManager, *xmpp.Component, error) {
+func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig, idsPath string) (*xmpp.StreamManager, *xmpp.Component, error) {
var err error
gateway.Jid, err = stanza.NewJid(conf.Jid)
@@ -53,6 +54,8 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
}
}
+ gateway.IdsDB = badger.IdsDBOpen(idsPath)
+
tgConf = tc
if tc.Content.Quota != "" {
@@ -163,6 +166,8 @@ func heartbeat(component *xmpp.Component) {
// it would be resolved on the next iteration
SaveSessions()
}
+
+ gateway.IdsDB.Gc()
}
}
@@ -240,6 +245,9 @@ func Close(component *xmpp.Component) {
// save sessions
SaveSessions()
+ // flush the ids database
+ gateway.IdsDB.Close()
+
// close stream
component.Disconnect()
}