diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-05 01:14:56 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-05 01:14:56 +0300 |
commit | c22008d991162fb0829af81ceb4d2f249eb5e262 (patch) | |
tree | 8b299c8163c0cb9af0a64f6f3bd020e5d401e8b4 /telegram | |
parent | 8cd6387552dc9b73c60950e8c1a47c84ae13f98b (diff) |
Send unavailable status to cached chats on disconnect
Diffstat (limited to 'telegram')
-rw-r--r-- | telegram/connect.go | 12 |
1 files changed, 11 insertions, 1 deletions
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 |