From 371b3827d287d65f6467cccf16cae1e3be2dca58 Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Thu, 27 Jun 2013 10:26:33 -0400 Subject: [PATCH] Show unread subjects in stream sidebar. Trac #1403. This shows the 5 most recent subjects, as well as any others with unread messages. This requires tracking all subjects and filtering at display time, rather than filtering when building the subject list. (imported from commit 8bda7d50e6785a6e70abea4b3af4d03a16d076d3) --- zephyr/static/js/stream_list.js | 9 ++++++--- zephyr/static/js/zephyr.js | 3 --- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zephyr/static/js/stream_list.js b/zephyr/static/js/stream_list.js index 5ac8bedb29..731e9fb5ab 100644 --- a/zephyr/static/js/stream_list.js +++ b/zephyr/static/js/stream_list.js @@ -155,10 +155,11 @@ function rebuild_recent_subjects(stream, subject) { // TODO: Call rebuild_recent_subjects less, not on every new // message. $('.expanded_subjects').remove(); + var max_subjects = 5; var stream_li = get_filter_li('stream', stream); var subjects = recent_subjects[stream] || []; var active_orig_subject = subject; - $.each(subjects, function (idx, subject_obj) { + var display_subjects = $.grep(subjects, function (subject_obj, idx) { var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject); subject_obj.unread = num_unread; subject_obj.is_zero = num_unread === 0; @@ -167,11 +168,13 @@ function rebuild_recent_subjects(stream, subject) { active_orig_subject = subject_obj.subject; } subject_obj.url = narrow.by_stream_subject_uri(stream, subject_obj.subject); + + // Show the most recent subjects, as well as any with unread messages + return idx < max_subjects || subject_obj.unread > 0; }); - stream_li.append(templates.render('sidebar_subject_list', - {subjects: subjects, + {subjects: display_subjects, stream: stream})); if (active_orig_subject !== undefined) { diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 56b4b03f25..ced414c655 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -495,7 +495,6 @@ function case_insensitive_find(term, array) { function process_message_for_recent_subjects(message, remove_message) { var current_timestamp = 0; - var max_subjects = 5; var count = 0; var canon_stream = subs.canonicalized_name(message.stream); var canon_subject = subs.canonicalized_name(message.subject); @@ -534,8 +533,6 @@ function process_message_for_recent_subjects(message, remove_message) { return b.timestamp - a.timestamp; }); - recents = recents.slice(0, max_subjects); - recent_subjects[canon_stream] = recents; }