diff --git a/static/js/viewport.js b/static/js/viewport.js index 49a10d2c85..7210c3af62 100644 --- a/static/js/viewport.js +++ b/static/js/viewport.js @@ -48,6 +48,19 @@ exports.at_bottom = function () { return bottom + 2 >= window_size; }; +// This differs from at_bottom in that it only requires the bottom message to +// be visible, but you may be able to scroll down further. +exports.bottom_message_visible = function () { + var last_row = rows.last_visible(); + if (last_row.length) { + var message_bottom = last_row[0].getBoundingClientRect().bottom; + var bottom_of_feed = $("#compose")[0].getBoundingClientRect().top; + return bottom_of_feed > message_bottom; + } else { + return false; + } +}; + exports.is_below_visible_bottom = function (offset) { return offset > exports.scrollTop() + exports.height() - $("#compose").height(); }; diff --git a/static/js/zephyr.js b/static/js/zephyr.js index 5ff986a7d7..5d2e5ac358 100644 --- a/static/js/zephyr.js +++ b/static/js/zephyr.js @@ -1,6 +1,7 @@ var feature_flags = {}; _.each([ - 'always_open_compose' + 'always_open_compose', + 'mark_read_at_bottom' ], function (key) { feature_flags[key] = page_params.staging; }); @@ -338,17 +339,21 @@ function process_read_messages(messages) { // If we ever materially change the algorithm for this function, we // may need to update notifications.received_messages as well. function process_visible_unread_messages(update_cursor) { - // For any messages visible on the screen, make sure they have been marked - // as read. if (! notifications.window_has_focus()) { return; } - var visible_messages = viewport.visible_messages(); - var mark_as_read = _.filter(visible_messages, unread.message_unread); + if (feature_flags.mark_read_at_bottom) { + if (viewport.bottom_message_visible()) { + mark_current_list_as_read(); + } + } else { + var visible_messages = viewport.visible_messages(); + var mark_as_read = _.filter(visible_messages, unread.message_unread); - if (mark_as_read.length > 0) { - process_read_messages(mark_as_read); + if (mark_as_read.length > 0) { + process_read_messages(mark_as_read); + } } }