mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
Extract mit_edu_topic_name_match() in filter.js
(imported from commit e062cf7e987ca5af20417fe49785efa35574f628)
This commit is contained in:
@@ -13,6 +13,28 @@ function mit_edu_stream_name_match(message, operand) {
|
|||||||
return related_regexp.test(message.stream);
|
return related_regexp.test(message.stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mit_edu_topic_name_match(message, operand) {
|
||||||
|
// MIT users expect narrowing to topic "foo" to also show messages to /^foo(.d)*$/
|
||||||
|
// (foo, foo.d, foo.d.d, etc)
|
||||||
|
// TODO: hoist the regex compiling out of the closure
|
||||||
|
var m = /^(.*?)(?:\.d)*$/i.exec(operand);
|
||||||
|
var base_topic = m[1];
|
||||||
|
var related_regexp;
|
||||||
|
|
||||||
|
// Additionally, MIT users expect the empty instance and
|
||||||
|
// instance "personal" to be the same.
|
||||||
|
if (base_topic === ''
|
||||||
|
|| base_topic.toLowerCase() === 'personal'
|
||||||
|
|| base_topic.toLowerCase() === '(instance "")')
|
||||||
|
{
|
||||||
|
related_regexp = /^(|personal|\(instance ""\))(\.d)*$/i;
|
||||||
|
} else {
|
||||||
|
related_regexp = new RegExp(/^/.source + util.escape_regexp(base_topic) + /(\.d)*$/.source, 'i');
|
||||||
|
}
|
||||||
|
|
||||||
|
return related_regexp.test(message.subject);
|
||||||
|
}
|
||||||
|
|
||||||
function message_in_home(message) {
|
function message_in_home(message) {
|
||||||
if (message.type === "private") {
|
if (message.type === "private") {
|
||||||
return true;
|
return true;
|
||||||
@@ -200,7 +222,7 @@ Filter.prototype = {
|
|||||||
// build JavaScript code in a string and then eval() it.
|
// build JavaScript code in a string and then eval() it.
|
||||||
|
|
||||||
return function (message) {
|
return function (message) {
|
||||||
var operand, i, index, m, related_regexp;
|
var operand, i, index;
|
||||||
for (i = 0; i < operators.length; i++) {
|
for (i = 0; i < operators.length; i++) {
|
||||||
operand = operators[i][1];
|
operand = operators[i][1];
|
||||||
switch (operators[i][0]) {
|
switch (operators[i][0]) {
|
||||||
@@ -258,24 +280,7 @@ Filter.prototype = {
|
|||||||
|
|
||||||
operand = operand.toLowerCase();
|
operand = operand.toLowerCase();
|
||||||
if (page_params.domain === "mit.edu") {
|
if (page_params.domain === "mit.edu") {
|
||||||
// MIT users expect narrowing to topic "foo" to also show messages to /^foo(.d)*$/
|
if (!mit_edu_topic_name_match(message, operand)) {
|
||||||
// (foo, foo.d, foo.d.d, etc)
|
|
||||||
// TODO: hoist the regex compiling out of the closure
|
|
||||||
m = /^(.*?)(?:\.d)*$/i.exec(operand);
|
|
||||||
var base_topic = m[1];
|
|
||||||
|
|
||||||
// Additionally, MIT users expect the empty instance and
|
|
||||||
// instance "personal" to be the same.
|
|
||||||
if (base_topic === ''
|
|
||||||
|| base_topic.toLowerCase() === 'personal'
|
|
||||||
|| base_topic.toLowerCase() === '(instance "")')
|
|
||||||
{
|
|
||||||
related_regexp = /^(|personal|\(instance ""\))(\.d)*$/i;
|
|
||||||
} else {
|
|
||||||
related_regexp = new RegExp(/^/.source + util.escape_regexp(base_topic) + /(\.d)*$/.source, 'i');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! related_regexp.test(message.subject)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (message.subject.toLowerCase() !== operand) {
|
} else if (message.subject.toLowerCase() !== operand) {
|
||||||
|
|||||||
Reference in New Issue
Block a user