Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
import {$} from "jquery";
import assert from "minimalistic-assert";
import * as hash_util from "./hash_util.ts";
import * as message_feed_loading from "./message_feed_loading.ts";
import type {MessageList} from "./message_list.ts";
import * as message_lists from "./message_lists.ts";
import * as narrow_state from "./narrow_state.ts";
import {page_params} from "./page_params.ts";
function show_history_limit_notice(): void {
$(".history-limited-box").show();
// The history-limit notice and the empty-narrow banner are mutually
// exclusive top-of-feed states; clear the latter when showing this.
// We do this inline rather than calling narrow_banner, which imports
// this module, to avoid an import cycle.
$(".empty_feed_notice_main").empty();
}
function hide_history_limit_notice(): void {
$(".history-limited-box").hide();
}
function hide_end_of_results_notice(): void {
$(".all-messages-search-caution").hide();
$(".combined-feed-notice").hide();
}
function show_end_of_results_notice(): void {
// Both end-of-results notices are hidden for spectators.
if (page_params.is_spectator) {
return;
}
const narrow_filter = narrow_state.filter();
assert(narrow_filter !== undefined);
if (narrow_filter.is_in_home()) {
$(".combined-feed-notice").show();
return;
}
const terms = narrow_filter.terms();
// Set the link to point to this search with streams:public added.
// Note that element we adjust is not visible to spectators.
const update_hash = hash_util.search_public_streams_notice_url(terms);
$(".all-messages-search-caution").show();
$(".all-messages-search-caution .search-shared-history").attr("data-url", update_hash);
}
export function update_top_of_narrow_notices(msg_list: MessageList): void {
// Assumes that the current state is all notices hidden (i.e. this
// will not hide a notice that should not be there)
if (message_lists.current === undefined || msg_list !== message_lists.current) {
return;
}
message_feed_loading.run_when_top_of_feed_indicator_hidden(() => {
if (msg_list !== message_lists.current) {
return;
}
if (msg_list.data.fetch_status.has_found_oldest()) {
const filter = narrow_state.filter();
// Potentially display the notice that lets users know
// that not all messages were searched. One could
// imagine including `filter.is_keyword_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?.may_have_incomplete_message_history(false)) {
show_end_of_results_notice();
}
}
if (msg_list.data.fetch_status.history_limited()) {
show_history_limit_notice();
}
});
}
export function hide_top_of_narrow_notices(): void {
// A notice waiting for the loading indicator to go away must not
// show up after this; the empty-narrow banner, for one, hides the
// notices so that it can take their place.
message_feed_loading.cancel_run_when_top_of_feed_indicator_hidden();
hide_end_of_results_notice();
hide_history_limit_notice();
}