From f4e4692a94b24f661d67cd4e98ac9b2ca9928c0f Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sun, 2 Jan 2022 22:54:13 -0500 Subject: Multiple resources handling --- telegram/utils.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'telegram/utils.go') diff --git a/telegram/utils.go b/telegram/utils.go index 865c4d4..641f6d6 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -580,3 +580,37 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int func (c *Client) StatusesRange() chan *cache.Status { return c.cache.StatusesRange() } + +func (c *Client) addResource(resource string) { + if resource == "" { + return + } + c.locks.resourcesLock.Lock() + defer c.locks.resourcesLock.Unlock() + + c.resources[resource] = true +} + +func (c *Client) deleteResource(resource string) { + c.locks.resourcesLock.Lock() + defer c.locks.resourcesLock.Unlock() + + if _, ok := c.resources[resource]; ok { + delete(c.resources, resource) + } +} + +// refresh roster +func (c *Client) refresh(resource string) { + if _, ok := c.resources[resource]; ok { + return + } + + log.Warnf("Refreshing roster for resource %v", resource) + + for _, chat := range c.cache.ChatsKeys() { + c.ProcessStatusUpdate(chat, "", "") + } + + c.addResource(resource) +} -- cgit v1.2.3