Sort the narrow list better when there are more than 40 streams.

This shouldn't have any effect in normal realms, but for realms like
mit.edu that have large numbers of inactive streams, it will sort all
the streams that have had a recent message at the top (aka those that
aren't effectively inactive).

(imported from commit 027ce258d04b6fd58705e49f769dec7e0639bb38)
This commit is contained in:
Tim Abbott
2013-04-30 17:37:46 -04:00
parent 30f825ebfe
commit 203fc55a7c
2 changed files with 28 additions and 2 deletions

View File

@@ -1157,15 +1157,35 @@ $(function () {
});
function sort_narrow_list() {
var sort_recent = (subs.subscribed_streams().length > 40);
var items = $('#stream_filters > li').get();
var parent = $('#stream_filters');
items.sort(function(a,b){
return $(a).attr('data-name').localeCompare($(b).attr('data-name'));
var a_stream_name = $(a).attr('data-name');
var b_stream_name = $(b).attr('data-name');
if (sort_recent) {
if (recent_subjects[b_stream_name] !== undefined &&
recent_subjects[a_stream_name] === undefined) {
return 1;
} else if (recent_subjects[b_stream_name] === undefined &&
recent_subjects[a_stream_name] !== undefined) {
return -1;
}
}
return a_stream_name.localeCompare(b_stream_name);
});
parent.empty();
$.each(items, function(i, li){
var stream_name = $(li).attr('data-name');
if (sort_recent) {
if (recent_subjects[stream_name] === undefined) {
$(li).addClass("inactive_stream");
} else {
$(li).removeClass("inactive_stream");
}
}
parent.append(li);
});
}
@@ -1394,6 +1414,8 @@ exports.update_recent_subjects = function () {
}
}
});
// Resort the narrow list based on which streams have messages
sort_narrow_list();
};
return exports;

View File

@@ -1187,3 +1187,7 @@ li.expanded_subject {
#compose a.message-control-button:hover {
color: #000;
}
#stream_filters .inactive_stream {
opacity: .5;
}