mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
Add /cancelauth command && unsubscribe from chats more eagerly
This commit is contained in:
parent
140cf7fa4a
commit
e7c6318e48
4 changed files with 16 additions and 6 deletions
2
Makefile
2
Makefile
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
COMMIT := $(shell git rev-parse --short HEAD)
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
||||||
VERSION := "v1.12.6"
|
VERSION := "v1.12.7"
|
||||||
MAKEOPTS := "-j4"
|
MAKEOPTS := "-j4"
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
goxmpp "gosrc.io/xmpp"
|
goxmpp "gosrc.io/xmpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "1.12.6"
|
var version string = "1.12.7"
|
||||||
var commit string
|
var commit string
|
||||||
|
|
||||||
var sm *goxmpp.StreamManager
|
var sm *goxmpp.StreamManager
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ var transportCommands = map[string]command{
|
||||||
"help": command{0, []string{}, "help", false, nil},
|
"help": command{0, []string{}, "help", false, nil},
|
||||||
"login": command{1, []string{"phone"}, "sign in", false, nil},
|
"login": command{1, []string{"phone"}, "sign in", false, nil},
|
||||||
"logout": command{0, []string{}, "sign out", true, 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},
|
"cancelauth": command{0, []string{}, "quit the signin wizard", false, nil},
|
||||||
"code": command{1, []string{"xxxxx"}, "check one-time code", false, nil},
|
"code": command{1, []string{"xxxxx"}, "check one-time code", false, nil},
|
||||||
"password": command{1, []string{"********"}, "check 2fa password", 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...)
|
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) {
|
func (c *Client) sendMessagesReverse(chatID int64, messages []*client.Message) {
|
||||||
for i := len(messages) - 1; i >= 0; i-- {
|
for i := len(messages) - 1; i >= 0; i-- {
|
||||||
message := messages[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
|
return errors.Wrap(err, "Logout error").Error(), false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range c.cache.OwnChatsKeys() {
|
c.unsubscribeFromAll()
|
||||||
c.unsubscribe(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Session.Login = ""
|
c.Session.Login = ""
|
||||||
|
// cleanup
|
||||||
|
case "cleanup":
|
||||||
|
c.unsubscribeFromAll()
|
||||||
// cancel auth
|
// cancel auth
|
||||||
case "cancelauth":
|
case "cancelauth":
|
||||||
if c.Online() {
|
if c.Online() {
|
||||||
|
|
|
||||||
|
|
@ -153,11 +153,13 @@ func (c *Client) Connect(resource string) error {
|
||||||
c.addResource(resource)
|
c.addResource(resource)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
_, err = c.client.GetChats(&client.GetChatsRequest{
|
chats, err := c.client.GetChats(&client.GetChatsRequest{
|
||||||
Limit: chatsLimit,
|
Limit: chatsLimit,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Could not retrieve chats: %v", err)
|
log.Errorf("Could not retrieve chats: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Infof("Obtained ≈%v chats for initialization", chats.TotalCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
gateway.SubscribeToTransport(c.xmpp, c.jid)
|
gateway.SubscribeToTransport(c.xmpp, c.jid)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue