Add UI preferences and simplify config save/load (ref #43)
This commit is contained in:
@ -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 {
|
||||
|
@ -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{},
|
||||
|
Reference in New Issue
Block a user