BREAKING: update mautrix to 0.15.x

This commit is contained in:
Aine
2023-06-01 14:32:20 +00:00
parent a6b20a75ab
commit 2bdb8ca635
222 changed files with 7851 additions and 23986 deletions

View File

@@ -33,14 +33,15 @@ type PushActionArray []*PushAction
// PushActionArrayShould contains the important information parsed from a PushActionArray.
type PushActionArrayShould struct {
// Whether or not the array contained a Notify, DontNotify or Coalesce action type.
// Whether the array contained a Notify, DontNotify or Coalesce action type.
// Deprecated: an empty array should be treated as no notification, so there's no reason to check this field.
NotifySpecified bool
// Whether or not the event in question should trigger a notification.
// Whether the event in question should trigger a notification.
Notify bool
// Whether or not the event in question should be highlighted.
// Whether the event in question should be highlighted.
Highlight bool
// Whether or not the event in question should trigger a sound alert.
// Whether the event in question should trigger a sound alert.
PlaySound bool
// The name of the sound to play if PlaySound is true.
SoundName string

View File

@@ -20,6 +20,7 @@ func init() {
}
type PushRuleCollection interface {
GetMatchingRule(room Room, evt *event.Event) *PushRule
GetActions(room Room, evt *event.Event) PushActionArray
}
@@ -32,16 +33,20 @@ func (rules PushRuleArray) SetType(typ PushRuleType) PushRuleArray {
return rules
}
func (rules PushRuleArray) GetActions(room Room, evt *event.Event) PushActionArray {
func (rules PushRuleArray) GetMatchingRule(room Room, evt *event.Event) *PushRule {
for _, rule := range rules {
if !rule.Match(room, evt) {
continue
}
return rule.Actions
return rule
}
return nil
}
func (rules PushRuleArray) GetActions(room Room, evt *event.Event) PushActionArray {
return rules.GetMatchingRule(room, evt).GetActions()
}
type PushRuleMap struct {
Map map[string]*PushRule
Type PushRuleType
@@ -59,7 +64,7 @@ func (rules PushRuleArray) SetTypeAndMap(typ PushRuleType) PushRuleMap {
return data
}
func (ruleMap PushRuleMap) GetActions(room Room, evt *event.Event) PushActionArray {
func (ruleMap PushRuleMap) GetMatchingRule(room Room, evt *event.Event) *PushRule {
var rule *PushRule
var found bool
switch ruleMap.Type {
@@ -69,11 +74,15 @@ func (ruleMap PushRuleMap) GetActions(room Room, evt *event.Event) PushActionArr
rule, found = ruleMap.Map[string(evt.Sender)]
}
if found && rule.Match(room, evt) {
return rule.Actions
return rule
}
return nil
}
func (ruleMap PushRuleMap) GetActions(room Room, evt *event.Event) PushActionArray {
return ruleMap.GetMatchingRule(room, evt).GetActions()
}
func (ruleMap PushRuleMap) Unmap() PushRuleArray {
array := make(PushRuleArray, len(ruleMap.Map))
index := 0
@@ -114,8 +123,15 @@ type PushRule struct {
Pattern string `json:"pattern,omitempty"`
}
func (rule *PushRule) GetActions() PushActionArray {
if rule == nil {
return nil
}
return rule.Actions
}
func (rule *PushRule) Match(room Room, evt *event.Event) bool {
if !rule.Enabled {
if rule == nil || !rule.Enabled {
return false
}
switch rule.Type {

View File

@@ -67,10 +67,7 @@ func (rs *PushRuleset) MarshalJSON() ([]byte, error) {
// collections in a Ruleset match the event given to GetActions()
var DefaultPushActions = PushActionArray{&PushAction{Action: ActionDontNotify}}
// 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, evt *event.Event) (match PushActionArray) {
func (rs *PushRuleset) GetMatchingRule(room Room, evt *event.Event) (rule *PushRule) {
// 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.
@@ -78,11 +75,23 @@ func (rs *PushRuleset) GetActions(room Room, evt *event.Event) (match PushAction
if pra == nil {
continue
}
if match = pra.GetActions(room, evt); match != nil {
if rule = pra.GetMatchingRule(room, evt); rule != nil {
// Match found, return it.
return
}
}
// No match found, return default actions.
return DefaultPushActions
// No match found
return nil
}
// 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, evt *event.Event) (match PushActionArray) {
actions := rs.GetMatchingRule(room, evt).GetActions()
if actions == nil {
// No match found, return default actions.
return DefaultPushActions
}
return actions
}