For mit.edu, include unclasses and .d classes in narrowed views

(imported from commit e21aab715c949d4348c447e6e135281b47e06b98)
This commit is contained in:
Jeff Arnold 2013-06-25 17:12:59 -04:00 committed by Tim Abbott
parent dc54a24766
commit 45116a0b61
2 changed files with 22 additions and 3 deletions

View File

@ -103,7 +103,7 @@ Filter.prototype = {
// build JavaScript code in a string and then eval() it.
return function (message) {
var operand, i;
var operand, i, index;
for (i = 0; i < operators.length; i++) {
operand = operators[i][1];
switch (operators[i][0]) {
@ -133,9 +133,19 @@ Filter.prototype = {
break;
case 'stream':
if ((message.type !== 'stream') ||
(message.stream.toLowerCase() !== operand))
if (message.type !== 'stream')
return false;
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)
var related_regexp = new RegExp(/^(un)*/.source + util.escape_regexp(message.stream) + /(.d)*$/.source, 'i');
if (! related_regexp.test(operand)) {
return false;
}
} else if (message.stream.toLowerCase() !== operand) {
return false;
}
break;
case 'subject':

View File

@ -696,6 +696,15 @@ class NarrowBuilder(object):
stream = get_stream(operand, self.user_profile.realm)
if stream is None:
raise BadNarrowOperator('unknown stream ' + operand)
if self.user_profile.realm.domain == "mit.edu":
# MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/
# (unsocial, ununsocial, social.d, etc)
matching_streams = Stream.objects.filter(realm=self.user_profile.realm,
name__iregex=r'"^(un)*%s(.d)*$' % (re.escape(stream.name),))
return self.pQ(recipient__in=[get_recipient(Recipient.STREAM, type_id=stream.id)
for stream in matching_streams])
recipient = get_recipient(Recipient.STREAM, type_id=stream.id)
return self.pQ(recipient=recipient)