diff options
Diffstat (limited to 'matrix/pushrules/condition.go')
-rw-r--r-- | matrix/pushrules/condition.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go index 08958a3..bacab56 100644 --- a/matrix/pushrules/condition.go +++ b/matrix/pushrules/condition.go @@ -21,16 +21,15 @@ import ( "strconv" "strings" - "maunium.net/go/gomatrix" + "maunium.net/go/mautrix" "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) *mautrix.Member + GetMembers() map[string]*mautrix.Member + GetSessionOwner() string } // PushCondKind is the type of a push condition. @@ -60,7 +59,7 @@ type PushCondition struct { var MemberCountFilterRegex = regexp.MustCompile("^(==|[<>]=?)?([0-9]+)$") // Match checks if this condition is fulfilled for the given event in the given room. -func (cond *PushCondition) Match(room Room, event *gomatrix.Event) bool { +func (cond *PushCondition) Match(room Room, event *mautrix.Event) bool { switch cond.Kind { case KindEventMatch: return cond.matchValue(room, event) @@ -73,7 +72,7 @@ func (cond *PushCondition) Match(room Room, event *gomatrix.Event) bool { } } -func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool { +func (cond *PushCondition) matchValue(room Room, event *mautrix.Event) bool { index := strings.IndexRune(cond.Key, '.') key := cond.Key subkey := "" @@ -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,23 +99,23 @@ 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 } } -func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bool { - member := room.GetSessionOwner() - if member == nil || member.UserID == event.Sender { +func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) bool { + 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 { +func (cond *PushCondition) matchMemberCount(room Room, event *mautrix.Event) bool { group := MemberCountFilterRegex.FindStringSubmatch(cond.MemberCountCondition) if len(group) != 3 { return false |