message_list_view: Move "is_search_view" to narrow_state.

This helper function is only ever used to describe the current view,
so it might as well be in the module for such views.

Also added the test coverage for "is_search_view".
This commit is contained in:
bedo
2024-11-13 14:56:42 +02:00
committed by Tim Abbott
parent d4f43839a2
commit bf05694e59
3 changed files with 13 additions and 9 deletions

View File

@@ -428,14 +428,6 @@ function maybe_restore_focus_to_message_edit_form(): void {
}, 0); }, 0);
} }
function is_search_view(): boolean {
const current_filter = narrow_state.filter();
if (current_filter && !current_filter.supports_collapsing_recipients()) {
return true;
}
return false;
}
type SubscriptionMarkers = { type SubscriptionMarkers = {
bookend_top: boolean; bookend_top: boolean;
stream_name: string; stream_name: string;
@@ -456,7 +448,7 @@ function populate_group_from_message(
// Each searched message is a self-contained result, // Each searched message is a self-contained result,
// so we always display date in the recipient bar for those messages. // so we always display date in the recipient bar for those messages.
const always_display_date = is_search_view(); const always_display_date = narrow_state.is_search_view();
if (is_stream) { if (is_stream) {
assert(message.type === "stream"); assert(message.type === "stream");
// stream messages have string display_recipient // stream messages have string display_recipient

View File

@@ -25,6 +25,13 @@ export function search_terms(current_filter: Filter | undefined = filter()): Nar
return current_filter.terms(); return current_filter.terms();
} }
export function is_search_view(current_filter: Filter | undefined = filter()): boolean {
if (current_filter && !current_filter.supports_collapsing_recipients()) {
return true;
}
return false;
}
export function is_message_feed_visible(): boolean { export function is_message_feed_visible(): boolean {
// It's important that `message_lists.current` is the // It's important that `message_lists.current` is the
// source of truth for this since during the initial app load, // source of truth for this since during the initial app load,

View File

@@ -87,6 +87,7 @@ test("narrowed", () => {
assert.ok(!narrow_state.narrowed_by_pm_reply()); assert.ok(!narrow_state.narrowed_by_pm_reply());
assert.ok(!narrow_state.narrowed_by_topic_reply()); assert.ok(!narrow_state.narrowed_by_topic_reply());
assert.ok(narrow_state.narrowed_by_stream_reply()); assert.ok(narrow_state.narrowed_by_stream_reply());
assert.ok(!narrow_state.is_search_view());
set_filter([["dm", "steve@zulip.com"]]); set_filter([["dm", "steve@zulip.com"]]);
assert.ok(narrow_state.narrowed_to_pms()); assert.ok(narrow_state.narrowed_to_pms());
@@ -94,6 +95,7 @@ test("narrowed", () => {
assert.ok(narrow_state.narrowed_by_pm_reply()); assert.ok(narrow_state.narrowed_by_pm_reply());
assert.ok(!narrow_state.narrowed_by_topic_reply()); assert.ok(!narrow_state.narrowed_by_topic_reply());
assert.ok(!narrow_state.narrowed_by_stream_reply()); assert.ok(!narrow_state.narrowed_by_stream_reply());
assert.ok(!narrow_state.is_search_view());
set_filter([ set_filter([
["stream", foo_stream_id.toString()], ["stream", foo_stream_id.toString()],
@@ -104,6 +106,7 @@ test("narrowed", () => {
assert.ok(!narrow_state.narrowed_by_pm_reply()); assert.ok(!narrow_state.narrowed_by_pm_reply());
assert.ok(narrow_state.narrowed_by_topic_reply()); assert.ok(narrow_state.narrowed_by_topic_reply());
assert.ok(!narrow_state.narrowed_by_stream_reply()); assert.ok(!narrow_state.narrowed_by_stream_reply());
assert.ok(!narrow_state.is_search_view());
set_filter([["search", "grail"]]); set_filter([["search", "grail"]]);
assert.ok(!narrow_state.narrowed_to_pms()); assert.ok(!narrow_state.narrowed_to_pms());
@@ -111,6 +114,7 @@ test("narrowed", () => {
assert.ok(!narrow_state.narrowed_by_pm_reply()); assert.ok(!narrow_state.narrowed_by_pm_reply());
assert.ok(!narrow_state.narrowed_by_topic_reply()); assert.ok(!narrow_state.narrowed_by_topic_reply());
assert.ok(!narrow_state.narrowed_by_stream_reply()); assert.ok(!narrow_state.narrowed_by_stream_reply());
assert.ok(narrow_state.is_search_view());
set_filter([["is", "starred"]]); set_filter([["is", "starred"]]);
assert.ok(!narrow_state.narrowed_to_pms()); assert.ok(!narrow_state.narrowed_to_pms());
@@ -118,6 +122,7 @@ test("narrowed", () => {
assert.ok(!narrow_state.narrowed_by_pm_reply()); assert.ok(!narrow_state.narrowed_by_pm_reply());
assert.ok(!narrow_state.narrowed_by_topic_reply()); assert.ok(!narrow_state.narrowed_by_topic_reply());
assert.ok(!narrow_state.narrowed_by_stream_reply()); assert.ok(!narrow_state.narrowed_by_stream_reply());
assert.ok(narrow_state.is_search_view());
}); });
test("terms", () => { test("terms", () => {