From ba387764ca1590625d349e74eb8a8a64d1849b67 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 14 Nov 2018 00:00:35 +0200 Subject: Fix things --- matrix/pushrules/condition.go | 14 +++++++------- matrix/pushrules/condition_test.go | 10 +++++----- matrix/pushrules/pushrules.go | 8 ++++---- matrix/pushrules/pushrules_test.go | 4 ++-- matrix/pushrules/rule.go | 14 +++++++------- matrix/pushrules/ruleset.go | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) (limited to 'matrix/pushrules') diff --git a/matrix/pushrules/condition.go b/matrix/pushrules/condition.go index 22d59aa..bacab56 100644 --- a/matrix/pushrules/condition.go +++ b/matrix/pushrules/condition.go @@ -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 diff --git a/matrix/pushrules/condition_test.go b/matrix/pushrules/condition_test.go index 7fd06ee..750f2c7 100644 --- a/matrix/pushrules/condition_test.go +++ b/matrix/pushrules/condition_test.go @@ -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, diff --git a/matrix/pushrules/pushrules.go b/matrix/pushrules/pushrules.go index b383c66..643f2f2 100644 --- a/matrix/pushrules/pushrules.go +++ b/matrix/pushrules/pushrules.go @@ -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 { diff --git a/matrix/pushrules/pushrules_test.go b/matrix/pushrules/pushrules_test.go index 09698ac..73fa787 100644 --- a/matrix/pushrules/pushrules_test.go +++ b/matrix/pushrules/pushrules_test.go @@ -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, diff --git a/matrix/pushrules/rule.go b/matrix/pushrules/rule.go index 71f71e5..62318ac 100644 --- a/matrix/pushrules/rule.go +++ b/matrix/pushrules/rule.go @@ -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 diff --git a/matrix/pushrules/ruleset.go b/matrix/pushrules/ruleset.go index 940025f..366702e 100644 --- a/matrix/pushrules/ruleset.go +++ b/matrix/pushrules/ruleset.go @@ -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. -- cgit v1.2.3