storage: user set/get methods for contact method access

Get/GetKey/SetKey/DeleteKey methods are used for access to
email/discord/telegram/matrix, everywhere. Mutex added for each, avoids
concurrent read/write issues. Will also make potential transition to
database easier.
This commit is contained in:
Harvey Tindall
2023-06-20 12:19:24 +01:00
parent fcedea110d
commit 68004e1d34
15 changed files with 397 additions and 301 deletions
+3 -3
View File
@@ -46,7 +46,7 @@ func newTelegramDaemon(app *appContext) (*TelegramDaemon, error) {
link: "https://t.me/" + bot.Self.UserName,
app: app,
}
for _, user := range app.storage.telegram {
for _, user := range app.storage.GetTelegram() {
if user.Lang != "" {
td.languages[user.ChatID] = user.Lang
}
@@ -198,10 +198,10 @@ func (t *TelegramDaemon) commandLang(upd *tg.Update, sects []string, lang string
}
if _, ok := t.app.storage.lang.Telegram[sects[1]]; ok {
t.languages[upd.Message.Chat.ID] = sects[1]
for jfID, user := range t.app.storage.telegram {
for jfID, user := range t.app.storage.GetTelegram() {
if user.ChatID == upd.Message.Chat.ID {
user.Lang = sects[1]
t.app.storage.telegram[jfID] = user
t.app.storage.SetTelegramKey(jfID, user)
if err := t.app.storage.storeTelegramUsers(); err != nil {
t.app.err.Printf("Failed to store Telegram users: %v", err)
}