aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-05 00:47:44 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-05 00:47:44 +0300
commit8cd6387552dc9b73c60950e8c1a47c84ae13f98b (patch)
treeb3ea81add8cbac8fee2a5153f792cdf217a65d10 /telegram
parentfa841bfa8bc0941e0416608e78308401c9334ae9 (diff)
Make chats/users cache private
Diffstat (limited to 'telegram')
-rw-r--r--telegram/client.go22
-rw-r--r--telegram/handlers.go4
-rw-r--r--telegram/utils.go10
3 files changed, 18 insertions, 18 deletions
diff --git a/telegram/client.go b/telegram/client.go
index a7fe332..f15d07d 100644
--- a/telegram/client.go
+++ b/telegram/client.go
@@ -23,16 +23,11 @@ var logConstants = map[string]int32{
":all": 1023,
}
-type cacheStruct struct {
+type cache struct {
chats map[int64]*client.Chat
users map[int32]*client.User
}
-var cache = cacheStruct{
- chats: map[int64]*client.Chat{},
- users: map[int32]*client.User{},
-}
-
func stringToLogConstant(c string) int32 {
level, ok := logConstants[c]
if !ok {
@@ -54,6 +49,7 @@ type Client struct {
jid string
Session *persistence.Session
content *config.TelegramContentConfig
+ cache *cache
locks clientLocks
online bool
@@ -98,11 +94,15 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component
}
return &Client{
- parameters: &parameters,
- xmpp: component,
- jid: jid,
- Session: session,
- content: &conf.Content,
+ parameters: &parameters,
+ xmpp: component,
+ jid: jid,
+ Session: session,
+ content: &conf.Content,
+ cache: &cache{
+ chats: map[int64]*client.Chat{},
+ users: map[int32]*client.User{},
+ },
logVerbosity: logVerbosity,
locks: clientLocks{},
}, nil
diff --git a/telegram/handlers.go b/telegram/handlers.go
index f0faa18..0cc3fad 100644
--- a/telegram/handlers.go
+++ b/telegram/handlers.go
@@ -102,7 +102,7 @@ func (c *Client) updateHandler() {
// new user discovered
func (c *Client) updateUser(update *client.UpdateUser) {
- cache.users[update.User.Id] = update.User
+ c.cache.users[update.User.Id] = update.User
show, status := userStatusToText(update.User.Status)
c.processStatusUpdate(int64(update.User.Id), status, show)
}
@@ -127,7 +127,7 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
}
}
- cache.chats[update.Chat.Id] = update.Chat
+ c.cache.chats[update.Chat.Id] = update.Chat
var isChannel = false
if update.Chat.Type.ChatTypeType() == client.TypeChatTypeSupergroup {
diff --git a/telegram/utils.go b/telegram/utils.go
index 13c81d5..a708c28 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -58,7 +58,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
if id <= math.MaxInt32 && id >= math.MinInt32 {
userID := int32(id)
- user, ok = cache.users[userID]
+ user, ok = c.cache.users[userID]
if !ok && userID > 0 {
user, err = c.client.GetUser(&client.GetUserRequest{
UserId: userID,
@@ -67,11 +67,11 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
return nil, nil, err
}
- cache.users[userID] = user
+ c.cache.users[userID] = user
}
}
- cacheChat, ok = cache.chats[id]
+ cacheChat, ok = c.cache.chats[id]
if !ok {
if chat == nil {
cacheChat, err = c.client.GetChat(&client.GetChatRequest{
@@ -81,9 +81,9 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
return nil, nil, err
}
- cache.chats[id] = cacheChat
+ c.cache.chats[id] = cacheChat
} else {
- cache.chats[id] = chat
+ c.cache.chats[id] = chat
}
}
if chat == nil {