From c22008d991162fb0829af81ceb4d2f249eb5e262 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Thu, 5 Dec 2019 00:14:56 +0200 Subject: [PATCH] Send unavailable status to cached chats on disconnect --- telegram/connect.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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