Clear push rules when clearing cache and listen to push rule updates
This commit is contained in:
parent
efbce4c363
commit
b4902d4edb
@ -52,6 +52,7 @@ func (config *Config) NewSession(mxid string) *Session {
|
|||||||
|
|
||||||
func (s *Session) Clear() {
|
func (s *Session) Clear() {
|
||||||
s.Rooms = make(map[string]*rooms.Room)
|
s.Rooms = make(map[string]*rooms.Room)
|
||||||
|
s.PushRules = nil
|
||||||
s.NextBatch = ""
|
s.NextBatch = ""
|
||||||
s.FilterID = ""
|
s.FilterID = ""
|
||||||
s.Save()
|
s.Save()
|
||||||
|
@ -26,6 +26,22 @@ func GetScopedPushRules(client *gomatrix.Client, scope string) (resp *PushRulese
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EventToPushRules(event *gomatrix.Event) (*PushRuleset, error) {
|
||||||
|
content, _ := event.Content["global"]
|
||||||
|
raw, err := json.Marshal(content)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleset := &PushRuleset{}
|
||||||
|
err = json.Unmarshal(raw, ruleset)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ruleset, nil
|
||||||
|
}
|
||||||
|
|
||||||
type PushRuleset struct {
|
type PushRuleset struct {
|
||||||
Override PushRuleArray
|
Override PushRuleArray
|
||||||
Content PushRuleArray
|
Content PushRuleArray
|
||||||
|
@ -121,6 +121,7 @@ func (c *Container) Client() *gomatrix.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) UpdatePushRules() {
|
func (c *Container) UpdatePushRules() {
|
||||||
|
debug.Print("Updating push rules...")
|
||||||
resp, err := gomx_ext.GetPushRules(c.client)
|
resp, err := gomx_ext.GetPushRules(c.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Print("Failed to fetch push rules:", err)
|
debug.Print("Failed to fetch push rules:", err)
|
||||||
@ -162,10 +163,10 @@ func (c *Container) OnLogin() {
|
|||||||
syncer.OnEventType("m.room.message", c.HandleMessage)
|
syncer.OnEventType("m.room.message", c.HandleMessage)
|
||||||
syncer.OnEventType("m.room.member", c.HandleMembership)
|
syncer.OnEventType("m.room.member", c.HandleMembership)
|
||||||
syncer.OnEventType("m.typing", c.HandleTyping)
|
syncer.OnEventType("m.typing", c.HandleTyping)
|
||||||
|
syncer.OnEventType("m.push_rules", c.HandlePushRules)
|
||||||
c.client.Syncer = syncer
|
c.client.Syncer = syncer
|
||||||
|
|
||||||
c.UpdateRoomList()
|
c.UpdateRoomList()
|
||||||
c.UpdatePushRules()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) Start() {
|
func (c *Container) Start() {
|
||||||
@ -221,6 +222,15 @@ func (c *Container) HandleMessage(evt *gomatrix.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) HandlePushRules(evt *gomatrix.Event) {
|
||||||
|
debug.Print("Received updated push rules")
|
||||||
|
var err error
|
||||||
|
c.config.Session.PushRules, err = gomx_ext.EventToPushRules(evt)
|
||||||
|
if err != nil {
|
||||||
|
debug.Print("Failed to convert event to push rules:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Container) HandleMembership(evt *gomatrix.Event) {
|
func (c *Container) HandleMembership(evt *gomatrix.Event) {
|
||||||
const Hour = 1 * 60 * 60 * 1000
|
const Hour = 1 * 60 * 60 * 1000
|
||||||
if evt.Unsigned.Age > Hour {
|
if evt.Unsigned.Age > Hour {
|
||||||
|
@ -41,6 +41,9 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
|
|||||||
for _, event := range res.Presence.Events {
|
for _, event := range res.Presence.Events {
|
||||||
s.notifyListeners(event)
|
s.notifyListeners(event)
|
||||||
}
|
}
|
||||||
|
for _, event := range res.AccountData.Events {
|
||||||
|
s.notifyListeners(event)
|
||||||
|
}
|
||||||
for roomID, roomData := range res.Rooms.Join {
|
for roomID, roomData := range res.Rooms.Join {
|
||||||
room := s.Session.GetRoom(roomID)
|
room := s.Session.GetRoom(roomID)
|
||||||
for _, event := range roomData.State.Events {
|
for _, event := range roomData.State.Events {
|
||||||
|
Loading…
Reference in New Issue
Block a user