aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-01-03 06:54:13 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-01-03 06:54:13 +0300
commitf4e4692a94b24f661d67cd4e98ac9b2ca9928c0f (patch)
treeb9c917fc783b6bdd15fa2781b607b34b3cf51606 /telegram/utils.go
parent462a537021f471579877eceb1dd6c47154d8052d (diff)
Multiple resources handling
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go34
1 files changed, 34 insertions, 0 deletions
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)
+}