aboutsummaryrefslogtreecommitdiff
path: root/matrix/pushrules
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-16 21:25:41 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-16 21:25:41 +0300
commit754f8e493df64d6532ace194f3e75c9ccf5bfd95 (patch)
tree041ed5482c2f2b4c1a39645593aa7c71fae1a70d /matrix/pushrules
parentc6ca343cd1b198c6a15f8d3045bc7e83b1a36cf3 (diff)
Only ping if displayname has spaces/punctuation characters around it. Fixes #96
Diffstat (limited to 'matrix/pushrules')
-rw-r--r--matrix/pushrules/condition.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go
index 12fd3f3..0b7776a 100644
--- a/matrix/pushrules/condition.go
+++ b/matrix/pushrules/condition.go
@@ -20,6 +20,7 @@ import (
"regexp"
"strconv"
"strings"
+ "unicode"
"maunium.net/go/mautrix"
@@ -116,7 +117,19 @@ func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) boo
if member == nil {
return false
}
- return strings.Contains(event.Content.Body, member.Displayname)
+
+ msg := event.Content.Body
+ isAcceptable := func(r uint8) bool {
+ return unicode.IsSpace(rune(r)) || unicode.IsPunct(rune(r))
+ }
+ length := len(member.Displayname)
+ for index := strings.Index(msg, member.Displayname); index != -1; index = strings.Index(msg, member.Displayname) {
+ if (index <= 0 || isAcceptable(msg[index-1])) && (index + length >= len(msg) || isAcceptable(msg[index+length])) {
+ return true
+ }
+ msg = msg[index+len(member.Displayname):]
+ }
+ return false
}
func (cond *PushCondition) matchMemberCount(room Room, event *mautrix.Event) bool {