2023-06-01 01:57:47 +02:00
|
|
|
import $ from "jquery";
|
2024-02-28 12:24:44 +01:00
|
|
|
import _ from "lodash";
|
2024-01-03 07:28:43 +01:00
|
|
|
import assert from "minimalistic-assert";
|
2023-06-01 01:57:47 +02:00
|
|
|
|
|
|
|
import * as hash_util from "./hash_util";
|
|
|
|
import * as message_lists from "./message_lists";
|
2024-01-03 07:28:43 +01:00
|
|
|
import type {MessageList} from "./message_lists";
|
2023-06-01 01:57:47 +02:00
|
|
|
import * as narrow_banner from "./narrow_banner";
|
|
|
|
import * as narrow_state from "./narrow_state";
|
2024-02-28 12:24:44 +01:00
|
|
|
import * as people from "./people";
|
2023-06-01 01:57:47 +02:00
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
function show_history_limit_notice(): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
$(".top-messages-logo").hide();
|
|
|
|
$(".history-limited-box").show();
|
|
|
|
narrow_banner.hide_empty_narrow_message();
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
function hide_history_limit_notice(): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
$(".top-messages-logo").show();
|
|
|
|
$(".history-limited-box").hide();
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
function hide_end_of_results_notice(): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
$(".all-messages-search-caution").hide();
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
function show_end_of_results_notice(): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
$(".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.
|
2024-01-03 07:28:43 +01:00
|
|
|
const narrow_filter = narrow_state.filter();
|
|
|
|
assert(narrow_filter !== undefined);
|
|
|
|
const terms = narrow_filter.terms();
|
2023-12-22 00:26:14 +01:00
|
|
|
const update_hash = hash_util.search_public_streams_notice_url(terms);
|
2023-06-01 01:57:47 +02:00
|
|
|
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
export function update_top_of_narrow_notices(msg_list: MessageList): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
// Assumes that the current state is all notices hidden (i.e. this
|
|
|
|
// will not hide a notice that should not be there)
|
2024-02-05 19:03:29 +01:00
|
|
|
if (message_lists.current === undefined || msg_list !== message_lists.current) {
|
2023-06-01 01:57:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-05 19:15:40 +01:00
|
|
|
if (msg_list.data.fetch_status.has_found_oldest()) {
|
2023-06-01 01:57:47 +02:00
|
|
|
const filter = narrow_state.filter();
|
|
|
|
// Potentially display the notice that lets users know
|
|
|
|
// that not all messages were searched. One could
|
2023-11-12 00:13:40 +01:00
|
|
|
// imagine including `filter.is_keyword_search()` in these
|
2023-06-01 01:57:47 +02:00
|
|
|
// conditions, but there's a very legitimate use case
|
|
|
|
// for moderation of searching for all messages sent
|
|
|
|
// by a potential spammer user.
|
|
|
|
if (
|
2024-03-05 19:15:40 +01:00
|
|
|
filter &&
|
|
|
|
!filter.is_in_home() &&
|
2023-06-01 01:57:47 +02:00
|
|
|
!filter.contains_only_private_messages() &&
|
|
|
|
!filter.includes_full_stream_history() &&
|
2024-02-28 12:24:44 +01:00
|
|
|
!filter.is_personal_filter() &&
|
|
|
|
!(
|
|
|
|
_.isEqual(filter._sorted_term_types, ["sender", "has-reaction"]) &&
|
|
|
|
filter.operands("sender")[0] === people.my_current_email()
|
|
|
|
)
|
2023-06-01 01:57:47 +02:00
|
|
|
) {
|
|
|
|
show_end_of_results_notice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg_list.data.fetch_status.history_limited()) {
|
|
|
|
show_history_limit_notice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 07:28:43 +01:00
|
|
|
export function hide_top_of_narrow_notices(): void {
|
2023-06-01 01:57:47 +02:00
|
|
|
hide_end_of_results_notice();
|
|
|
|
hide_history_limit_notice();
|
|
|
|
}
|