From 3be1acebaa7bbdcec930c843bed0a9214489295f Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 22 May 2013 12:06:40 -0400 Subject: [PATCH] Use canonicalized names when processing unread counts (imported from commit 9a4a1d48221f10489a9dcf3ab2532b73b0c26e4e) --- zephyr/static/js/stream_list.js | 13 +++++++---- zephyr/static/js/unread.js | 38 ++++++++++++++++++++------------- zephyr/static/js/zephyr.js | 4 ++-- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/zephyr/static/js/stream_list.js b/zephyr/static/js/stream_list.js index 77764d427a..c720e156af 100644 --- a/zephyr/static/js/stream_list.js +++ b/zephyr/static/js/stream_list.js @@ -159,18 +159,23 @@ function rebuild_recent_subjects(stream, subject) { $('.expanded_subjects').remove(); 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 num_unread = unread.num_unread_for_subject(stream, subject_obj.subject); + var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject); subject_obj.unread = num_unread; subject_obj.has_unread = num_unread !== 0; + + if (subject === subject_obj.canon_subject) { + active_orig_subject = subject_obj.subject; + } }); stream_li.append(templates.render('sidebar_subject_list', {subjects: subjects, stream: stream})); - if (subject !== undefined) { - get_subject_filter_li(stream, subject).addClass('active-subject-filter'); + if (active_orig_subject !== undefined) { + get_subject_filter_li(stream, active_orig_subject).addClass('active-subject-filter'); } } @@ -235,7 +240,7 @@ exports.update_dom_with_unread_counts = function (counts) { exports.set_count("global", "private-message", counts.private_message_count); exports.set_count("global", "home", counts.home_unread_messages); - // For now increases in private messages get special treatment in terms of + // For now increases in private messages get special treatment in terms of // animating the left pane. It is unlikely that we will generalize this, // since Starred messages are user-initiated and Home messages would be too // spammy. diff --git a/zephyr/static/js/unread.js b/zephyr/static/js/unread.js index 83327f9aa0..172ff556e5 100644 --- a/zephyr/static/js/unread.js +++ b/zephyr/static/js/unread.js @@ -8,7 +8,7 @@ var unread_subjects = {}; function unread_hashkey(message) { var hashkey; if (message.type === 'stream') { - hashkey = message.stream; + hashkey = subs.canonicalized_name(message.stream); } else { hashkey = message.display_reply_to; } @@ -18,11 +18,12 @@ function unread_hashkey(message) { } if (message.type === 'stream') { + var canon_subject = subs.canonicalized_name(message.subject); if (unread_subjects[hashkey] === undefined) { unread_subjects[hashkey] = {}; } - if (unread_subjects[hashkey][message.subject] === undefined) { - unread_subjects[hashkey][message.subject] = {}; + if (unread_subjects[hashkey][canon_subject] === undefined) { + unread_subjects[hashkey][canon_subject] = {}; } } @@ -49,19 +50,23 @@ exports.message_unread = function (message) { }; exports.update_unread_subjects = function (msg, event) { + var canon_stream = subs.canonicalized_name(msg.stream); + var canon_subject = subs.canonicalized_name(msg.subject); + if (event.subject !== undefined && - unread_subjects[msg.stream] !== undefined && - unread_subjects[msg.stream][msg.subject] !== undefined && - unread_subjects[msg.stream][msg.subject][msg.id]) { + unread_subjects[canon_stream] !== undefined && + unread_subjects[canon_stream][canon_subject] !== undefined && + unread_subjects[canon_stream][canon_subject][msg.id]) { + var new_canon_subject = subs.canonicalized_name(event.subject); // Move the unread subject count to the new subject - delete unread_subjects[msg.stream][msg.subject][msg.id]; - if (unread_subjects[msg.stream][msg.subject].length === 0) { - delete unread_subjects[msg.stream][msg.subject]; + delete unread_subjects[canon_stream][canon_subject][msg.id]; + if (unread_subjects[canon_stream][canon_subject].length === 0) { + delete unread_subjects[canon_stream][canon_subject]; } - if (unread_subjects[msg.stream][event.subject] === undefined) { - unread_subjects[msg.stream][event.subject] = {}; + if (unread_subjects[canon_stream][new_canon_subject] === undefined) { + unread_subjects[canon_stream][new_canon_subject] = {}; } - unread_subjects[msg.stream][event.subject][msg.id] = true; + unread_subjects[canon_stream][new_canon_subject][msg.id] = true; } }; @@ -76,7 +81,8 @@ exports.process_loaded_messages = function (messages) { unread_counts[message.type][hashkey][message.id] = true; if (message.type === 'stream') { - unread_subjects[hashkey][message.subject][message.id] = true; + var canon_subject = subs.canonicalized_name(message.subject); + unread_subjects[hashkey][canon_subject][message.id] = true; } }); }; @@ -85,7 +91,9 @@ exports.process_read_message = function (message) { var hashkey = unread_hashkey(message); delete unread_counts[message.type][hashkey][message.id]; if (message.type === 'stream') { - delete unread_subjects[message.stream][message.subject][message.id]; + var canon_stream = subs.canonicalized_name(message.stream); + var canon_subject = subs.canonicalized_name(message.subject); + delete unread_subjects[canon_stream][canon_subject][message.id]; } }; @@ -95,7 +103,7 @@ exports.declare_bankruptcy = function () { exports.get_counts = function () { var res = {}; - + // Return a data structure with various counts. This function should be // pretty cheap, even if you don't care about all the counts, and you // should strive to keep it free of side effects on globals or DOM. diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index c4c97f2562..a4e203c1a9 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -66,7 +66,7 @@ $(function () { }); function within_viewport(row_offset, row_height) { - // Returns true if a message is fully within the effectively visible + // Returns true if a message is fully within the effectively visible // part of the viewport. var message_top = row_offset.top; var message_bottom = message_top + row_height; @@ -271,7 +271,7 @@ function update_unread_counts() { // This updates some DOM elements directly, so try to // avoid excessive calls to this. - stream_list.update_dom_with_unread_counts(res); + stream_list.update_dom_with_unread_counts(res); notifications.update_title_count(); }