aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'account.go')
-rw-r--r--account.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/account.go b/account.go
index 6785fb7..0d7f94c 100644
--- a/account.go
+++ b/account.go
@@ -34,6 +34,9 @@ func SetAccount(mxid string, name string, protocol string, config map[string]str
accounts := registeredAccounts[mxid]
if prev_acct, ok := accounts[name]; ok {
+ prev_acct.Conn.Close()
+ prev_acct.JoinedRooms = map[RoomID]bool{}
+
if protocol != prev_acct.Protocol {
return fmt.Errorf("Wrong protocol")
}
@@ -112,6 +115,8 @@ func RemoveAccount(mxUser string, name string) {
}
}
+// ----
+
func SaveDbAccounts(mxid string, key *[32]byte) {
accountsLock.Lock()
defer accountsLock.Unlock()
@@ -130,6 +135,23 @@ func SaveDbAccounts(mxid string, key *[32]byte) {
}
}
+func LoadDbAccounts(mxid string, key *[32]byte) {
+ var allAccounts []DbAccountConfig
+ db.Where(&DbAccountConfig{MxUserID: mxid}).Find(&allAccounts)
+ for _, acct := range allAccounts {
+ config, err := decryptAccountConfig(acct.Config, key)
+ if err != nil {
+ ezbrSystemSendf("Could not decrypt stored configuration for account %s", acct.Name)
+ continue
+ }
+
+ err = SetAccount(mxid, acct.Name, acct.Protocol, config)
+ if err != nil {
+ ezbrSystemSendf("Could not setup account %s: %s", acct.Name, err.Error())
+ }
+ }
+}
+
// ----
func (a *Account) ezbrMessagef(format string, args ...interface{}) {