recent_topics: Save offset when navigating from narrow or "all".

This is partially a prep commit to correctly saving/restoring the
position of the blue message select box when using browser
back/forward navigation, and partially a bug fix that ensures that
switching from "all_messages" to "recent_topics" preserves one's
position in "all_messages".
Note that this is with regards to saving the visual position of the
selected message, not about saving "which message was selected".
This commit is contained in:
YashRE42
2021-11-28 13:55:16 +05:30
committed by Tim Abbott
parent 9d460a513e
commit c4bb181056
3 changed files with 12 additions and 2 deletions

View File

@@ -97,9 +97,10 @@ mock_esm("../../static/js/muted_topics", {
return false;
},
});
mock_esm("../../static/js/narrow", {
const narrow = mock_esm("../../static/js/narrow", {
set_narrow_title: noop,
hide_mark_as_read_turned_off_banner: noop,
has_shown_message_list_view: true,
});
mock_esm("../../static/js/recent_senders", {
get_topic_recent_senders: () => [1, 2],
@@ -338,7 +339,9 @@ function test(label, f) {
});
}
test("test_recent_topics_show", ({mock_template}) => {
test("test_recent_topics_show", ({mock_template, override}) => {
override(narrow, "save_pre_narrow_offset_for_reload", () => {});
// Note: unread count and urls are fake,
// since they are generated in external libraries
// and are not to be tested here.

View File

@@ -114,6 +114,7 @@ export function save_pre_narrow_offset_for_reload() {
}
export let narrow_title = "home";
export let has_shown_message_list_view = false;
export function set_narrow_title(title) {
narrow_title = title;
@@ -292,6 +293,7 @@ export function activate(raw_operators, opts) {
// populating the new narrow, so we update our narrow_state.
// From here on down, any calls to the narrow_state API will
// reflect the upcoming narrow.
has_shown_message_list_view = true;
narrow_state.set_current_filter(filter);
const excludes_muted_topics = narrow_state.excludes_muted_topics();
@@ -882,6 +884,7 @@ export function deactivate(coming_from_recent_topics = false) {
}
narrow_state.reset_current_filter();
has_shown_message_list_view = true;
$("body").removeClass("narrowed_view");
$("#zfilt").removeClass("focused_table");

View File

@@ -622,6 +622,10 @@ export function complete_rerender() {
}
export function show() {
if (narrow.has_shown_message_list_view) {
narrow.save_pre_narrow_offset_for_reload();
}
if (is_visible()) {
// If we're already visible, E.g. because the user hit Esc
// while already in the recent topics view, do nothing.