aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go27
1 files changed, 17 insertions, 10 deletions
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()