Add /cancelauth command && unsubscribe from chats more eagerly

This commit is contained in:
Bohdan Horbeshko 2025-10-09 11:32:33 -04:00
parent 140cf7fa4a
commit e7c6318e48
4 changed files with 16 additions and 6 deletions

View file

@ -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:

View file

@ -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

View file

@ -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() {

View file

@ -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)