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
Apply prettier formatting
This commit is contained in:
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { deepCompare, escapeRegExp, globToRegexp, isNullOrUndefined } from "./utils";
|
||||
import { logger } from './logger';
|
||||
import { logger } from "./logger";
|
||||
import { MatrixClient } from "./client";
|
||||
import { MatrixEvent } from "./models/event";
|
||||
import {
|
||||
@@ -66,9 +66,7 @@ const DEFAULT_OVERRIDE_RULES: IPushRule[] = [
|
||||
pattern: "m.reaction",
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
PushRuleActionName.DontNotify,
|
||||
],
|
||||
actions: [PushRuleActionName.DontNotify],
|
||||
},
|
||||
{
|
||||
// For homeservers which don't support MSC3786 yet
|
||||
@@ -139,7 +137,7 @@ export class PushProcessor {
|
||||
for (const action of actionList) {
|
||||
if (action === PushRuleActionName.Notify) {
|
||||
actionObj.notify = true;
|
||||
} else if (typeof action === 'object') {
|
||||
} else if (typeof action === "object") {
|
||||
if (action.value === undefined) {
|
||||
action.value = true;
|
||||
}
|
||||
@@ -169,8 +167,7 @@ export class PushProcessor {
|
||||
// Merge the client-level defaults with the ones from the server
|
||||
const globalOverrides = newRules.global.override;
|
||||
for (const override of DEFAULT_OVERRIDE_RULES) {
|
||||
const existingRule = globalOverrides
|
||||
.find((r) => r.rule_id === override.rule_id);
|
||||
const existingRule = globalOverrides.find((r) => r.rule_id === override.rule_id);
|
||||
|
||||
if (existingRule) {
|
||||
// Copy over the actions, default, and conditions. Don't touch the user's preference.
|
||||
@@ -187,8 +184,7 @@ export class PushProcessor {
|
||||
|
||||
const globalUnderrides = newRules.global.underride ?? [];
|
||||
for (const underride of DEFAULT_UNDERRIDE_RULES) {
|
||||
const existingRule = globalUnderrides
|
||||
.find((r) => r.rule_id === underride.rule_id);
|
||||
const existingRule = globalUnderrides.find((r) => r.rule_id === underride.rule_id);
|
||||
|
||||
if (existingRule) {
|
||||
// Copy over the actions, default, and conditions. Don't touch the user's preference.
|
||||
@@ -241,9 +237,9 @@ export class PushProcessor {
|
||||
tprule: IPushRule,
|
||||
): Pick<IPushRule, "rule_id" | "actions" | "conditions"> | null {
|
||||
const rawrule: Pick<IPushRule, "rule_id" | "actions" | "conditions"> = {
|
||||
'rule_id': tprule.rule_id,
|
||||
'actions': tprule.actions,
|
||||
'conditions': [],
|
||||
rule_id: tprule.rule_id,
|
||||
actions: tprule.actions,
|
||||
conditions: [],
|
||||
};
|
||||
switch (kind) {
|
||||
case PushRuleKind.Underride:
|
||||
@@ -255,9 +251,9 @@ export class PushProcessor {
|
||||
return null;
|
||||
}
|
||||
rawrule.conditions!.push({
|
||||
'kind': ConditionKind.EventMatch,
|
||||
'key': 'room_id',
|
||||
'value': tprule.rule_id,
|
||||
kind: ConditionKind.EventMatch,
|
||||
key: "room_id",
|
||||
value: tprule.rule_id,
|
||||
});
|
||||
break;
|
||||
case PushRuleKind.SenderSpecific:
|
||||
@@ -265,9 +261,9 @@ export class PushProcessor {
|
||||
return null;
|
||||
}
|
||||
rawrule.conditions!.push({
|
||||
'kind': ConditionKind.EventMatch,
|
||||
'key': 'user_id',
|
||||
'value': tprule.rule_id,
|
||||
kind: ConditionKind.EventMatch,
|
||||
key: "user_id",
|
||||
value: tprule.rule_id,
|
||||
});
|
||||
break;
|
||||
case PushRuleKind.ContentSpecific:
|
||||
@@ -275,9 +271,9 @@ export class PushProcessor {
|
||||
return null;
|
||||
}
|
||||
rawrule.conditions!.push({
|
||||
'kind': ConditionKind.EventMatch,
|
||||
'key': 'content.body',
|
||||
'pattern': tprule.pattern,
|
||||
kind: ConditionKind.EventMatch,
|
||||
key: "content.body",
|
||||
pattern: tprule.pattern,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -309,7 +305,7 @@ export class PushProcessor {
|
||||
cond: ISenderNotificationPermissionCondition,
|
||||
ev: MatrixEvent,
|
||||
): boolean {
|
||||
const notifLevelKey = cond['key'];
|
||||
const notifLevelKey = cond["key"];
|
||||
if (!notifLevelKey) {
|
||||
return false;
|
||||
}
|
||||
@@ -347,16 +343,16 @@ export class PushProcessor {
|
||||
return false;
|
||||
}
|
||||
switch (ineq) {
|
||||
case '':
|
||||
case '==':
|
||||
case "":
|
||||
case "==":
|
||||
return memberCount == rhs;
|
||||
case '<':
|
||||
case "<":
|
||||
return memberCount < rhs;
|
||||
case '>':
|
||||
case ">":
|
||||
return memberCount > rhs;
|
||||
case '<=':
|
||||
case "<=":
|
||||
return memberCount <= rhs;
|
||||
case '>=':
|
||||
case ">=":
|
||||
return memberCount >= rhs;
|
||||
default:
|
||||
return false;
|
||||
@@ -368,7 +364,7 @@ export class PushProcessor {
|
||||
if (ev.isEncrypted() && ev.getClearContent()) {
|
||||
content = ev.getClearContent()!;
|
||||
}
|
||||
if (!content || !content.body || typeof content.body != 'string') {
|
||||
if (!content || !content.body || typeof content.body != "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -382,7 +378,7 @@ export class PushProcessor {
|
||||
|
||||
// N.B. we can't use \b as it chokes on unicode. however \W seems to be okay
|
||||
// as shorthand for [^0-9A-Za-z_].
|
||||
const pat = new RegExp("(^|\\W)" + escapeRegExp(displayName) + "(\\W|$)", 'i');
|
||||
const pat = new RegExp("(^|\\W)" + escapeRegExp(displayName) + "(\\W|$)", "i");
|
||||
return content.body.search(pat) > -1;
|
||||
}
|
||||
|
||||
@@ -392,7 +388,7 @@ export class PushProcessor {
|
||||
}
|
||||
|
||||
const val = this.valueForDottedKey(cond.key, ev);
|
||||
if (typeof val !== 'string') {
|
||||
if (typeof val !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -400,13 +396,14 @@ export class PushProcessor {
|
||||
return cond.value === val;
|
||||
}
|
||||
|
||||
if (typeof cond.pattern !== 'string') {
|
||||
if (typeof cond.pattern !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const regex = cond.key === 'content.body'
|
||||
? this.createCachedRegex('(^|\\W)', cond.pattern, '(\\W|$)')
|
||||
: this.createCachedRegex('^', cond.pattern, '$');
|
||||
const regex =
|
||||
cond.key === "content.body"
|
||||
? this.createCachedRegex("(^|\\W)", cond.pattern, "(\\W|$)")
|
||||
: this.createCachedRegex("^", cond.pattern, "$");
|
||||
|
||||
return !!val.match(regex);
|
||||
}
|
||||
@@ -418,12 +415,10 @@ export class PushProcessor {
|
||||
// Since servers don't support properly sending push notification
|
||||
// about MSC3401 call events, we do the handling ourselves
|
||||
return (
|
||||
["m.ring", "m.prompt"].includes(ev.getContent()["m.intent"])
|
||||
&& !("m.terminated" in ev.getContent())
|
||||
&& (
|
||||
(ev.getPrevContent()["m.terminated"] !== ev.getContent()["m.terminated"])
|
||||
|| deepCompare(ev.getPrevContent(), {})
|
||||
)
|
||||
["m.ring", "m.prompt"].includes(ev.getContent()["m.intent"]) &&
|
||||
!("m.terminated" in ev.getContent()) &&
|
||||
(ev.getPrevContent()["m.terminated"] !== ev.getContent()["m.terminated"] ||
|
||||
deepCompare(ev.getPrevContent(), {}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -433,21 +428,21 @@ export class PushProcessor {
|
||||
}
|
||||
PushProcessor.cachedGlobToRegex[glob] = new RegExp(
|
||||
prefix + globToRegexp(glob) + suffix,
|
||||
'i', // Case insensitive
|
||||
"i", // Case insensitive
|
||||
);
|
||||
return PushProcessor.cachedGlobToRegex[glob];
|
||||
}
|
||||
|
||||
private valueForDottedKey(key: string, ev: MatrixEvent): any {
|
||||
const parts = key.split('.');
|
||||
const parts = key.split(".");
|
||||
let val: any;
|
||||
|
||||
// special-case the first component to deal with encrypted messages
|
||||
const firstPart = parts[0];
|
||||
if (firstPart === 'content') {
|
||||
if (firstPart === "content") {
|
||||
val = ev.getContent();
|
||||
parts.shift();
|
||||
} else if (firstPart === 'type') {
|
||||
} else if (firstPart === "type") {
|
||||
val = ev.getType();
|
||||
parts.shift();
|
||||
} else {
|
||||
@@ -488,14 +483,14 @@ export class PushProcessor {
|
||||
if (actionObj.tweaks.highlight === undefined) {
|
||||
// if it isn't specified, highlight if it's a content
|
||||
// rule but otherwise not
|
||||
actionObj.tweaks.highlight = (rule.kind == PushRuleKind.ContentSpecific);
|
||||
actionObj.tweaks.highlight = rule.kind == PushRuleKind.ContentSpecific;
|
||||
}
|
||||
|
||||
return actionObj;
|
||||
}
|
||||
|
||||
public ruleMatchesEvent(rule: Partial<IPushRule> & Pick<IPushRule, "conditions">, ev: MatrixEvent): boolean {
|
||||
return !rule.conditions?.some(cond => !this.eventFulfillsCondition(cond, ev));
|
||||
return !rule.conditions?.some((cond) => !this.eventFulfillsCondition(cond, ev));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,7 +507,7 @@ export class PushProcessor {
|
||||
* @returns The push rule, or null if no such rule was found
|
||||
*/
|
||||
public getPushRuleById(ruleId: string): IPushRule | null {
|
||||
for (const scope of ['global'] as const) {
|
||||
for (const scope of ["global"] as const) {
|
||||
if (this.client.pushRules?.[scope] === undefined) continue;
|
||||
|
||||
for (const kind of RULEKINDS_IN_ORDER) {
|
||||
|
||||
Reference in New Issue
Block a user