Documentation
¶
Overview ¶
Package pushrules contains utilities to parse push notification rules.
Index ¶
- Variables
- type EventContent
- type EventfulRoom
- type PowerLevelfulRoom
- type PushAction
- type PushActionArray
- type PushActionArrayShould
- type PushActionTweak
- type PushActionType
- type PushCondKind
- type PushCondition
- type PushRule
- type PushRuleArray
- func (rules PushRuleArray) GetActions(room Room, evt *event.Event) PushActionArray
- func (rules PushRuleArray) GetMatchingRule(room Room, evt *event.Event) *PushRule
- func (rules PushRuleArray) SetType(typ PushRuleType) PushRuleArray
- func (rules PushRuleArray) SetTypeAndMap(typ PushRuleType) PushRuleMap
- type PushRuleCollection
- type PushRuleMap
- type PushRuleType
- type PushRuleset
- type Room
Constants ¶
This section is empty.
Variables ¶
var DefaultPushActions = PushActionArray{&PushAction{Action: ActionDontNotify}}
DefaultPushActions is the value returned if none of the rule collections in a Ruleset match the event given to GetActions()
var MemberCountFilterRegex = regexp.MustCompile("^(==|[<>]=?)?([0-9]+)$")
MemberCountFilterRegex is the regular expression to parse the MemberCountCondition of PushConditions.
Functions ¶
This section is empty.
Types ¶
type EventContent ¶
type EventContent struct {
Ruleset *PushRuleset `json:"global"`
}
EventContent represents the content of a m.push_rules account data event. https://spec.matrix.org/v1.2/client-server-api/#mpush_rules
type EventfulRoom ¶ added in v0.12.2
EventfulRoom is an extension of Room to support MSC3664.
type PowerLevelfulRoom ¶ added in v0.22.0
type PowerLevelfulRoom interface {
Room
GetPowerLevels() *event.PowerLevelsEventContent
}
type PushAction ¶
type PushAction struct {
Action PushActionType
Tweak PushActionTweak
Value interface{}
}
PushAction is a single action that should be triggered when receiving a message.
func (*PushAction) MarshalJSON ¶
func (action *PushAction) MarshalJSON() (raw []byte, err error)
MarshalJSON is the reverse of UnmarshalJSON()
func (*PushAction) UnmarshalJSON ¶
func (action *PushAction) UnmarshalJSON(raw []byte) error
UnmarshalJSON parses JSON into this PushAction.
- If the JSON is a single string, the value is stored in the Action field.
- If the JSON is an object with the set_tweak field, Action will be set to "set_tweak", Tweak will be set to the value of the set_tweak field and and Value will be set to the value of the value field.
- In any other case, the function does nothing.
type PushActionArray ¶
type PushActionArray []*PushAction
PushActionArray is an array of PushActions.
func (PushActionArray) Should ¶
func (actions PushActionArray) Should() (should PushActionArrayShould)
Should parses this push action array and returns the relevant details wrapped in a PushActionArrayShould struct.
type PushActionArrayShould ¶
type PushActionArrayShould struct {
// 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 the event in question should trigger a notification.
Notify bool
// Whether the event in question should be highlighted.
Highlight bool
// 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
}
PushActionArrayShould contains the important information parsed from a PushActionArray.
type PushActionTweak ¶
type PushActionTweak string
PushActionTweak is the type of the tweak in SetTweak push actions.
const ( TweakSound PushActionTweak = "sound" TweakHighlight PushActionTweak = "highlight" )
The allowed tweak types as specified in spec section 11.12.1.4.1.1.
type PushActionType ¶
type PushActionType string
PushActionType is the type of a PushAction
const ( ActionNotify PushActionType = "notify" ActionDontNotify PushActionType = "dont_notify" ActionCoalesce PushActionType = "coalesce" ActionSetTweak PushActionType = "set_tweak" )
The allowed push action types as specified in spec section 11.12.1.4.1.
type PushCondKind ¶
type PushCondKind string
PushCondKind is the type of a push condition.
const ( KindEventMatch PushCondKind = "event_match" KindContainsDisplayName PushCondKind = "contains_display_name" KindRoomMemberCount PushCondKind = "room_member_count" KindEventPropertyIs PushCondKind = "event_property_is" KindEventPropertyContains PushCondKind = "event_property_contains" KindSenderNotificationPermission PushCondKind = "sender_notification_permission" KindRelatedEventMatch PushCondKind = "related_event_match" KindUnstableRelatedEventMatch PushCondKind = "im.nheko.msc3664.related_event_match" )
The allowed push condition kinds as specified in https://spec.matrix.org/v1.2/client-server-api/#conditions-1
type PushCondition ¶
type PushCondition struct {
// The type of the condition.
Kind PushCondKind `json:"kind"`
// The dot-separated field of the event to match. Only applicable if kind is EventMatch.
Key string `json:"key,omitempty"`
// The glob-style pattern to match the field against. Only applicable if kind is EventMatch.
Pattern string `json:"pattern,omitempty"`
// The exact value to match the field against. Only applicable if kind is EventPropertyIs or EventPropertyContains.
Value any `json:"value,omitempty"`
// The condition that needs to be fulfilled for RoomMemberCount-type conditions.
// A decimal integer optionally prefixed by ==, <, >, >= or <=. Prefix "==" is assumed if no prefix found.
MemberCountCondition string `json:"is,omitempty"`
// The relation type for related_event_match from MSC3664
RelType event.RelationType `json:"rel_type,omitempty"`
}
PushCondition wraps a condition that is required for a specific PushRule to be used.
type PushRule ¶
type PushRule struct {
// The type of this rule.
Type PushRuleType `json:"-"`
// The ID of this rule.
// For room-specific rules and user-specific rules, this is the room or user ID (respectively)
// For other types of rules, this doesn't affect anything.
RuleID string `json:"rule_id"`
// The actions this rule should trigger when matched.
Actions PushActionArray `json:"actions"`
// Whether this is a default rule, or has been set explicitly.
Default bool `json:"default"`
// Whether or not this push rule is enabled.
Enabled bool `json:"enabled"`
// The conditions to match in order to trigger this rule.
// Only applicable to generic underride/override rules.
Conditions []*PushCondition `json:"conditions,omitempty"`
// Pattern for content-specific push rules
Pattern string `json:"pattern,omitempty"`
}
func (*PushRule) GetActions ¶ added in v0.15.1
func (rule *PushRule) GetActions() PushActionArray
type PushRuleArray ¶
type PushRuleArray []*PushRule
func (PushRuleArray) GetActions ¶
func (rules PushRuleArray) GetActions(room Room, evt *event.Event) PushActionArray
func (PushRuleArray) GetMatchingRule ¶ added in v0.15.1
func (rules PushRuleArray) GetMatchingRule(room Room, evt *event.Event) *PushRule
func (PushRuleArray) SetType ¶
func (rules PushRuleArray) SetType(typ PushRuleType) PushRuleArray
func (PushRuleArray) SetTypeAndMap ¶
func (rules PushRuleArray) SetTypeAndMap(typ PushRuleType) PushRuleMap
type PushRuleCollection ¶
type PushRuleMap ¶
type PushRuleMap struct {
Map map[string]*PushRule
Type PushRuleType
}
func (PushRuleMap) GetActions ¶
func (ruleMap PushRuleMap) GetActions(room Room, evt *event.Event) PushActionArray
func (PushRuleMap) GetMatchingRule ¶ added in v0.15.1
func (ruleMap PushRuleMap) GetMatchingRule(room Room, evt *event.Event) *PushRule
func (PushRuleMap) Unmap ¶
func (ruleMap PushRuleMap) Unmap() PushRuleArray
type PushRuleType ¶
type PushRuleType string
const ( OverrideRule PushRuleType = "override" ContentRule PushRuleType = "content" RoomRule PushRuleType = "room" SenderRule PushRuleType = "sender" UnderrideRule PushRuleType = "underride" )
type PushRuleset ¶
type PushRuleset struct {
Override PushRuleArray
Content PushRuleArray
Room PushRuleMap
Sender PushRuleMap
Underride PushRuleArray
}
func EventToPushRules ¶
func EventToPushRules(evt *event.Event) (*PushRuleset, error)
EventToPushRules converts a m.push_rules event to a PushRuleset by passing the data through JSON.
func (*PushRuleset) GetActions ¶
func (rs *PushRuleset) GetActions(room Room, evt *event.Event) (match PushActionArray)
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 (*PushRuleset) GetMatchingRule ¶ added in v0.15.1
func (rs *PushRuleset) GetMatchingRule(room Room, evt *event.Event) (rule *PushRule)
func (*PushRuleset) MarshalJSON ¶
func (rs *PushRuleset) MarshalJSON() ([]byte, error)
MarshalJSON is the reverse of UnmarshalJSON()
func (*PushRuleset) UnmarshalJSON ¶
func (rs *PushRuleset) UnmarshalJSON(raw []byte) (err error)
UnmarshalJSON parses JSON into this PushRuleset.
For override, sender and underride push rule arrays, the type is added to each PushRule and the array is used as-is.
For room and sender push rule arrays, the type is added to each PushRule and the array is converted to a map with the rule ID as the key and the PushRule as the value.