Handle unsubscribe presence too, improve logging
This commit is contained in:
parent
f0c0d0ba94
commit
c0c21a35a4
|
@ -3,6 +3,7 @@ package telegram
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/zelenin/go-tdlib/client"
|
"github.com/zelenin/go-tdlib/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,6 +13,8 @@ func (c *Client) Connect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Warn("Connecting to Telegram network...")
|
||||||
|
|
||||||
authorizer := client.ClientAuthorizer()
|
authorizer := client.ClientAuthorizer()
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
@ -48,6 +51,10 @@ func (c *Client) Disconnect() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Warn("Disconnecting from Telegram network...")
|
||||||
|
|
||||||
|
// TODO: send unavailable presence to cached chats
|
||||||
|
|
||||||
c.client.Stop()
|
c.client.Stop()
|
||||||
c.online = false
|
c.online = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch p.Type {
|
switch p.Type {
|
||||||
case "unsubscribed":
|
case "unsubscribed", "unsubscribe":
|
||||||
session.Disconnect()
|
session.Disconnect()
|
||||||
delete(sessions, bareFromJid)
|
delete(sessions, bareFromJid)
|
||||||
case "unavailable", "error":
|
case "unavailable", "error":
|
||||||
|
@ -105,7 +105,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
// due to the weird implentation of go-tdlib wrapper, it won't
|
// due to the weird implentation of go-tdlib wrapper, it won't
|
||||||
// return the client instance until successful authorization
|
// return the client instance until successful authorization
|
||||||
go func() {
|
go func() {
|
||||||
session.Connect()
|
err = session.Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(errors.Wrap(err, "TDlib connection failure"))
|
log.Error(errors.Wrap(err, "TDlib connection failure"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue