aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-22 04:04:45 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-22 04:04:45 +0300
commited8fd6415c2e7dc6ce4cd2907aea10ffe9b4ba55 (patch)
tree43d7fe245e99eb043648647815f5a9b08dffa936
parent915b7fe1de6bf8f726a596b000956ae14ecbf2a2 (diff)
Migrate some comments from Zhabogram; change queue behaviour
-rw-r--r--telegabber.go2
-rw-r--r--telegram/utils.go1
-rw-r--r--xmpp/component.go7
-rw-r--r--xmpp/handlers.go4
4 files changed, 13 insertions, 1 deletions
diff --git a/telegabber.go b/telegabber.go
index a196cc1..2752163 100644
--- a/telegabber.go
+++ b/telegabber.go
@@ -56,6 +56,8 @@ func main() {
if err != nil {
<-cleanupDone
log.Fatal(err)
+ // bye
+ os.Exit(-1)
}
}
diff --git a/telegram/utils.go b/telegram/utils.go
index 1983367..cef5167 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -129,6 +129,7 @@ func (c *Client) userStatusToText(status client.UserStatus) (string, string) {
return show, textStatus
}
+// set contact status
func (c *Client) processStatusUpdate(chatID int64, status string, show string, args ...args.V) error {
if !c.Online() {
return nil
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()
}
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index f7f628b..2addd7b 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -148,6 +148,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
}).Warn("Presence")
log.Debugf("%#v", p)
+ // create session
fromJid, err := xmpp.NewJid(p.From)
if err != nil {
log.Error("Invalid from JID!")
@@ -160,11 +161,14 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
}
switch p.Type {
+ // destroy session
case "unsubscribed", "unsubscribe":
session.Disconnect()
delete(sessions, bareFromJid)
+ // go offline
case "unavailable", "error":
session.Disconnect()
+ // go online
case "probe", "", "online":
// due to the weird implementation of go-tdlib wrapper, it won't
// return the client instance until successful authorization