aboutsummaryrefslogtreecommitdiff
path: root/matrix/pushrules
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-09-05 10:55:48 +0300
committerTulir Asokan <tulir@maunium.net>2018-09-05 10:55:48 +0300
commitcfb2cc057c32330be0ca0a68cfbd245cb2b8e31b (patch)
treef0d02d40d41091fd052582fe1fe701c80decf0d7 /matrix/pushrules
parent68db26bcace31297471641fe95f8882e301f5699 (diff)
Update to latest gomatrix. Things are broken
Diffstat (limited to 'matrix/pushrules')
-rw-r--r--matrix/pushrules/condition.go19
-rw-r--r--matrix/pushrules/pushrules.go16
-rw-r--r--matrix/pushrules/rule.go3
3 files changed, 17 insertions, 21 deletions
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go
index 08958a3..22d59aa 100644
--- a/matrix/pushrules/condition.go
+++ b/matrix/pushrules/condition.go
@@ -23,14 +23,13 @@ import (
"maunium.net/go/gomatrix"
"maunium.net/go/gomuks/lib/glob"
- "maunium.net/go/gomuks/matrix/rooms"
)
// Room is an interface with the functions that are needed for processing room-specific push conditions
type Room interface {
- GetMember(mxid string) *rooms.Member
- GetMembers() map[string]*rooms.Member
- GetSessionOwner() *rooms.Member
+ GetMember(mxid string) *gomatrix.Member
+ GetMembers() map[string]*gomatrix.Member
+ GetSessionOwner() string
}
// PushCondKind is the type of a push condition.
@@ -89,7 +88,7 @@ func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
switch key {
case "type":
- return pattern.MatchString(event.Type)
+ return pattern.MatchString(event.Type.String())
case "sender":
return pattern.MatchString(event.Sender)
case "room_id":
@@ -100,7 +99,7 @@ func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
}
return pattern.MatchString(*event.StateKey)
case "content":
- val, _ := event.Content[subkey].(string)
+ val, _ := event.Content.Raw[subkey].(string)
return pattern.MatchString(val)
default:
return false
@@ -108,12 +107,12 @@ func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
}
func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bool {
- member := room.GetSessionOwner()
- if member == nil || member.UserID == event.Sender {
+ ownerID := room.GetSessionOwner()
+ if ownerID == event.Sender {
return false
}
- text, _ := event.Content["body"].(string)
- return strings.Contains(text, member.DisplayName)
+ member := room.GetMember(ownerID)
+ return strings.Contains(event.Content.Body, member.Displayname)
}
func (cond *PushCondition) matchMemberCount(room Room, event *gomatrix.Event) bool {
diff --git a/matrix/pushrules/pushrules.go b/matrix/pushrules/pushrules.go
index 876713b..b383c66 100644
--- a/matrix/pushrules/pushrules.go
+++ b/matrix/pushrules/pushrules.go
@@ -21,19 +21,17 @@ func GetScopedPushRules(client *gomatrix.Client, scope string) (resp *PushRulese
return
}
+type contentWithRuleset struct {
+ Ruleset *PushRuleset `json:"global"`
+}
+
// EventToPushRules converts a m.push_rules event to a PushRuleset by passing the data through JSON.
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)
+ content := &contentWithRuleset{}
+ err := json.Unmarshal(event.Content.VeryRaw, content)
if err != nil {
return nil, err
}
- return ruleset, nil
+ return content.Ruleset, nil
}
diff --git a/matrix/pushrules/rule.go b/matrix/pushrules/rule.go
index 5ede895..71f71e5 100644
--- a/matrix/pushrules/rule.go
+++ b/matrix/pushrules/rule.go
@@ -154,6 +154,5 @@ func (rule *PushRule) matchPattern(room Room, event *gomatrix.Event) bool {
if err != nil {
return false
}
- text, _ := event.Content["body"].(string)
- return pattern.MatchString(text)
+ return pattern.MatchString(event.Content.Body)
}