diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-28 05:35:40 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-28 05:35:40 +0300 |
commit | 536451f648bce43aa34e90a9154adf831027dae7 (patch) | |
tree | 36c66093319e3972f97a141c68e332e25d468331 /telegram/client.go | |
parent | fdc8397b93ed355cb931646f0c4eda496ce0e858 (diff) |
Make the chats/users cache thread-safe
Diffstat (limited to 'telegram/client.go')
-rw-r--r-- | telegram/client.go | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/telegram/client.go b/telegram/client.go index 2acd75e..dde15f2 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -9,6 +9,7 @@ import ( "dev.narayana.im/narayana/telegabber/config" "dev.narayana.im/narayana/telegabber/persistence" + "dev.narayana.im/narayana/telegabber/telegram/cache" "github.com/zelenin/go-tdlib/client" "gosrc.io/xmpp" @@ -24,11 +25,6 @@ var logConstants = map[string]int32{ ":all": 1023, } -type cache struct { - chats map[int64]*client.Chat - users map[int32]*client.User -} - func stringToLogConstant(c string) int32 { level, ok := logConstants[c] if !ok { @@ -51,7 +47,7 @@ type Client struct { jid string Session *persistence.Session content *config.TelegramContentConfig - cache *cache + cache *cache.Cache online bool locks clientLocks @@ -109,11 +105,8 @@ func NewClient(conf config.TelegramConfig, jid string, component *xmpp.Component jid: jid, Session: session, content: &conf.Content, - cache: &cache{ - chats: map[int64]*client.Chat{}, - users: map[int32]*client.User{}, - }, - options: options, - locks: clientLocks{}, + cache: cache.NewCache(), + options: options, + locks: clientLocks{}, }, nil } |