diff --git a/static/js/filter.js b/static/js/filter.js index 5955c37364..5ec8cf4f11 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -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) {