From 0f6bdafea3cd5105e0d1dcdca98c7e5c2ad28ba5 Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Tue, 2 Jul 2013 15:50:05 -0400 Subject: [PATCH] Mark all messages in view as read when you hit the bottom. Trac #1428 (imported from commit f40d890091528969ae4e4db80adb019cbce60fef) --- tools/jslint/check-all.js | 2 +- zephyr/static/js/hotkey.js | 3 +++ zephyr/static/js/zephyr.js | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 59781d1456..3138bd0a3f 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -44,7 +44,7 @@ var globals = + ' viewport restart_get_updates force_get_updates' + ' load_more_messages reset_load_more_status have_scrolled_away_from_top' + ' maybe_scroll_to_selected recenter_pointer_on_display suppress_scroll_pointer_update' - + ' message_range message_in_table process_loaded_for_unread' + + ' mark_current_list_as_read message_range message_in_table process_loaded_for_unread' + ' mark_all_as_read message_unread process_read_messages unread_in_current_view' + ' fast_forward_pointer recent_subjects unread_subjects' + ' add_message_metadata' diff --git a/zephyr/static/js/hotkey.js b/zephyr/static/js/hotkey.js index 45a7cdd8b0..bbc26fc69b 100644 --- a/zephyr/static/js/hotkey.js +++ b/zephyr/static/js/hotkey.js @@ -191,6 +191,7 @@ function process_hotkey(e) { last_viewport_movement_direction = 1; current_msg_list.select_id(next_id, {then_scroll: true, from_scroll: true}); + mark_current_list_as_read(); return true; } @@ -213,6 +214,7 @@ function process_hotkey(e) { // FIXME: this doesn't work for End because rows.last_visible() // always returns a message. viewport.scrollTop($("#main_div").outerHeight(true)); + mark_current_list_as_read(); } return true; } @@ -245,6 +247,7 @@ function process_hotkey(e) { case 'page_down': if (viewport.at_bottom() && !current_msg_list.empty()) { current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false}); + mark_current_list_as_read(); } else { ui.page_down_the_right_amount(); diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 741425dbfa..be06a96b9d 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -346,14 +346,14 @@ function process_read_messages(messages) { } function mark_read_between(msg_list, start_id, end_id) { - var mark_as_read = []; - $.each(message_range(msg_list, start_id, end_id), - function (idx, msg) { - if (unread.message_unread(msg)) { - mark_as_read.push(msg); - } - }); - process_read_messages(mark_as_read); + var msgs_in_range = message_range(msg_list, start_id, end_id); + var unread_msgs = $.grep(msgs_in_range, unread.message_unread); + process_read_messages(unread_msgs); +} + +function mark_current_list_as_read() { + var unread_msgs = $.grep(current_msg_list.all(), unread.message_unread); + process_read_messages(unread_msgs); } function update_pointer() { @@ -1195,6 +1195,10 @@ function move_pointer_at_page_top_and_bottom(delta) { } else { // We're scrolling down (we want more recent messages) next_row = rows.next_visible(next_row); + + if (next_row.length === 0) { + mark_current_list_as_read(); + } } if (next_row.length !== 0) { current_msg_list.select_id(rows.id(next_row));