aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-28 17:32:09 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-28 17:32:09 +0100
commit3880bd170144b913fe52a1ef1f3687551d797973 (patch)
treedec8ec5b734a0a04b4e47ffbe9807c529c5942cb
parent3bb8a78d073563c309195581780254b0e6f9dbe6 (diff)
downloadeasybridge-3880bd170144b913fe52a1ef1f3687551d797973.tar.gz
easybridge-3880bd170144b913fe52a1ef1f3687551d797973.zip
Add easybridge account config widget in system rooms
-rw-r--r--main.go1
-rw-r--r--util.go20
2 files changed, 20 insertions, 1 deletions
diff --git a/main.go b/main.go
index 80eede0..339f6c7 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,7 @@ type ConfigFile struct {
LogLevel string `json:"log_level"`
ASBindAddr string `json:"appservice_bind_addr"`
WebBindAddr string `json:"web_bind_addr"`
+ WebURL string `json:"web_url"`
Registration string `json:"registration"`
Server string `json:"homeserver_url"`
DbType string `json:"db_type"`
diff --git a/util.go b/util.go
index 323f99d..c8a62ef 100644
--- a/util.go
+++ b/util.go
@@ -20,7 +20,25 @@ func ezbrMxId() string {
}
func ezbrSystemRoom(user_mx_id string) (string, error) {
- return dbGetMxPmRoom(EASYBRIDGE_SYSTEM_PROTOCOL, UserID("Easybridge"), ezbrMxId(), user_mx_id, "easybridge")
+ mx_room_id, err := dbGetMxPmRoom(EASYBRIDGE_SYSTEM_PROTOCOL, UserID("Easybridge"), ezbrMxId(), user_mx_id, "easybridge")
+ if err != nil {
+ return "", err
+ }
+
+ widget_kv_key := "ezbr_widget_on:" + mx_room_id
+ if config.WebURL != "" && dbKvTestAndSet(widget_kv_key, "yes") {
+ widget := map[string]interface{}{
+ "type": "m.easybridge",
+ "url": config.WebURL,
+ "name": "Easybridge account configuration dashboard",
+ }
+ err = mx.PutStateAs(mx_room_id, "im.vector.modular.widgets", "ezbr_widget", widget, ezbrMxId())
+ if err != nil {
+ dbKvPut(widget_kv_key, "")
+ }
+ }
+
+ return mx_room_id, nil
}
func ezbrSystemSend(user_mx_id string, msg string) {