Use same canonicalization for stream names when calculating recent subjects

(imported from commit d934f67cb469728162b8ae48b5fc63805bf18d8f)
This commit is contained in:
Leo Franchi 2013-05-22 09:45:31 -04:00
parent cce8dfab84
commit c12fd08050
3 changed files with 15 additions and 8 deletions

View File

@ -65,7 +65,7 @@ Filter.prototype = {
// We don't use $.map because it flattens returned arrays. // We don't use $.map because it flattens returned arrays.
$.each(operators_mixed_case, function (idx, operator) { $.each(operators_mixed_case, function (idx, operator) {
// We may want to consider allowing mixed-case operators at some point // We may want to consider allowing mixed-case operators at some point
new_operators.push([operator[0], operator[1].toString().toLowerCase()]); new_operators.push([operator[0], subs.canonicalized_name(operator[1])]);
}); });
return new_operators; return new_operators;
}, },

View File

@ -118,6 +118,10 @@ exports.stream_id = function(stream_name) {
return parseInt(sub.id, 10); return parseInt(sub.id, 10);
}; };
exports.canonicalized_name = function (stream_name) {
return stream_name.toString().toLowerCase();
};
function update_stream_sidebar_swatch_color(stream_name, color) { function update_stream_sidebar_swatch_color(stream_name, color) {
var id = exports.stream_id(stream_name); var id = exports.stream_id(stream_name);
$("#stream_sidebar_swatch_" + id).css('background-color', color); $("#stream_sidebar_swatch_" + id).css('background-color', color);

View File

@ -443,13 +443,15 @@ function process_message_for_recent_subjects(message, remove_message) {
var current_timestamp = 0; var current_timestamp = 0;
var max_subjects = 5; var max_subjects = 5;
var count = 0; var count = 0;
var canon_stream = subs.canonicalized_name(message.stream);
var canon_subject = subs.canonicalized_name(message.subject);
if (! recent_subjects.hasOwnProperty(message.stream)) { if (! recent_subjects.hasOwnProperty(canon_stream)) {
recent_subjects[message.stream] = []; recent_subjects[canon_stream] = [];
} else { } else {
recent_subjects[message.stream] = recent_subjects[canon_stream] =
$.grep(recent_subjects[message.stream], function (item) { $.grep(recent_subjects[canon_stream], function (item) {
var is_duplicate = (item.subject.toLowerCase() === message.subject.toLowerCase()); var is_duplicate = (item.canon_subject.toLowerCase() === canon_subject.toLowerCase());
if (is_duplicate) { if (is_duplicate) {
current_timestamp = item.timestamp; current_timestamp = item.timestamp;
count = item.count; count = item.count;
@ -459,7 +461,7 @@ function process_message_for_recent_subjects(message, remove_message) {
}); });
} }
var recents = recent_subjects[message.stream]; var recents = recent_subjects[canon_stream];
if (remove_message !== undefined) { if (remove_message !== undefined) {
count = count - 1; count = count - 1;
@ -469,6 +471,7 @@ function process_message_for_recent_subjects(message, remove_message) {
if (count !== 0) { if (count !== 0) {
recents.push({subject: message.subject, recents.push({subject: message.subject,
canon_subject: canon_subject,
count: count, count: count,
timestamp: Math.max(message.timestamp, current_timestamp)}); timestamp: Math.max(message.timestamp, current_timestamp)});
} }
@ -479,7 +482,7 @@ function process_message_for_recent_subjects(message, remove_message) {
recents = recents.slice(0, max_subjects); recents = recents.slice(0, max_subjects);
recent_subjects[message.stream] = recents; recent_subjects[canon_stream] = recents;
} }
var msg_metadata_cache = {}; var msg_metadata_cache = {};