Fix things
This commit is contained in:
@ -21,14 +21,14 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/gomuks/lib/glob"
|
||||
)
|
||||
|
||||
// Room is an interface with the functions that are needed for processing room-specific push conditions
|
||||
type Room interface {
|
||||
GetMember(mxid string) *gomatrix.Member
|
||||
GetMembers() map[string]*gomatrix.Member
|
||||
GetMember(mxid string) *mautrix.Member
|
||||
GetMembers() map[string]*mautrix.Member
|
||||
GetSessionOwner() string
|
||||
}
|
||||
|
||||
@ -59,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)
|
||||
@ -72,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 := ""
|
||||
@ -106,7 +106,7 @@ func (cond *PushCondition) matchValue(room Room, event *gomatrix.Event) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bool {
|
||||
func (cond *PushCondition) matchDisplayName(room Room, event *mautrix.Event) bool {
|
||||
ownerID := room.GetSessionOwner()
|
||||
if ownerID == event.Sender {
|
||||
return false
|
||||
@ -115,7 +115,7 @@ func (cond *PushCondition) matchDisplayName(room Room, event *gomatrix.Event) bo
|
||||
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
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/gomuks/matrix/pushrules"
|
||||
"maunium.net/go/gomuks/matrix/rooms"
|
||||
)
|
||||
@ -30,7 +30,7 @@ var (
|
||||
blankTestRoom *rooms.Room
|
||||
displaynameTestRoom pushrules.Room
|
||||
|
||||
countConditionTestEvent *gomatrix.Event
|
||||
countConditionTestEvent *mautrix.Event
|
||||
|
||||
displaynamePushCondition *pushrules.PushCondition
|
||||
)
|
||||
@ -38,7 +38,7 @@ var (
|
||||
func init() {
|
||||
blankTestRoom = rooms.NewRoom("!fakeroom:maunium.net", "@tulir:maunium.net")
|
||||
|
||||
countConditionTestEvent = &gomatrix.Event{
|
||||
countConditionTestEvent = &mautrix.Event{
|
||||
Sender: "@tulir:maunium.net",
|
||||
Type: "m.room.message",
|
||||
Timestamp: 1523791120,
|
||||
@ -56,8 +56,8 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func newFakeEvent(evtType string, content map[string]interface{}) *gomatrix.Event {
|
||||
return &gomatrix.Event{
|
||||
func newFakeEvent(evtType string, content map[string]interface{}) *mautrix.Event {
|
||||
return &mautrix.Event{
|
||||
Sender: "@tulir:maunium.net",
|
||||
Type: evtType,
|
||||
Timestamp: 1523791120,
|
||||
|
@ -4,16 +4,16 @@ import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
)
|
||||
|
||||
// GetPushRules returns the push notification rules for the global scope.
|
||||
func GetPushRules(client *gomatrix.Client) (*PushRuleset, error) {
|
||||
func GetPushRules(client *mautrix.Client) (*PushRuleset, error) {
|
||||
return GetScopedPushRules(client, "global")
|
||||
}
|
||||
|
||||
// GetScopedPushRules returns the push notification rules for the given scope.
|
||||
func GetScopedPushRules(client *gomatrix.Client, scope string) (resp *PushRuleset, err error) {
|
||||
func GetScopedPushRules(client *mautrix.Client, scope string) (resp *PushRuleset, err error) {
|
||||
u, _ := url.Parse(client.BuildURL("pushrules", scope))
|
||||
// client.BuildURL returns the URL without a trailing slash, but the pushrules endpoint requires the slash.
|
||||
u.Path += "/"
|
||||
@ -26,7 +26,7 @@ type contentWithRuleset struct {
|
||||
}
|
||||
|
||||
// EventToPushRules converts a m.push_rules event to a PushRuleset by passing the data through JSON.
|
||||
func EventToPushRules(event *gomatrix.Event) (*PushRuleset, error) {
|
||||
func EventToPushRules(event *mautrix.Event) (*PushRuleset, error) {
|
||||
content := &contentWithRuleset{}
|
||||
err := json.Unmarshal(event.Content.VeryRaw, content)
|
||||
if err != nil {
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/gomuks/matrix/pushrules"
|
||||
)
|
||||
|
||||
@ -33,7 +33,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestEventToPushRules(t *testing.T) {
|
||||
event := &gomatrix.Event{
|
||||
event := &mautrix.Event{
|
||||
Type: "m.push_rules",
|
||||
Timestamp: 1523380910,
|
||||
Content: mapExamplePushRules,
|
||||
|
@ -18,7 +18,7 @@ package pushrules
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/gomuks/lib/glob"
|
||||
)
|
||||
|
||||
@ -28,7 +28,7 @@ func init() {
|
||||
}
|
||||
|
||||
type PushRuleCollection interface {
|
||||
GetActions(room Room, event *gomatrix.Event) PushActionArray
|
||||
GetActions(room Room, event *mautrix.Event) PushActionArray
|
||||
}
|
||||
|
||||
type PushRuleArray []*PushRule
|
||||
@ -40,7 +40,7 @@ func (rules PushRuleArray) SetType(typ PushRuleType) PushRuleArray {
|
||||
return rules
|
||||
}
|
||||
|
||||
func (rules PushRuleArray) GetActions(room Room, event *gomatrix.Event) PushActionArray {
|
||||
func (rules PushRuleArray) GetActions(room Room, event *mautrix.Event) PushActionArray {
|
||||
for _, rule := range rules {
|
||||
if !rule.Match(room, event) {
|
||||
continue
|
||||
@ -67,7 +67,7 @@ func (rules PushRuleArray) SetTypeAndMap(typ PushRuleType) PushRuleMap {
|
||||
return data
|
||||
}
|
||||
|
||||
func (ruleMap PushRuleMap) GetActions(room Room, event *gomatrix.Event) PushActionArray {
|
||||
func (ruleMap PushRuleMap) GetActions(room Room, event *mautrix.Event) PushActionArray {
|
||||
var rule *PushRule
|
||||
var found bool
|
||||
switch ruleMap.Type {
|
||||
@ -122,7 +122,7 @@ type PushRule struct {
|
||||
Pattern string `json:"pattern,omitempty"`
|
||||
}
|
||||
|
||||
func (rule *PushRule) Match(room Room, event *gomatrix.Event) bool {
|
||||
func (rule *PushRule) Match(room Room, event *mautrix.Event) bool {
|
||||
if !rule.Enabled {
|
||||
return false
|
||||
}
|
||||
@ -140,7 +140,7 @@ func (rule *PushRule) Match(room Room, event *gomatrix.Event) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (rule *PushRule) matchConditions(room Room, event *gomatrix.Event) bool {
|
||||
func (rule *PushRule) matchConditions(room Room, event *mautrix.Event) bool {
|
||||
for _, cond := range rule.Conditions {
|
||||
if !cond.Match(room, event) {
|
||||
return false
|
||||
@ -149,7 +149,7 @@ func (rule *PushRule) matchConditions(room Room, event *gomatrix.Event) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (rule *PushRule) matchPattern(room Room, event *gomatrix.Event) bool {
|
||||
func (rule *PushRule) matchPattern(room Room, event *mautrix.Event) bool {
|
||||
pattern, err := glob.Compile(rule.Pattern)
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -19,7 +19,7 @@ package pushrules
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix"
|
||||
)
|
||||
|
||||
type PushRuleset struct {
|
||||
@ -80,7 +80,7 @@ var DefaultPushActions = make(PushActionArray, 0)
|
||||
// GetActions matches the given event against all of the push rule
|
||||
// collections in this push ruleset in the order of priority as
|
||||
// specified in spec section 11.12.1.4.
|
||||
func (rs *PushRuleset) GetActions(room Room, event *gomatrix.Event) (match PushActionArray) {
|
||||
func (rs *PushRuleset) GetActions(room Room, event *mautrix.Event) (match PushActionArray) {
|
||||
// Add push rule collections to array in priority order
|
||||
arrays := []PushRuleCollection{rs.Override, rs.Content, rs.Room, rs.Sender, rs.Underride}
|
||||
// Loop until one of the push rule collections matches the room/event combo.
|
||||
|
Reference in New Issue
Block a user