aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-28 22:08:18 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-28 22:08:18 +0100
commit708bd14e994765e818eb835da0bc0799e3e67ccd (patch)
treeed3f02e69510c1709de535b315990ac669ef183d
parent2444302510e2e26a71802d134c9440511900e06a (diff)
downloadeasybridge-708bd14e994765e818eb835da0bc0799e3e67ccd.tar.gz
easybridge-708bd14e994765e818eb835da0bc0799e3e67ccd.zip
Fixes
-rw-r--r--account.go2
-rw-r--r--server.go27
2 files changed, 18 insertions, 11 deletions
diff --git a/account.go b/account.go
index 311b7de..732ff77 100644
--- a/account.go
+++ b/account.go
@@ -159,7 +159,7 @@ func LoadDbAccounts(mxid string, key *[32]byte) {
err = SetAccount(mxid, acct.Name, acct.Protocol, config)
if err != nil {
- ezbrSystemSendf("Could not setup account %s: %s", acct.Name, err.Error())
+ ezbrSystemSendf(mxid, "Could not setup account %s: %s", acct.Name, err.Error())
}
}
}
diff --git a/server.go b/server.go
index f11615e..79654c5 100644
--- a/server.go
+++ b/server.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "os"
"strings"
"github.com/gorilla/mux"
@@ -23,22 +24,28 @@ func StartAppService(errch chan error) error {
return err
}
- err = mx.RegisterUser(registration.SenderLocalpart)
- if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" {
- return err
- }
- if err == nil {
- // If Easybridge account was created, update avatar and display name
- err = mx.ProfileAvatar(ezbrMxId(), &connector.FileMediaObject{
- Path: config.AvatarFile,
- })
- if err != nil {
+ if dbKvGet("ezbr_initialized") != "yes" {
+ err = mx.RegisterUser(registration.SenderLocalpart)
+ if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" {
return err
}
+
+ _, st := os.Stat(config.AvatarFile)
+ if !os.IsNotExist(st) {
+ err = mx.ProfileAvatar(ezbrMxId(), &connector.FileMediaObject{
+ Path: config.AvatarFile,
+ })
+ if err != nil {
+ return err
+ }
+ }
+
err = mx.ProfileDisplayname(ezbrMxId(), fmt.Sprintf("Easybridge (%s)", EASYBRIDGE_SYSTEM_PROTOCOL))
if err != nil {
return err
}
+
+ dbKvPut("ezbr_initialized", "yes")
}
router := mux.NewRouter()