aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-24 23:26:57 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-24 23:27:12 +0300
commitb76c8d01478bcdeb8e0f0c00ca56f577a425674b (patch)
treea3e9761a05c556730846c5645f8d9afc7c6e052b /matrix
parenta4d07e9a81f3bf0018b4f1368d8b4d06992cadba (diff)
Add UI preferences and simplify config save/load (ref #43)
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go20
-rw-r--r--matrix/sync.go2
2 files changed, 21 insertions, 1 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index b11b9ed..556df4e 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -39,6 +39,7 @@ import (
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
"crypto/tls"
+ "encoding/json"
)
// Container is a wrapper for a gomatrix Client and some other stuff.
@@ -188,6 +189,7 @@ func (c *Container) OnLogin() {
c.syncer.OnEventType("m.direct", c.HandleDirectChatInfo)
c.syncer.OnEventType("m.push_rules", c.HandlePushRules)
c.syncer.OnEventType("m.tag", c.HandleTag)
+ c.syncer.OnEventType("net.maunium.gomuks.preferences", c.HandlePreferences)
c.syncer.InitDoneCallback = func() {
c.config.AuthCache.InitialSyncDone = true
c.config.SaveAuthCache()
@@ -235,6 +237,24 @@ func (c *Container) Start() {
}
}
+func (c *Container) HandlePreferences(source EventSource, evt *gomatrix.Event) {
+ orig := c.config.Preferences
+ rt, _ := json.Marshal(&evt.Content)
+ json.Unmarshal(rt, &c.config.Preferences)
+ debug.Print("Updated preferences:", orig, "->", c.config.Preferences)
+ c.ui.HandleNewPreferences()
+}
+
+func (c *Container) SendPreferencesToMatrix() {
+ defer debug.Recover()
+ debug.Print("Sending updated preferences:", c.config.Preferences)
+ u := c.client.BuildURL("user", c.config.UserID, "account_data", "net.maunium.gomuks.preferences")
+ _, err := c.client.MakeRequest("PUT", u, &c.config.Preferences, nil)
+ if err != nil {
+ debug.Print("Failed to update preferences:", err)
+ }
+}
+
// HandleMessage is the event handler for the m.room.message timeline event.
func (c *Container) HandleMessage(source EventSource, evt *gomatrix.Event) {
if source&EventSourceLeave != 0 {
diff --git a/matrix/sync.go b/matrix/sync.go
index 3f6860a..2037fcd 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -184,7 +184,7 @@ func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
},
},
AccountData: gomatrix.FilterPart{
- Types: []string{"m.push_rules", "m.direct"},
+ Types: []string{"m.push_rules", "m.direct", "net.maunium.gomuks.preferences"},
},
Presence: gomatrix.FilterPart{
Types: []string{},