mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
Extracted mit_edu_stream_name_match() in filter.js.
The original code was buried inside a switch statement inside a for statement. (imported from commit 768c4ee8596cb63b2caa14c5b113cc867db90293)
This commit is contained in:
parent
400f03fa60
commit
26a8aee2d0
@ -1,5 +1,18 @@
|
||||
var Filter = (function () {
|
||||
|
||||
function mit_edu_stream_name_match(message, operand) {
|
||||
// MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/
|
||||
// (unsocial, ununsocial, social.d, etc)
|
||||
// TODO: hoist the regex compiling out of the closure
|
||||
var m = /^(?:un)*(.+?)(?:\.d)*$/i.exec(operand);
|
||||
var base_stream_name = operand;
|
||||
if (m !== null && m[1] !== undefined) {
|
||||
base_stream_name = m[1];
|
||||
}
|
||||
var related_regexp = new RegExp(/^(un)*/.source + util.escape_regexp(base_stream_name) + /(\.d)*$/.source, 'i');
|
||||
return related_regexp.test(message.stream);
|
||||
}
|
||||
|
||||
function message_in_home(message) {
|
||||
if (message.type === "private") {
|
||||
return true;
|
||||
@ -230,16 +243,7 @@ Filter.prototype = {
|
||||
|
||||
operand = operand.toLowerCase();
|
||||
if (page_params.domain === "mit.edu") {
|
||||
// MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/
|
||||
// (unsocial, ununsocial, social.d, etc)
|
||||
// TODO: hoist the regex compiling out of the closure
|
||||
m = /^(?:un)*(.+?)(?:\.d)*$/i.exec(operand);
|
||||
var base_stream_name = operand;
|
||||
if (m !== null && m[1] !== undefined) {
|
||||
base_stream_name = m[1];
|
||||
}
|
||||
related_regexp = new RegExp(/^(un)*/.source + util.escape_regexp(base_stream_name) + /(\.d)*$/.source, 'i');
|
||||
if (! related_regexp.test(message.stream)) {
|
||||
if (!mit_edu_stream_name_match(message, operand)) {
|
||||
return false;
|
||||
}
|
||||
} else if (message.stream.toLowerCase() !== operand) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user