diff --git a/telegram/connect.go b/telegram/connect.go index 478f5a3..7e9154c 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -3,6 +3,7 @@ package telegram import ( "github.com/pkg/errors" "math" + "strconv" "dev.narayana.im/narayana/telegabber/xmpp/gateway" @@ -122,13 +123,22 @@ func (c *Client) Connect() error { // Disconnect drops TDlib connection func (c *Client) Disconnect() { + // already disconnected if !c.online { return } 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.online = false