Mark all messages between start of scroll and end of scroll as read

If the user scrolls super fast, our scroll handler might not catch
the user  passing by some messages.

(imported from commit 14cebffcd1321f02443971ac5e1c922db19648ab)
This commit is contained in:
Leo Franchi 2013-03-15 10:23:28 -04:00
parent 4280affd1f
commit 79dfe57840
2 changed files with 24 additions and 2 deletions

View File

@ -41,7 +41,7 @@ var globals =
+ ' home_unread_messages'
+ ' maybe_scroll_to_selected recenter_pointer_on_display suppress_scroll_pointer_update'
+ ' process_visible_unread_messages message_range message_in_table process_loaded_for_unread'
+ ' mark_all_as_read message_unread'
+ ' mark_all_as_read message_unread process_read_messages'
;

View File

@ -512,6 +512,8 @@ $(function () {
function () { $('#send-status').stop(true).fadeOut(500); }
);
var scroll_start_message = -1;
function scroll_finished() {
if ($('#home').hasClass('active')) {
if (!suppress_scroll_pointer_update) {
@ -531,6 +533,21 @@ $(function () {
// When the window scrolls, it may cause some messages to go off the screen
notifications_bar.update();
var new_selected = current_msg_list.selected_id();
if (scroll_start_message === -1) {
blueslip.error("Got a scroll finish with no saved message from scroll start");
} else if (new_selected > scroll_start_message) {
var mark_as_read = [];
$.each(message_range(current_msg_list, scroll_start_message, new_selected),
function (idx, msg) {
if (message_unread(msg)) {
mark_as_read.push(msg);
}
});
process_read_messages(mark_as_read);
}
scroll_start_message = -1;
setTimeout(process_visible_unread_messages, 0);
}
}
@ -541,7 +558,12 @@ $(function () {
scroll_timer = setTimeout(scroll_finished, 100);
}
$(window).scroll(process_visible_unread_messages);
$(window).scroll(function () {
if (scroll_start_message === -1) {
scroll_start_message = current_msg_list.selected_id();
}
process_visible_unread_messages();
});
$(window).scroll($.throttle(50, function (e) {
if (!hotkeys.in_scroll_caused_by_keypress) {