From fa2573815964e632e779b2a01fac83fa3d9df10b Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 19 Feb 2020 13:45:57 -0800 Subject: [PATCH] message_fetch: Select the anchor message in home view. In the past, the anchor message has always been the same as the pointer, but we're about to change that as part of removing the pointer entirely. Using the anchor is logically what we meant, anyway, since we always want to select a message that's actually within the range we just fetched. --- frontend_tests/node_tests/message_fetch.js | 1 + static/js/message_fetch.js | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 17a5966644..ea2e44a06f 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -143,6 +143,7 @@ const initialize_data = { resp: { messages: message_range(201, 801), found_newest: false, + anchor: 444, }, }, diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index f98209f418..2bebac24cf 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -340,13 +340,13 @@ exports.start_backfilling_messages = function () { exports.initialize = function () { // get the initial message list function load_more(data) { - // If we received the initially selected message, select it on the client side, - // but not if the user has already selected another one during load. - // - // We fall back to the closest selected id, as the user may have removed - // a stream from the home before already + // If we haven't selected a message in the home view yet, and + // the home view isn't empty, we select the anchor message here. if (home_msg_list.selected_id() === -1 && !home_msg_list.empty()) { - home_msg_list.select_id(page_params.pointer, + // We fall back to the closest selected id, as the user + // may have removed a stream from the home view while we + // were loading data. + home_msg_list.select_id(data.anchor, {then_scroll: true, use_closest: true, target_scroll_offset: page_params.initial_offset}); }