You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-19 16:42:09 +03:00
Get rid of micromatch & reinstate our hacky version because micromatch, ironically, is huge.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
var micromatch = require("micromatch");
|
||||
|
||||
/**
|
||||
* Construct a Push Processor.
|
||||
* @constructor
|
||||
@@ -152,15 +150,29 @@ module.exports = function(client) {
|
||||
var val = valueForDottedKey(cond.key, ev);
|
||||
if (!val || typeof val != 'string') { return false; }
|
||||
|
||||
// Supportting ! in globs would mean figuring out when we
|
||||
// don't want to use things as a regex, like room IDs
|
||||
var pat = cond.pattern.replace("!", "\\!");
|
||||
|
||||
if (cond.key == 'content.body') {
|
||||
return micromatch.contains(val, pat);
|
||||
pat = '\\b'+globToRegexp(cond.pattern)+'\\b';
|
||||
} else {
|
||||
return micromatch.isMatch(val, pat);
|
||||
pat = '^'+globToRegexp(cond.pattern)+'$';
|
||||
}
|
||||
var val = valueForDottedKey(cond['key'], ev);
|
||||
if (!val || typeof val != 'string') return false;
|
||||
var regex = new RegExp(pat, 'i');
|
||||
return !!val.match(regex);
|
||||
};
|
||||
|
||||
var globToRegexp = function(glob) {
|
||||
// From https://github.com/matrix-org/synapse/blob/abbee6b29be80a77e05730707602f3bbfc3f38cb/synapse/push/__init__.py#L132
|
||||
// Because micromatch is about 130KB with dependencies, and minimatch is not much better.
|
||||
var pat = escapeRegExp(glob);
|
||||
pat = pat.replace(/\\\*/, '.*');
|
||||
pat = pat.replace(/\?/, '.');
|
||||
pat = pat.replace(/\\\[(!|)(.*)\\]/, function(match, p1, p2, offset, string) {
|
||||
var first = p1 && '^' || '';
|
||||
var second = p2.replace(/\\\-/, '-');
|
||||
return '['+first+second+']';
|
||||
});
|
||||
return pat;
|
||||
};
|
||||
|
||||
var valueForDottedKey = function(key, ev) {
|
||||
|
Reference in New Issue
Block a user