You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Implement MSC3966: a push rule condition to check if an array contains a value (#3180)
* Support MSC3966 to match values in an array in push rule conditions. * Update to stable identifiers. * Appease the linter.
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
IContainsDisplayNameCondition,
|
||||
IEventMatchCondition,
|
||||
IEventPropertyIsCondition,
|
||||
IEventPropertyContainsCondition,
|
||||
IPushRule,
|
||||
IPushRules,
|
||||
IRoomMemberCountCondition,
|
||||
@@ -340,6 +341,8 @@ export class PushProcessor {
|
||||
return this.eventFulfillsEventMatchCondition(cond, ev);
|
||||
case ConditionKind.EventPropertyIs:
|
||||
return this.eventFulfillsEventPropertyIsCondition(cond, ev);
|
||||
case ConditionKind.EventPropertyContains:
|
||||
return this.eventFulfillsEventPropertyContains(cond, ev);
|
||||
case ConditionKind.ContainsDisplayName:
|
||||
return this.eventFulfillsDisplayNameCondition(cond, ev);
|
||||
case ConditionKind.RoomMemberCount:
|
||||
@@ -488,6 +491,24 @@ export class PushProcessor {
|
||||
return cond.value === this.valueForDottedKey(cond.key, ev);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given event matches the push rule condition by fetching
|
||||
* the property from the event and comparing exactly against the condition's
|
||||
* value.
|
||||
* @param cond - The push rule condition to check for a match.
|
||||
* @param ev - The event to check for a match.
|
||||
*/
|
||||
private eventFulfillsEventPropertyContains(cond: IEventPropertyContainsCondition, ev: MatrixEvent): boolean {
|
||||
if (!cond.key || cond.value === undefined) {
|
||||
return false;
|
||||
}
|
||||
const val = this.valueForDottedKey(cond.key, ev);
|
||||
if (!Array.isArray(val)) {
|
||||
return false;
|
||||
}
|
||||
return val.includes(cond.value);
|
||||
}
|
||||
|
||||
private eventFulfillsCallStartedCondition(
|
||||
_cond: ICallStartedCondition | ICallStartedPrefixCondition,
|
||||
ev: MatrixEvent,
|
||||
|
||||
Reference in New Issue
Block a user