Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hashchange: Hide other views when showing a view in the same call.

Aman Agrawal22b50e231224
diff --git a/web/src/hashchange.ts b/web/src/hashchange.ts
index ffb84633f2d..20e5c4249d5 100644
--- a/web/src/hashchange.ts
+++ b/web/src/hashchange.ts
@@ -9,7 +9,6 @@ import * as hash_parser from "./hash_parser.ts";
import * as hash_util from "./hash_util.ts";
import {$t_html} from "./i18n.ts";
import * as inbox_ui from "./inbox_ui.ts";
-import * as inbox_util from "./inbox_util.ts";
import * as info_overlay from "./info_overlay.ts";
import * as message_fetch from "./message_fetch.ts";
import * as message_view from "./message_view.ts";
@@ -20,7 +19,6 @@ import {page_params} from "./page_params.ts";
import * as people from "./people.ts";
import * as popovers from "./popovers.ts";
import * as recent_view_ui from "./recent_view_ui.ts";
-import * as recent_view_util from "./recent_view_util.ts";
import * as scheduled_messages_overlay_ui from "./scheduled_messages_overlay_ui.ts";
import * as settings from "./settings.ts";
import * as settings_panel_menu from "./settings_panel_menu.ts";
@@ -53,22 +51,6 @@ declare global {
}
}
-function maybe_hide_recent_view(): boolean {
- if (recent_view_util.is_visible()) {
- recent_view_ui.hide();
- return true;
- }
- return false;
-}
-
-function maybe_hide_inbox(): boolean {
- if (inbox_util.is_visible()) {
- inbox_ui.hide();
- return true;
- }
- return false;
-}
-
function show_all_message_view(): void {
// Don't export this function outside of this module since
// `change_hash` is false here which means it is should only
@@ -143,7 +125,6 @@ function show_home_view(): void {
// rendered without a hash.
switch (user_settings.web_home_view) {
case "recent_topics": {
- maybe_hide_inbox();
recent_view_ui.show();
break;
}
@@ -153,7 +134,6 @@ function show_home_view(): void {
break;
}
case "inbox": {
- maybe_hide_recent_view();
inbox_ui.show();
break;
}
@@ -241,11 +221,9 @@ function do_hashchange_normal(from_reload: boolean, restore_selected_id: boolean
window.location.replace("#recent");
break;
case "#recent":
- maybe_hide_inbox();
recent_view_ui.show();
break;
case "#inbox":
- maybe_hide_recent_view();
inbox_ui.show();
break;
case "#all_messages":
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts
index 57ec3910858..9b0739256d7 100644
--- a/web/src/inbox_ui.ts
+++ b/web/src/inbox_ui.ts
@@ -161,6 +161,8 @@ const COLUMNS = {
let col_focus = COLUMNS.COLLAPSE_BUTTON;
let row_focus = 0;
+let hide_other_views_callback: (() => void) | undefined;
+
const ls_filter_key = "inbox-filters";
const ls_collapsed_containers_key = "inbox_collapsed_containers";
@@ -189,6 +191,8 @@ function save_data_to_ls(): void {
}
export function show(): void {
+ assert(hide_other_views_callback !== undefined);
+ hide_other_views_callback();
// Avoid setting col_focus to recipient when moving to inbox from other narrows.
// We prefer to focus entire row instead of stream name for inbox-header.
// Since inbox-row doesn't has a collapse button, focus on COLUMNS.COLLAPSE_BUTTON
@@ -231,6 +235,9 @@ export function show(): void {
}
export function hide(): void {
+ if (!is_visible()) {
+ return;
+ }
views_util.hide({
$view: $("#inbox-view"),
set_visible,
@@ -1502,7 +1509,8 @@ export function is_in_focus(): boolean {
return is_visible() && views_util.is_in_focus();
}
-export function initialize(): void {
+export function initialize({hide_other_views}: {hide_other_views: () => void}): void {
+ hide_other_views_callback = hide_other_views;
$(document).on(
"scroll",
_.throttle(() => {
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index cadb804276c..b858f4cb238 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -113,6 +113,11 @@ let is_waiting_for_revive_current_focus = true;
// Used to store the last scroll position of the recent view before
// it is hidden to avoid scroll jumping when it is shown again.
let last_scroll_offset: number | undefined;
+let hide_other_views_callback: (() => void) | undefined;
+
+export function set_hide_other_views(callback: () => void): void {
+ hide_other_views_callback = callback;
+}
export function set_initial_message_fetch_status(value: boolean): void {
is_initial_message_fetch_pending = value;
@@ -1405,6 +1410,8 @@ export function update_recent_view_rendered_time(): void {
}
export function show(): void {
+ assert(hide_other_views_callback !== undefined);
+ hide_other_views_callback();
// We remove event handler before hiding, so they need to
// be attached again, checking for topics_widget to be defined
// is a reliable solution to check if recent view was displayed earlier.
@@ -1457,6 +1464,9 @@ function filter_buttons(): JQuery {
}
export function hide(): void {
+ if (!recent_view_util.is_visible()) {
+ return;
+ }
// Since we have events attached to element (window) which are present in
// views others than recent view, it is important to clear events here.
topics_widget?.clear_event_handlers();
@@ -1839,12 +1849,15 @@ export function initialize({
on_mark_pm_as_read,
on_mark_topic_as_read,
maybe_load_older_messages,
+ hide_other_views,
}: {
on_click_participant: (avatar_element: Element, participant_user_id: number) => void;
on_mark_pm_as_read: (user_ids_string: string) => void;
on_mark_topic_as_read: (stream_id: number, topic: string) => void;
maybe_load_older_messages: (first_unread_unmuted_message_id: number) => void;
+ hide_other_views: () => void;
}): void {
+ hide_other_views_callback = hide_other_views;
load_filters();
$("body").on(
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index 2bc42d6e3cc..89f5c0ad1e2 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -515,8 +515,11 @@ export function initialize_everything(state_data) {
first_unread_message_id,
});
},
+ hide_other_views: inbox_ui.hide,
+ });
+ inbox_ui.initialize({
+ hide_other_views: recent_view_ui.hide,
});
- inbox_ui.initialize();
alert_words.initialize(state_data.alert_words);
saved_snippets.initialize(state_data.saved_snippets);
emojisets.initialize();
diff --git a/web/tests/recent_view.test.cjs b/web/tests/recent_view.test.cjs
index 59360dabe75..6a4b82edd38 100644
--- a/web/tests/recent_view.test.cjs
+++ b/web/tests/recent_view.test.cjs
@@ -208,6 +208,7 @@ const {buddy_list} = zrequire("buddy_list");
const activity_ui = zrequire("activity_ui");
const people = zrequire("people");
const rt = zrequire("recent_view_ui");
+rt.set_hide_other_views(noop);
const recent_view_util = zrequire("recent_view_util");
const rt_data = zrequire("recent_view_data");
const muted_users = zrequire("muted_users");