1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Polls push rules (#3181)

* add poll push rule ids

* add getPushRuleAndKindById method to pushprocessor
This commit is contained in:
Kerry
2023-03-02 09:30:40 +13:00
committed by GitHub
parent c8a4d9b88a
commit 933a0c9909
3 changed files with 62 additions and 17 deletions

View File

@@ -634,6 +634,18 @@ export class PushProcessor {
* @returns The push rule, or null if no such rule was found
*/
public getPushRuleById(ruleId: string): IPushRule | null {
const result = this.getPushRuleAndKindById(ruleId);
return result?.rule ?? null;
}
/**
* Get one of the users push rules by its ID
*
* @param ruleId - The ID of the rule to search for
* @returns rule The push rule, or null if no such rule was found
* @returns kind - The PushRuleKind of the rule to search for
*/
public getPushRuleAndKindById(ruleId: string): { rule: IPushRule; kind: PushRuleKind } | null {
for (const scope of ["global"] as const) {
if (this.client.pushRules?.[scope] === undefined) continue;
@@ -641,7 +653,7 @@ export class PushProcessor {
if (this.client.pushRules[scope][kind] === undefined) continue;
for (const rule of this.client.pushRules[scope][kind]!) {
if (rule.rule_id === ruleId) return rule;
if (rule.rule_id === ruleId) return { rule, kind };
}
}
}