Change pointer semantic to better support side bar users.

There are now 2 cases for narrowing:

1. We narrowed, but only backwards in time (ie no unread were
read). In this case, try to go back to exactly where we were before
narrowing. This behavior is unchanged.

2. We read some unread messages in a narrow. Instead of going back to
where we were before the narrow, go to our first unread message (or
the bottom of the feed, if there are no unread messages). This is new.

This means that after catching up through the sidebar, on returning
home you'll be at the bottom of your feed.

Searching for the first unread message in a message list with 40,000
messages only takes 17ms according to:

function timeit() {
    var t0 = new Date().getTime();
    _.find(current_msg_list.all(), unread.message_unread);
    var t1 = new Date().getTime();
    console.log('Find first unread: ' + (t1 - t0) + ' ms');
}

(imported from commit 87c467578a2cced0aa976d8ae2924371b85d2445)
This commit is contained in:
Jessica McKellar 2013-11-26 13:06:21 -05:00
parent 7c9e7e57b9
commit 81b493ba0b
3 changed files with 36 additions and 13 deletions

View File

@ -172,6 +172,11 @@ exports.activate = function (operators, opts) {
var was_narrowed_already = exports.active();
var then_select_id = opts.then_select_id;
var then_select_offset;
if (!was_narrowed_already) {
unread_messages_read_in_narrow = false;
}
if (!opts.select_first_unread && current_msg_list.get_row(then_select_id).length > 0) {
then_select_offset = current_msg_list.get_row(then_select_id).offset().top -
viewport.scrollTop();
@ -414,12 +419,28 @@ exports.deactivate = function () {
current_msg_list.rerender();
}
// We fall back to the closest selected id, if the user has removed a stream from the home
// view since leaving it the old selected id might no longer be there
current_msg_list.select_id(current_msg_list.selected_id(), {
then_scroll: !preserve_pre_narrowing_screen_position,
use_closest: true
});
if (unread_messages_read_in_narrow) {
// We read some unread messages in a narrow. Instead of going back to
// where we were before the narrow, go to our first unread message (or
// the bottom of the feed, if there are no unread messages).
var first_unread = _.find(current_msg_list.all(), unread.message_unread);
if (first_unread) {
current_msg_list.select_id(first_unread.id, {use_closest: true});
} else {
current_msg_list.select_id(current_msg_list.last().id);
}
} else {
// We narrowed, but only backwards in time (ie no unread were read). Try
// to go back to exactly where we were before narrowing.
// We fall back to the closest selected id, if the user has removed a
// stream from the home view since leaving it the old selected id might
// no longer be there
current_msg_list.select_id(current_msg_list.selected_id(), {
then_scroll: !preserve_pre_narrowing_screen_position,
use_closest: true
});
}
if (preserve_pre_narrowing_screen_position) {
// We scroll the user back to exactly the offset from the selected

View File

@ -44,6 +44,7 @@ var last_viewport_movement_direction = 1;
var furthest_read = -1;
var server_furthest_read = -1;
var unread_messages_read_in_narrow = false;
var pointer_update_in_flight = false;
var suppress_unread_counts = true;
@ -379,6 +380,9 @@ function mark_messages_as_read(messages, options) {
// Don't do anything if the message is already read.
return;
}
if (current_msg_list === narrowed_msg_list) {
unread_messages_read_in_narrow = true;
}
send_read(message);
summary.maybe_mark_summarized(message);
@ -1290,12 +1294,10 @@ function main() {
$(document).on('message_selected.zulip', function (event) {
// Narrowing is a temporary view on top of the home view and
// doesn't affect your pointer in the home view.
if (event.msg_list === home_msg_list
&& event.id > furthest_read)
{
furthest_read = event.id;
if ((event.msg_list === home_msg_list) || (event.msg_list === all_msg_list)) {
if (event.id > furthest_read) {
furthest_read = event.id;
}
}
if (event.mark_read && event.previously_selected !== -1) {

View File

@ -45,7 +45,7 @@ var globals =
+ ' all_msg_list home_msg_list narrowed_msg_list current_msg_list get_updates_params'
+ ' add_messages'
+ ' people_dict realm_people_dict'
+ ' keep_pointer_in_view'
+ ' keep_pointer_in_view unread_messages_read_in_narrow'
+ ' respond_to_message recenter_view last_viewport_movement_direction'
+ ' scroll_to_selected get_private_message_recipient'
+ ' load_old_messages enable_unread_counts'