message_scroll: Extract module message_feed_top_notices.

This commit is contained in:
Tim Abbott
2023-05-31 16:57:47 -07:00
parent 2de9db9305
commit 713a64d415
7 changed files with 82 additions and 76 deletions

View File

@@ -110,6 +110,7 @@ EXEMPT_FILES = make_set(
"web/src/message_edit_history.js",
"web/src/message_events.js",
"web/src/message_feed_loading.ts",
"web/src/message_feed_top_notices.js",
"web/src/message_fetch.js",
"web/src/message_list.js",
"web/src/message_list_data.js",

View File

@@ -0,0 +1,72 @@
import $ from "jquery";
import * as hash_util from "./hash_util";
import * as message_lists from "./message_lists";
import * as narrow_banner from "./narrow_banner";
import * as narrow_state from "./narrow_state";
function show_history_limit_notice() {
$(".top-messages-logo").hide();
$(".history-limited-box").show();
narrow_banner.hide_empty_narrow_message();
}
function hide_history_limit_notice() {
$(".top-messages-logo").show();
$(".history-limited-box").hide();
}
function hide_end_of_results_notice() {
$(".all-messages-search-caution").hide();
}
function show_end_of_results_notice() {
$(".all-messages-search-caution").show();
// Set the link to point to this search with streams:public added.
// Note that element we adjust is not visible to spectators.
const operators = narrow_state.filter().operators();
const update_hash = hash_util.search_public_streams_notice_url(operators);
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
}
export function update_top_of_narrow_notices(msg_list) {
// Assumes that the current state is all notices hidden (i.e. this
// will not hide a notice that should not be there)
if (msg_list !== message_lists.current) {
return;
}
if (
msg_list.data.fetch_status.has_found_oldest() &&
message_lists.current !== message_lists.home
) {
const filter = narrow_state.filter();
if (filter === undefined && !narrow_state.is_message_feed_visible()) {
// user moved away from the narrow / filter to recent topics.
return;
}
// Potentially display the notice that lets users know
// that not all messages were searched. One could
// imagine including `filter.is_search()` in these
// conditions, but there's a very legitimate use case
// for moderation of searching for all messages sent
// by a potential spammer user.
if (
!filter.contains_only_private_messages() &&
!filter.includes_full_stream_history() &&
!filter.is_personal_filter()
) {
show_end_of_results_notice();
}
}
if (msg_list.data.fetch_status.history_limited()) {
show_history_limit_notice();
}
}
export function hide_top_of_narrow_notices() {
hide_end_of_results_notice();
hide_history_limit_notice();
}

View File

@@ -5,10 +5,10 @@ import * as channel from "./channel";
import {Filter} from "./filter";
import * as huddle_data from "./huddle_data";
import * as message_feed_loading from "./message_feed_loading";
import * as message_feed_top_notices from "./message_feed_top_notices";
import * as message_helper from "./message_helper";
import * as message_list from "./message_list";
import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll";
import * as message_util from "./message_util";
import * as narrow_banner from "./narrow_banner";
import {page_params} from "./page_params";
@@ -105,7 +105,7 @@ function get_messages_success(data, opts) {
history_limited: data.history_limited,
});
}
message_scroll.update_top_of_narrow_notices(opts.msg_list);
message_feed_top_notices.update_top_of_narrow_notices(opts.msg_list);
}
if (opts.num_after > 0) {

View File

@@ -2,11 +2,9 @@ import $ from "jquery";
import _ from "lodash";
import * as compose_banner from "./compose_banner";
import * as hash_util from "./hash_util";
import * as message_fetch from "./message_fetch";
import * as message_lists from "./message_lists";
import * as message_viewport from "./message_viewport";
import * as narrow_banner from "./narrow_banner";
import * as narrow_state from "./narrow_state";
import * as recent_topics_util from "./recent_topics_util";
import * as unread from "./unread";
@@ -31,72 +29,6 @@ export function mark_keyboard_triggered_current_scroll() {
keyboard_triggered_current_scroll = true;
}
export function show_history_limit_notice() {
$(".top-messages-logo").hide();
$(".history-limited-box").show();
narrow_banner.hide_empty_narrow_message();
}
export function hide_history_limit_notice() {
$(".top-messages-logo").show();
$(".history-limited-box").hide();
}
export function hide_end_of_results_notice() {
$(".all-messages-search-caution").hide();
}
export function show_end_of_results_notice() {
$(".all-messages-search-caution").show();
// Set the link to point to this search with streams:public added.
// Note that element we adjust is not visible to spectators.
const operators = narrow_state.filter().operators();
const update_hash = hash_util.search_public_streams_notice_url(operators);
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
}
export function update_top_of_narrow_notices(msg_list) {
// Assumes that the current state is all notices hidden (i.e. this
// will not hide a notice that should not be there)
if (msg_list !== message_lists.current) {
return;
}
if (
msg_list.data.fetch_status.has_found_oldest() &&
message_lists.current !== message_lists.home
) {
const filter = narrow_state.filter();
if (filter === undefined && !narrow_state.is_message_feed_visible()) {
// user moved away from the narrow / filter to recent topics.
return;
}
// Potentially display the notice that lets users know
// that not all messages were searched. One could
// imagine including `filter.is_search()` in these
// conditions, but there's a very legitimate use case
// for moderation of searching for all messages sent
// by a potential spammer user.
if (
!filter.contains_only_private_messages() &&
!filter.includes_full_stream_history() &&
!filter.is_personal_filter()
) {
show_end_of_results_notice();
}
}
if (msg_list.data.fetch_status.history_limited()) {
show_history_limit_notice();
}
}
export function hide_top_of_narrow_notices() {
hide_end_of_results_notice();
hide_history_limit_notice();
}
let hide_scroll_to_bottom_timer;
export function hide_scroll_to_bottom() {
const $show_scroll_to_bottom_button = $("#scroll-to-bottom-button-container");

View File

@@ -17,6 +17,7 @@ import * as hashchange from "./hashchange";
import {$t} from "./i18n";
import * as message_edit from "./message_edit";
import * as message_feed_loading from "./message_feed_loading";
import * as message_feed_top_notices from "./message_feed_top_notices";
import * as message_fetch from "./message_fetch";
import * as message_helper from "./message_helper";
import * as message_list from "./message_list";
@@ -131,7 +132,7 @@ export function reset_ui_state() {
// Resets the state of various visual UI elements that are
// a function of the current narrow.
narrow_banner.hide_empty_narrow_message();
message_scroll.hide_top_of_narrow_notices();
message_feed_top_notices.hide_top_of_narrow_notices();
message_feed_loading.hide_indicators();
unread_ui.reset_unread_banner();
}
@@ -1008,7 +1009,7 @@ function handle_post_narrow_deactivate_processes() {
typing_events.render_notifications_for_narrow();
message_view_header.initialize();
update_narrow_title(narrow_state.filter());
message_scroll.update_top_of_narrow_notices(message_lists.home);
message_feed_top_notices.update_top_of_narrow_notices(message_lists.home);
}
export function deactivate(coming_from_recent_topics = false) {

View File

@@ -40,7 +40,7 @@ const message_util = mock_esm("../src/message_util");
const stream_list = mock_esm("../src/stream_list", {
maybe_scroll_narrow_into_view() {},
});
mock_esm("../src/message_scroll", {
mock_esm("../src/message_feed_top_notices", {
update_top_of_narrow_notices() {},
});
mock_esm("../src/message_feed_loading", {

View File

@@ -24,7 +24,7 @@ const message_lists = mock_esm("../src/message_lists", {
message_lists.current = msg_list;
},
});
const message_scroll = mock_esm("../src/message_scroll");
const message_feed_top_notices = mock_esm("../src/message_feed_top_notices");
const message_feed_loading = mock_esm("../src/message_feed_loading");
const message_view_header = mock_esm("../src/message_view_header");
const notifications = mock_esm("../src/notifications");
@@ -86,7 +86,7 @@ function test_helper() {
stub(hashchange, "save_narrow");
stub(message_feed_loading, "hide_indicators");
stub(message_feed_loading, "show_loading_older");
stub(message_scroll, "hide_top_of_narrow_notices");
stub(message_feed_top_notices, "hide_top_of_narrow_notices");
stub(notifications, "redraw_title");
stub(search, "update_button_visibility");
stub(stream_list, "handle_narrow_activated");
@@ -185,7 +185,7 @@ run_test("basics", () => {
assert.equal(narrow_state.narrowed_to_pms(), false);
helper.assert_events([
[message_scroll, "hide_top_of_narrow_notices"],
[message_feed_top_notices, "hide_top_of_narrow_notices"],
[message_feed_loading, "hide_indicators"],
[compose_banner, "clear_message_sent_banners"],
[notifications, "redraw_title"],