diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-06 00:04:22 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-01-06 00:04:22 +0300 |
commit | 077edae986f2229d263f978b7cf35ed88254c042 (patch) | |
tree | 01877034c1989565e2de30bce04d1c15eb06579e /telegram | |
parent | d48cb8b58682d3b9c5798913de35ae62dd20dd38 (diff) |
Add keeponline option
Diffstat (limited to 'telegram')
-rw-r--r-- | telegram/commands.go | 4 | ||||
-rw-r--r-- | telegram/connect.go | 4 | ||||
-rw-r--r-- | telegram/utils.go | 12 |
3 files changed, 12 insertions, 8 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index 4b0ee13..82dca91 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -53,7 +53,8 @@ var chatCommands = map[string]command{ } var transportConfigurationOptions = map[string]configurationOption{ - "timezone": configurationOption{"00:00", "adjust timezone for Telegram user statuses"}, + "timezone": configurationOption{"<timezone>", "adjust timezone for Telegram user statuses (example: +02:00)"}, + "keeponline": configurationOption{"<bool>", "always keep telegram session online and rely on jabber offline messages (example: true)"}, } type command struct { @@ -293,6 +294,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string if err != nil { return err.Error() } + gateway.DirtySessions = true return fmt.Sprintf("%s set to %s", args[0], value) } else if len(args) > 0 { diff --git a/telegram/connect.go b/telegram/connect.go index 8cee376..f2ea01d 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -91,7 +91,7 @@ func (c *Client) Connect(resource string) error { c.locks.authorizationReady.Wait() if c.Online() { - c.refresh(resource) + c.roster(resource) return nil } @@ -157,7 +157,7 @@ func (c *Client) Disconnect(resource string, quit bool) bool { c.deleteResource(resource) } // other resources are still active - if len(c.resources) > 0 && !quit { + if (len(c.resources) > 0 || c.Session.KeepOnline) && !quit { log.Infof("Resource %v for account %v has disconnected, %v remaining", resource, c.Session.Login, len(c.resources)) log.Debugf("Resources: %#v", c.resources) return false diff --git a/telegram/utils.go b/telegram/utils.go index cdd2914..4c73f9e 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -48,7 +48,7 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us // GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing) func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *client.User, error) { - if !c.Online() { + if !c.Online() || id == 0 { return nil, nil, errOffline } @@ -600,17 +600,19 @@ func (c *Client) deleteResource(resource string) { } } -// refresh roster -func (c *Client) refresh(resource string) { +// resend statuses to (to another resource, for example) +func (c *Client) roster(resource string) { if _, ok := c.resources[resource]; ok { - return + return // we know it } - log.Warnf("Refreshing roster for resource %v", resource) + log.Warnf("Sending roster for %v", resource) for _, chat := range c.cache.ChatsKeys() { c.ProcessStatusUpdate(chat, "", "") } + gateway.SendPresence(c.xmpp, c.jid, gateway.SPStatus("Logged in as: "+c.Session.Login)) + c.addResource(resource) } |