Send unavailable status to cached chats on disconnect

This commit is contained in:
bodqhrohro 2019-12-05 00:14:56 +02:00
parent 8cd6387552
commit c22008d991

View file

@ -3,6 +3,7 @@ package telegram
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
"math" "math"
"strconv"
"dev.narayana.im/narayana/telegabber/xmpp/gateway" "dev.narayana.im/narayana/telegabber/xmpp/gateway"
@ -122,13 +123,22 @@ func (c *Client) Connect() error {
// Disconnect drops TDlib connection // Disconnect drops TDlib connection
func (c *Client) Disconnect() { func (c *Client) Disconnect() {
// already disconnected
if !c.online { if !c.online {
return return
} }
log.Warn("Disconnecting from Telegram network...") log.Warn("Disconnecting from Telegram network...")
// TODO: send unavailable presence to cached chats // we're offline (unsubscribe if logout)
for id := range c.cache.chats {
gateway.SendPresence(
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(id, 10)),
gateway.SPType("unavailable"),
)
}
c.client.Destroy() c.client.Destroy()
c.online = false c.online = false