aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/server.go b/server.go
index f3eb898..e914f3b 100644
--- a/server.go
+++ b/server.go
@@ -15,17 +15,17 @@ import (
var mx *mxlib.Client
-func StartAppService() (chan error, error) {
+func StartAppService(errch chan error) error {
mx = mxlib.NewClient(config.Server, registration.AsToken)
err := InitDb()
if err != nil {
- return nil, err
+ return err
}
err = mx.RegisterUser(registration.SenderLocalpart)
if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" {
- return nil, err
+ return err
}
if err == nil {
// If Easybridge account was created, update avatar and display name
@@ -33,11 +33,11 @@ func StartAppService() (chan error, error) {
Path: "easybridge.jpg",
})
if err != nil {
- return nil, err
+ return err
}
err = mx.ProfileDisplayname(ezbrMxId(), fmt.Sprintf("Easybridge (%s)", EASYBRIDGE_SYSTEM_PROTOCOL))
if err != nil {
- return nil, err
+ return err
}
}
@@ -45,7 +45,6 @@ func StartAppService() (chan error, error) {
router.HandleFunc("/_matrix/app/v1/transactions/{txnId}", handleTxn)
router.HandleFunc("/transactions/{txnId}", handleTxn)
- errch := make(chan error)
go func() {
log.Printf("Starting HTTP server on %s", config.ASBindAddr)
err := http.ListenAndServe(config.ASBindAddr, checkTokenAndLog(router))
@@ -54,7 +53,18 @@ func StartAppService() (chan error, error) {
}
}()
- return errch, nil
+ // Notify users that Easybridge has restarted
+ go func() {
+ var users []DbAccountConfig
+ db.Model(&DbAccountConfig{}).Select("mx_user_id").Group("mx_user_id").Find(&users)
+ for _, u := range users {
+ ezbrSystemSendf(u.MxUserID,
+ "Easybridge has restarted, please visit %s or open configuration widget to reconnect to your accounts.",
+ config.WebURL)
+ }
+ }()
+
+ return nil
}
func checkTokenAndLog(handler http.Handler) http.Handler {