Change mark-as-read behavior.

Mark messages as read when with the pointer, but mark all messages
read if the last message is visible.

(imported from commit 4c1a928bd6966111f0f34c5207723656b5f193b9)
This commit is contained in:
Kevin Mehall 2013-07-26 13:14:33 -04:00
parent 0e0ed886e1
commit 0cbee97ffd
2 changed files with 25 additions and 7 deletions

View File

@ -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();
};

View File

@ -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);
}
}
}