2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2024-11-12 03:59:37 +01:00
|
|
|
import * as about_zulip from "./about_zulip.ts";
|
|
|
|
import * as admin from "./admin.js";
|
|
|
|
import * as blueslip from "./blueslip.ts";
|
|
|
|
import * as browser_history from "./browser_history.ts";
|
|
|
|
import * as drafts_overlay_ui from "./drafts_overlay_ui.js";
|
|
|
|
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";
|
|
|
|
import * as message_viewport from "./message_viewport.ts";
|
|
|
|
import * as modals from "./modals.ts";
|
|
|
|
import * as overlays from "./overlays.ts";
|
|
|
|
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.js";
|
2024-11-18 02:24:32 +01:00
|
|
|
import * as settings_panel_menu from "./settings_panel_menu.ts";
|
2024-11-12 03:59:37 +01:00
|
|
|
import * as settings_toggle from "./settings_toggle.js";
|
|
|
|
import * as sidebar_ui from "./sidebar_ui.ts";
|
|
|
|
import * as spectators from "./spectators.ts";
|
|
|
|
import {current_user} from "./state_data.ts";
|
|
|
|
import * as stream_settings_ui from "./stream_settings_ui.js";
|
|
|
|
import * as ui_report from "./ui_report.ts";
|
|
|
|
import * as user_group_edit from "./user_group_edit.js";
|
|
|
|
import * as user_profile from "./user_profile.ts";
|
|
|
|
import {user_settings} from "./user_settings.ts";
|
2021-02-10 17:00:58 +01:00
|
|
|
|
2017-11-16 19:51:44 +01:00
|
|
|
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
|
2018-12-04 23:01:41 +01:00
|
|
|
// or locally: docs/subsystems/hashchange-system.md
|
2012-12-07 20:52:39 +01:00
|
|
|
|
2023-09-06 23:51:45 +02:00
|
|
|
function maybe_hide_recent_view() {
|
2023-09-06 23:21:13 +02:00
|
|
|
if (recent_view_util.is_visible()) {
|
2023-09-06 23:14:37 +02:00
|
|
|
recent_view_ui.hide();
|
2020-07-05 12:19:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-09 07:23:30 +02:00
|
|
|
function maybe_hide_inbox() {
|
|
|
|
if (inbox_util.is_visible()) {
|
|
|
|
inbox_ui.hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-15 17:17:31 +01:00
|
|
|
function show_all_message_view() {
|
2024-02-26 09:24:34 +01:00
|
|
|
// Don't export this function outside of this module since
|
|
|
|
// `change_hash` is false here which means it is should only
|
|
|
|
// be called after hash is updated in the URL.
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show([{operator: "in", operand: "home"}], {
|
2024-02-26 09:24:34 +01:00
|
|
|
trigger: "hashchange",
|
|
|
|
change_hash: false,
|
2024-06-08 00:39:47 +02:00
|
|
|
then_select_id: window.history.state?.narrow_pointer,
|
|
|
|
then_select_offset: window.history.state?.narrow_offset,
|
2024-02-26 09:24:34 +01:00
|
|
|
});
|
2012-12-12 19:00:50 +01:00
|
|
|
}
|
|
|
|
|
2024-02-24 17:54:59 +01:00
|
|
|
function is_somebody_else_profile_open() {
|
|
|
|
return (
|
|
|
|
user_profile.get_user_id_if_user_profile_modal_open() !== undefined &&
|
|
|
|
user_profile.get_user_id_if_user_profile_modal_open() !== people.my_current_user_id()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-30 11:28:49 +02:00
|
|
|
function handle_invalid_users_section_url(user_settings_tab) {
|
|
|
|
const valid_user_settings_tab_values = new Set(["active", "deactivated", "invitations"]);
|
|
|
|
if (!valid_user_settings_tab_values.has(user_settings_tab)) {
|
|
|
|
const valid_users_section_url = "#organization/users/active";
|
|
|
|
browser_history.update(valid_users_section_url);
|
|
|
|
return "active";
|
|
|
|
}
|
|
|
|
return user_settings_tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_user_settings_tab(section) {
|
|
|
|
if (section === "users") {
|
|
|
|
const current_user_settings_tab = hash_parser.get_current_nth_hash_section(2);
|
|
|
|
return handle_invalid_users_section_url(current_user_settings_tab);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2024-05-03 06:10:45 +02:00
|
|
|
export function set_hash_to_home_view(triggered_by_escape_key = false) {
|
2024-09-19 19:55:03 +02:00
|
|
|
if (browser_history.is_current_hash_home_view()) {
|
2024-05-16 06:07:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-19 19:55:03 +02:00
|
|
|
const hash_before_current = browser_history.old_hash();
|
|
|
|
if (
|
|
|
|
triggered_by_escape_key &&
|
|
|
|
browser_history.get_home_view_hash() === "#feed" &&
|
|
|
|
(hash_before_current === "" || hash_before_current === "#feed")
|
|
|
|
) {
|
|
|
|
// If the previous view was the user's Combined Feed home
|
|
|
|
// view, and this change was triggered by escape keypress,
|
|
|
|
// then we simulate the back button in order to reuse
|
|
|
|
// existing code for restoring the user's scroll position.
|
|
|
|
window.history.back();
|
|
|
|
return;
|
2024-04-23 20:58:34 +02:00
|
|
|
}
|
|
|
|
|
2024-09-19 19:55:03 +02:00
|
|
|
// We want to set URL with no hash here. It is not possible
|
|
|
|
// to do so with `window.location.hash` since it will set an empty
|
|
|
|
// hash. So, we use `pushState` which simply updates the current URL
|
|
|
|
// but doesn't trigger `hashchange`. So, we trigger hashchange directly
|
|
|
|
// here to let it handle the whole rendering process for us.
|
|
|
|
browser_history.set_hash("");
|
|
|
|
hashchanged(false);
|
2021-05-12 23:38:55 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 09:02:57 +02:00
|
|
|
function show_home_view() {
|
2021-05-12 23:38:55 +02:00
|
|
|
// This function should only be called from the hashchange
|
|
|
|
// handlers, as it does not set the hash to "".
|
|
|
|
//
|
2023-10-23 09:02:57 +02:00
|
|
|
// We only allow the primary recommended options for home views
|
2023-09-18 17:36:15 +02:00
|
|
|
// rendered without a hash.
|
2023-10-23 09:02:57 +02:00
|
|
|
switch (user_settings.web_home_view) {
|
2023-09-18 17:36:15 +02:00
|
|
|
case "recent_topics": {
|
2023-11-16 01:47:35 +01:00
|
|
|
maybe_hide_inbox();
|
2023-09-18 17:36:15 +02:00
|
|
|
recent_view_ui.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "all_messages": {
|
2023-11-16 01:47:35 +01:00
|
|
|
// Hides inbox/recent views internally if open.
|
2023-09-18 17:36:15 +02:00
|
|
|
show_all_message_view();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "inbox": {
|
2023-11-16 01:47:35 +01:00
|
|
|
maybe_hide_recent_view();
|
2023-09-18 17:36:15 +02:00
|
|
|
inbox_ui.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// NOTE: Setting a hash which is not rendered on
|
|
|
|
// empty hash (like a stream narrow) will
|
|
|
|
// introduce a bug that user will not be able to
|
|
|
|
// go back in browser history. See
|
2024-06-06 21:48:31 +02:00
|
|
|
// https://chat.zulip.org/#narrow/channel/9-issues/topic/Browser.20back.20button.20on.20RT
|
2023-09-18 17:36:15 +02:00
|
|
|
// for detailed description of the issue.
|
2023-10-23 09:02:57 +02:00
|
|
|
window.location.hash = user_settings.web_home_view;
|
2023-09-18 17:36:15 +02:00
|
|
|
}
|
2021-03-15 15:01:19 +01:00
|
|
|
}
|
2021-03-10 13:56:10 +01:00
|
|
|
}
|
|
|
|
|
2012-12-21 01:04:27 +01:00
|
|
|
// Returns true if this function performed a narrow
|
2024-10-05 07:16:48 +02:00
|
|
|
function do_hashchange_normal(from_reload, restore_selected_id) {
|
2018-12-04 19:08:26 +01:00
|
|
|
message_viewport.stop_auto_scrolling();
|
2013-04-23 21:59:49 +02:00
|
|
|
|
2013-03-20 00:22:51 +01:00
|
|
|
// NB: In Firefox, window.location.hash is URI-decoded.
|
|
|
|
// Even if the URL bar says #%41%42%43%44, the value here will
|
|
|
|
// be #ABCD.
|
2019-11-02 00:06:25 +01:00
|
|
|
const hash = window.location.hash.split("/");
|
2021-06-28 05:08:55 +02:00
|
|
|
|
2012-12-19 21:19:29 +01:00
|
|
|
switch (hash[0]) {
|
2020-07-15 02:14:03 +02:00
|
|
|
case "#narrow": {
|
2023-12-22 00:26:14 +01:00
|
|
|
let terms;
|
2022-02-25 19:27:25 +01:00
|
|
|
try {
|
|
|
|
// TODO: Show possible valid URLs to the user.
|
2023-12-22 00:26:14 +01:00
|
|
|
terms = hash_util.parse_narrow(hash);
|
2022-02-25 19:27:25 +01:00
|
|
|
} catch {
|
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Invalid URL"}),
|
|
|
|
undefined,
|
|
|
|
$("#home-error"),
|
|
|
|
2000,
|
|
|
|
);
|
|
|
|
}
|
2023-12-22 00:26:14 +01:00
|
|
|
if (terms === undefined) {
|
2021-03-15 15:01:19 +01:00
|
|
|
// If the narrow URL didn't parse,
|
2023-10-23 09:02:57 +02:00
|
|
|
// send them to web_home_view.
|
2021-03-15 15:01:19 +01:00
|
|
|
// We cannot clear hash here since
|
|
|
|
// it will block user from going back
|
|
|
|
// in browser history.
|
2023-10-23 09:02:57 +02:00
|
|
|
show_home_view();
|
2020-07-15 02:14:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const narrow_opts = {
|
2020-07-16 23:29:01 +02:00
|
|
|
change_hash: false, // already set
|
2020-07-15 02:14:03 +02:00
|
|
|
trigger: "hash change",
|
2024-04-30 16:28:32 +02:00
|
|
|
show_more_topics: false,
|
2020-07-15 02:14:03 +02:00
|
|
|
};
|
|
|
|
if (from_reload) {
|
|
|
|
blueslip.debug("We are narrowing as part of a reload.");
|
2023-12-30 23:55:57 +01:00
|
|
|
if (message_fetch.initial_narrow_pointer !== undefined) {
|
|
|
|
narrow_opts.then_select_id = message_fetch.initial_narrow_pointer;
|
|
|
|
narrow_opts.then_select_offset = message_fetch.initial_narrow_offset;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2017-06-15 18:30:40 +02:00
|
|
|
}
|
2023-08-08 23:59:25 +02:00
|
|
|
|
2024-06-08 00:39:47 +02:00
|
|
|
const data_for_hash = window.history.state;
|
2024-10-05 07:16:48 +02:00
|
|
|
if (restore_selected_id && data_for_hash) {
|
2024-04-30 16:28:32 +02:00
|
|
|
narrow_opts.then_select_id = data_for_hash.narrow_pointer;
|
|
|
|
narrow_opts.then_select_offset = data_for_hash.narrow_offset;
|
|
|
|
narrow_opts.show_more_topics = data_for_hash.show_more_topics ?? false;
|
2023-08-08 23:59:25 +02:00
|
|
|
}
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show(terms, narrow_opts);
|
2020-07-15 02:14:03 +02:00
|
|
|
return true;
|
2014-02-12 20:03:05 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
case "":
|
|
|
|
case "#":
|
2023-10-23 09:02:57 +02:00
|
|
|
show_home_view();
|
2021-03-10 13:56:10 +01:00
|
|
|
break;
|
2020-07-05 12:19:09 +02:00
|
|
|
case "#recent_topics":
|
2022-10-24 12:18:09 +02:00
|
|
|
// The URL for Recent Conversations was changed from
|
|
|
|
// #recent_topics to #recent in 2022. Because pre-change
|
|
|
|
// Welcome Bot messages included links to this URL, we
|
|
|
|
// need to support the "#recent_topics" hash as an alias
|
|
|
|
// for #recent permanently. We show the view and then
|
|
|
|
// replace the current URL hash in a way designed to hide
|
|
|
|
// this detail in the browser's forward/back session history.
|
2023-09-06 23:14:37 +02:00
|
|
|
recent_view_ui.show();
|
2022-10-24 12:18:09 +02:00
|
|
|
window.location.replace("#recent");
|
|
|
|
break;
|
|
|
|
case "#recent":
|
2023-08-09 07:23:30 +02:00
|
|
|
maybe_hide_inbox();
|
2023-09-06 23:14:37 +02:00
|
|
|
recent_view_ui.show();
|
2020-07-05 12:19:09 +02:00
|
|
|
break;
|
2023-08-09 07:23:30 +02:00
|
|
|
case "#inbox":
|
|
|
|
maybe_hide_recent_view();
|
|
|
|
inbox_ui.show();
|
|
|
|
break;
|
2020-09-20 10:14:24 +02:00
|
|
|
case "#all_messages":
|
2024-04-23 20:58:34 +02:00
|
|
|
// "#all_messages" was renamed to "#feed" in 2024. Unlike
|
|
|
|
// the recent hash rename, there are likely few links that
|
|
|
|
// would break if this compatibility code was removed, but
|
|
|
|
// there's little cost to keeping it.
|
|
|
|
show_all_message_view();
|
|
|
|
window.location.replace("#feed");
|
|
|
|
break;
|
|
|
|
case "#feed":
|
2021-03-15 17:17:31 +01:00
|
|
|
show_all_message_view();
|
2020-09-20 10:14:24 +02:00
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
case "#keyboard-shortcuts":
|
|
|
|
case "#message-formatting":
|
|
|
|
case "#search-operators":
|
|
|
|
case "#drafts":
|
|
|
|
case "#invite":
|
2024-04-30 13:30:24 +02:00
|
|
|
case "#channels":
|
2020-07-15 02:14:03 +02:00
|
|
|
case "#streams":
|
|
|
|
case "#organization":
|
|
|
|
case "#settings":
|
2021-02-09 11:16:52 +01:00
|
|
|
case "#about-zulip":
|
2023-04-14 21:35:56 +02:00
|
|
|
case "#scheduled":
|
2020-07-15 02:14:03 +02:00
|
|
|
blueslip.error("overlay logic skipped for: " + hash);
|
|
|
|
break;
|
2021-06-19 06:58:15 +02:00
|
|
|
default:
|
2023-10-23 09:02:57 +02:00
|
|
|
show_home_view();
|
2012-12-07 20:52:39 +01:00
|
|
|
}
|
2012-12-21 01:04:27 +01:00
|
|
|
return false;
|
2012-12-07 20:52:39 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 19:00:01 +01:00
|
|
|
function do_hashchange_overlay(old_hash) {
|
2020-11-04 09:10:18 +01:00
|
|
|
if (old_hash === undefined) {
|
2021-05-12 17:18:08 +02:00
|
|
|
// The user opened the app with an overlay hash; we need to
|
2023-10-23 09:02:57 +02:00
|
|
|
// show the user's home view behind it.
|
|
|
|
show_home_view();
|
2020-11-04 09:10:18 +01:00
|
|
|
}
|
2024-04-30 13:30:24 +02:00
|
|
|
let base = hash_parser.get_current_hash_category();
|
2023-10-01 22:03:44 +02:00
|
|
|
const old_base = hash_parser.get_hash_category(old_hash);
|
|
|
|
let section = hash_parser.get_current_hash_section();
|
2018-12-01 01:08:48 +01:00
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
if (base === "groups" && current_user.is_guest) {
|
2022-08-19 16:57:43 +02:00
|
|
|
// The #groups settings page is unfinished, and disabled in production.
|
2023-10-23 09:02:57 +02:00
|
|
|
show_home_view();
|
2022-08-19 16:57:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-01 22:03:44 +02:00
|
|
|
const coming_from_overlay = hash_parser.is_overlay_hash(old_hash);
|
2023-06-29 15:28:38 +02:00
|
|
|
if (section === "display-settings") {
|
|
|
|
// Since display-settings was deprecated and replaced with preferences
|
|
|
|
// #settings/display-settings is being redirected to #settings/preferences.
|
|
|
|
section = "preferences";
|
|
|
|
}
|
2024-06-12 10:59:52 +02:00
|
|
|
if (section === "user-list-admin") {
|
|
|
|
// #settings/user-list-admin is being redirected to #settings/users after it was renamed.
|
|
|
|
section = "users";
|
|
|
|
}
|
2022-02-07 12:01:58 +01:00
|
|
|
if ((base === "settings" || base === "organization") && !section) {
|
|
|
|
let settings_panel_object = settings_panel_menu.normal_settings;
|
|
|
|
if (base === "organization") {
|
|
|
|
settings_panel_object = settings_panel_menu.org_settings;
|
|
|
|
}
|
2024-06-08 00:39:47 +02:00
|
|
|
window.history.replaceState(
|
2022-02-07 12:01:58 +01:00
|
|
|
null,
|
|
|
|
"",
|
2024-05-30 11:16:13 +02:00
|
|
|
browser_history.get_full_url(base + "/" + settings_panel_object.current_tab),
|
2022-02-07 12:01:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-30 13:30:24 +02:00
|
|
|
// In 2024, stream was renamed to channel in the Zulip API and UI.
|
|
|
|
// Because pre-change Welcome Bot and Notification Bot messages
|
|
|
|
// included links to "/#streams/all" and "/#streams/new", we'll
|
|
|
|
// need to support "streams" as an overlay hash as an alias for
|
|
|
|
// "channels" permanently.
|
|
|
|
if (base === "streams" || base === "channels") {
|
|
|
|
const valid_hash = hash_util.validate_channels_settings_hash(window.location.hash);
|
|
|
|
// Here valid_hash will always return "channels" as the base.
|
|
|
|
// So, if we update the history because the valid hash does
|
|
|
|
// not match the window.location.hash, then we also reset the
|
|
|
|
// base string we're tracking for the hash.
|
2024-02-01 10:26:22 +01:00
|
|
|
if (valid_hash !== window.location.hash) {
|
2024-06-08 00:39:47 +02:00
|
|
|
window.history.replaceState(null, "", browser_history.get_full_url(valid_hash));
|
2024-02-01 10:26:22 +01:00
|
|
|
section = hash_parser.get_current_hash_section();
|
2024-04-30 13:30:24 +02:00
|
|
|
base = hash_parser.get_current_hash_category();
|
2024-02-01 10:26:22 +01:00
|
|
|
}
|
2022-02-08 12:07:40 +01:00
|
|
|
}
|
|
|
|
|
2024-02-09 14:34:09 +01:00
|
|
|
if (base === "groups") {
|
|
|
|
const valid_hash = hash_util.validate_group_settings_hash(window.location.hash);
|
|
|
|
if (valid_hash !== window.location.hash) {
|
2024-06-08 00:39:47 +02:00
|
|
|
window.history.replaceState(null, "", browser_history.get_full_url(valid_hash));
|
2024-02-09 14:34:09 +01:00
|
|
|
section = hash_parser.get_current_hash_section();
|
|
|
|
}
|
2024-01-18 11:15:53 +01:00
|
|
|
}
|
|
|
|
|
2024-04-30 13:30:24 +02:00
|
|
|
// Start by handling the specific case of going from
|
|
|
|
// something like "#channels/all" to "#channels/subscribed".
|
2018-12-01 18:54:41 +01:00
|
|
|
//
|
|
|
|
// In most situations we skip by this logic and load
|
|
|
|
// the new overlay.
|
2020-12-22 11:26:39 +01:00
|
|
|
if (coming_from_overlay && base === old_base) {
|
2024-04-30 13:30:24 +02:00
|
|
|
if (base === "channels") {
|
|
|
|
// e.g. #channels/29/social/subscribers
|
2024-01-26 23:17:49 +01:00
|
|
|
const right_side_tab = hash_parser.get_current_nth_hash_section(3);
|
2024-02-24 17:55:39 +01:00
|
|
|
stream_settings_ui.change_state(section, undefined, right_side_tab);
|
2020-12-22 11:26:39 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-12-06 22:28:52 +01:00
|
|
|
|
2022-08-19 16:57:43 +02:00
|
|
|
if (base === "groups") {
|
2024-01-30 15:26:56 +01:00
|
|
|
const right_side_tab = hash_parser.get_current_nth_hash_section(3);
|
2024-02-24 17:54:59 +01:00
|
|
|
user_group_edit.change_state(section, undefined, right_side_tab);
|
2022-08-19 16:57:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 11:26:39 +01:00
|
|
|
if (base === "settings") {
|
|
|
|
if (!section) {
|
|
|
|
// We may be on a really old browser or somebody
|
|
|
|
// hand-typed a hash.
|
|
|
|
blueslip.warn("missing section for settings");
|
2018-12-06 22:28:52 +01:00
|
|
|
}
|
2020-12-22 11:26:39 +01:00
|
|
|
settings_panel_menu.normal_settings.activate_section_or_default(section);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-06 22:28:52 +01:00
|
|
|
|
2020-12-22 11:26:39 +01:00
|
|
|
if (base === "organization") {
|
|
|
|
if (!section) {
|
|
|
|
// We may be on a really old browser or somebody
|
|
|
|
// hand-typed a hash.
|
|
|
|
blueslip.warn("missing section for organization");
|
2018-12-01 18:54:41 +01:00
|
|
|
}
|
2024-05-30 11:28:49 +02:00
|
|
|
settings_panel_menu.org_settings.activate_section_or_default(
|
|
|
|
section,
|
|
|
|
get_user_settings_tab(section),
|
|
|
|
);
|
2018-12-01 18:54:41 +01:00
|
|
|
return;
|
2018-12-01 01:08:48 +01:00
|
|
|
}
|
2020-12-22 11:26:39 +01:00
|
|
|
|
|
|
|
// TODO: handle other cases like internal settings
|
|
|
|
// changes.
|
|
|
|
return;
|
2018-12-01 18:54:41 +01:00
|
|
|
}
|
2018-12-01 01:08:48 +01:00
|
|
|
|
2021-03-16 07:22:28 +01:00
|
|
|
// This is a special case when user clicks on a URL that makes the overlay switch
|
|
|
|
// from org settings to user settings or user edits the URL to switch between them.
|
|
|
|
const settings_hashes = new Set(["settings", "organization"]);
|
|
|
|
// Ensure that we are just switching between user and org settings and the settings
|
|
|
|
// overlay is open.
|
|
|
|
const is_hashchange_internal =
|
|
|
|
settings_hashes.has(base) && settings_hashes.has(old_base) && overlays.settings_open();
|
|
|
|
if (is_hashchange_internal) {
|
2021-07-01 20:19:33 +02:00
|
|
|
if (base === "settings") {
|
2024-05-30 11:16:13 +02:00
|
|
|
settings_panel_menu.normal_settings.set_current_tab(section);
|
2021-07-01 20:19:33 +02:00
|
|
|
} else {
|
2024-05-30 11:16:13 +02:00
|
|
|
settings_panel_menu.org_settings.set_current_tab(section);
|
2024-05-30 11:28:49 +02:00
|
|
|
settings_panel_menu.org_settings.set_user_settings_tab(get_user_settings_tab(section));
|
2021-07-01 20:19:33 +02:00
|
|
|
}
|
2024-06-12 09:37:00 +02:00
|
|
|
settings_toggle.goto(base);
|
2021-03-16 07:22:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 18:54:41 +01:00
|
|
|
// It's not super likely that an overlay is already open,
|
|
|
|
// but you can jump from /settings to /streams by using
|
|
|
|
// the browser's history menu or hand-editing the URL or
|
|
|
|
// whatever. If so, just close the overlays.
|
2018-12-03 18:11:14 +01:00
|
|
|
if (base !== old_base) {
|
2018-12-01 18:54:41 +01:00
|
|
|
overlays.close_for_hash_change();
|
|
|
|
}
|
2018-12-01 01:08:48 +01:00
|
|
|
|
2018-12-01 18:54:41 +01:00
|
|
|
// NORMAL FLOW: basically, launch the overlay:
|
|
|
|
|
|
|
|
if (!coming_from_overlay) {
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.set_hash_before_overlay(old_hash);
|
2018-12-01 01:08:48 +01:00
|
|
|
}
|
2018-12-01 18:54:41 +01:00
|
|
|
|
2024-04-30 13:30:24 +02:00
|
|
|
if (base === "channels") {
|
|
|
|
// e.g. #channels/29/social/subscribers
|
2024-01-26 23:17:49 +01:00
|
|
|
const right_side_tab = hash_parser.get_current_nth_hash_section(3);
|
2024-02-24 17:55:39 +01:00
|
|
|
|
|
|
|
if (is_somebody_else_profile_open()) {
|
|
|
|
stream_settings_ui.launch(section, "all-streams", right_side_tab);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We pass left_side_tab as undefined in change_state to
|
|
|
|
// select the tab based on user's subscriptions. "Subscribed" is
|
|
|
|
// selected if user is subscribed to the stream being edited.
|
|
|
|
// Otherwise "All streams" is selected.
|
|
|
|
stream_settings_ui.launch(section, undefined, right_side_tab);
|
2018-12-06 20:03:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-21 16:34:56 +02:00
|
|
|
if (base === "groups") {
|
2024-01-30 15:26:56 +01:00
|
|
|
const right_side_tab = hash_parser.get_current_nth_hash_section(3);
|
2024-02-24 17:54:59 +01:00
|
|
|
|
|
|
|
if (is_somebody_else_profile_open()) {
|
|
|
|
user_group_edit.launch(section, "all-groups", right_side_tab);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We pass left_side_tab as undefined in change_state to
|
|
|
|
// select the tab based on user's membership. "My groups" is
|
|
|
|
// selected if user is a member of group being edited.
|
|
|
|
// Otherwise "All groups" is selected.
|
|
|
|
user_group_edit.launch(section, undefined, right_side_tab);
|
2022-08-21 16:34:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-06 20:03:18 +01:00
|
|
|
if (base === "drafts") {
|
2023-10-06 01:19:21 +02:00
|
|
|
drafts_overlay_ui.launch();
|
2018-12-06 20:03:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (base === "settings") {
|
2023-04-15 18:52:44 +02:00
|
|
|
settings.build_page();
|
|
|
|
admin.build_page();
|
2018-12-06 20:18:56 +01:00
|
|
|
settings.launch(section);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (base === "organization") {
|
2023-04-15 18:52:44 +02:00
|
|
|
settings.build_page();
|
|
|
|
admin.build_page();
|
2024-05-30 11:28:49 +02:00
|
|
|
admin.launch(section, get_user_settings_tab(section));
|
2018-12-06 20:03:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-02 12:07:30 +02:00
|
|
|
if (base === "keyboard-shortcuts") {
|
|
|
|
info_overlay.show("keyboard-shortcuts");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base === "message-formatting") {
|
|
|
|
info_overlay.show("message-formatting");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base === "search-operators") {
|
|
|
|
info_overlay.show("search-operators");
|
|
|
|
return;
|
|
|
|
}
|
2021-02-09 11:16:52 +01:00
|
|
|
|
|
|
|
if (base === "about-zulip") {
|
|
|
|
about_zulip.launch();
|
|
|
|
}
|
2023-04-14 21:35:56 +02:00
|
|
|
|
|
|
|
if (base === "scheduled") {
|
|
|
|
scheduled_messages_overlay_ui.launch();
|
|
|
|
}
|
2024-01-05 16:00:57 +01:00
|
|
|
if (base === "user") {
|
|
|
|
const user_id = Number.parseInt(hash_parser.get_current_hash_section(), 10);
|
|
|
|
if (!people.is_known_user_id(user_id)) {
|
|
|
|
user_profile.show_user_profile_access_error_modal();
|
|
|
|
} else {
|
|
|
|
const user = people.get_by_user_id(user_id);
|
|
|
|
user_profile.show_user_profile(user);
|
|
|
|
}
|
|
|
|
}
|
2018-12-01 01:08:48 +01:00
|
|
|
}
|
|
|
|
|
2024-10-05 07:16:48 +02:00
|
|
|
function hashchanged(from_reload, e, restore_selected_id = true) {
|
2021-05-19 05:34:35 +02:00
|
|
|
const current_hash = window.location.hash;
|
2021-03-22 16:09:12 +01:00
|
|
|
const old_hash = e && (e.oldURL ? new URL(e.oldURL).hash : browser_history.old_hash());
|
2021-11-17 13:24:17 +01:00
|
|
|
const is_hash_web_public_compatible = browser_history.update_web_public_hash(current_hash);
|
2021-03-22 16:09:12 +01:00
|
|
|
|
|
|
|
const was_internal_change = browser_history.save_old_hash();
|
|
|
|
if (was_internal_change) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-12-04 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 05:08:55 +02:00
|
|
|
// TODO: Migrate the `#reload` syntax to use slashes as separators
|
|
|
|
// so that this can be part of the main switch statement.
|
|
|
|
if (window.location.hash.startsWith("#reload")) {
|
|
|
|
// We don't want to change narrow if app is undergoing reload.
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-05-19 05:34:35 +02:00
|
|
|
if (page_params.is_spectator && !is_hash_web_public_compatible) {
|
2021-09-07 04:09:12 +02:00
|
|
|
spectators.login_to_access();
|
2021-05-19 05:34:35 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2024-05-09 10:14:59 +02:00
|
|
|
popovers.hide_all();
|
|
|
|
|
2023-10-01 22:03:44 +02:00
|
|
|
if (hash_parser.is_overlay_hash(current_hash)) {
|
2021-04-09 13:54:44 +02:00
|
|
|
browser_history.state.changing_hash = true;
|
2024-09-26 13:05:01 +02:00
|
|
|
modals.close_active_if_any();
|
2018-12-04 23:06:30 +01:00
|
|
|
do_hashchange_overlay(old_hash);
|
2021-04-09 13:54:44 +02:00
|
|
|
browser_history.state.changing_hash = false;
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-12-04 23:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// We are changing to a "main screen" view.
|
|
|
|
overlays.close_for_hash_change();
|
2023-09-30 09:47:11 +02:00
|
|
|
sidebar_ui.hide_all();
|
2023-10-22 21:58:33 +02:00
|
|
|
modals.close_active_if_any();
|
2021-04-09 13:53:45 +02:00
|
|
|
browser_history.state.changing_hash = true;
|
2024-10-05 07:16:48 +02:00
|
|
|
const ret = do_hashchange_normal(from_reload, restore_selected_id);
|
2021-04-09 13:53:45 +02:00
|
|
|
browser_history.state.changing_hash = false;
|
2018-12-04 23:06:30 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:07:47 +01:00
|
|
|
export function initialize() {
|
2023-05-23 22:44:37 +02:00
|
|
|
// We don't want browser to restore the scroll
|
|
|
|
// position of the new hash in the current hash.
|
|
|
|
window.history.scrollRestoration = "manual";
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(window).on("hashchange", (e) => {
|
2019-07-09 04:30:51 +02:00
|
|
|
hashchanged(false, e.originalEvent);
|
2016-10-23 07:07:09 +02:00
|
|
|
});
|
2014-02-12 20:03:05 +01:00
|
|
|
hashchanged(true);
|
2024-10-05 07:16:48 +02:00
|
|
|
|
|
|
|
$("body").on("click", "a", (e) => {
|
|
|
|
const href = e.currentTarget.getAttribute("href");
|
|
|
|
if (href === window.location.hash && href.includes("/near/")) {
|
|
|
|
// The clicked on a link, perhaps a "said" reference, that
|
|
|
|
// matches the current view. Such a click doesn't trigger
|
|
|
|
// a hashchange event, so we manually trigger one in order
|
|
|
|
// to ensure the app scrolls to the correct message.
|
|
|
|
hashchanged(false, e, false);
|
|
|
|
}
|
|
|
|
});
|
2021-02-28 01:07:47 +01:00
|
|
|
}
|