From e7c6318e48fa4d89495b26adb9a210dbc7609a63 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 9 Oct 2025 11:32:33 -0400 Subject: [PATCH] Add /cancelauth command && unsubscribe from chats more eagerly --- Makefile | 2 +- telegabber.go | 2 +- telegram/commands.go | 14 +++++++++++--- telegram/connect.go | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3182744..71aeabf 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ COMMIT := $(shell git rev-parse --short HEAD) TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551" -VERSION := "v1.12.6" +VERSION := "v1.12.7" MAKEOPTS := "-j4" all: diff --git a/telegabber.go b/telegabber.go index cbc58b3..6fb5d5b 100644 --- a/telegabber.go +++ b/telegabber.go @@ -16,7 +16,7 @@ import ( goxmpp "gosrc.io/xmpp" ) -var version string = "1.12.6" +var version string = "1.12.7" var commit string var sm *goxmpp.StreamManager diff --git a/telegram/commands.go b/telegram/commands.go index 1c066e0..fa38efb 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -54,6 +54,7 @@ var transportCommands = map[string]command{ "help": command{0, []string{}, "help", false, nil}, "login": command{1, []string{"phone"}, "sign in", false, nil}, "logout": command{0, []string{}, "sign out", true, nil}, + "cleanup": command{0, []string{}, "unsubscribe from all known chats", false, nil}, "cancelauth": command{0, []string{}, "quit the signin wizard", false, nil}, "code": command{1, []string{"xxxxx"}, "check one-time code", false, nil}, "password": command{1, []string{"********"}, "check 2fa password", false, nil}, @@ -279,6 +280,12 @@ func (c *Client) unsubscribe(chatID int64) error { return c.sendPresence(args...) } +func (c *Client) unsubscribeFromAll() { + for _, id := range c.cache.ChatsKeys() { + c.unsubscribe(id) + } +} + func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) { for i := len(messages) - 1; i >= 0; i-- { message := messages[i] @@ -378,11 +385,12 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin return errors.Wrap(err, "Logout error").Error(), false } - for _, id := range c.cache.OwnChatsKeys() { - c.unsubscribe(id) - } + c.unsubscribeFromAll() c.Session.Login = "" + // cleanup + case "cleanup": + c.unsubscribeFromAll() // cancel auth case "cancelauth": if c.Online() { diff --git a/telegram/connect.go b/telegram/connect.go index 8a2b928..27d63c7 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -153,11 +153,13 @@ func (c *Client) Connect(resource string) error { c.addResource(resource) go func() { - _, err = c.client.GetChats(&client.GetChatsRequest{ + chats, err := c.client.GetChats(&client.GetChatsRequest{ Limit: chatsLimit, }) if err != nil { log.Errorf("Could not retrieve chats: %v", err) + } else { + log.Infof("Obtained ≈%v chats for initialization", chats.TotalCount) } gateway.SubscribeToTransport(c.xmpp, c.jid)