Make chats/users cache private
This commit is contained in:
parent
fa841bfa8b
commit
8cd6387552
|
@ -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: ¶meters,
|
||||
xmpp: component,
|
||||
jid: jid,
|
||||
Session: session,
|
||||
content: &conf.Content,
|
||||
parameters: ¶meters,
|
||||
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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue