mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	js: Convert static/js/hash_util.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							9d318f054f
						
					
				
				
					commit
					c94ffb5319
				
			@@ -144,7 +144,6 @@
 | 
				
			|||||||
                "emoji_picker": false,
 | 
					                "emoji_picker": false,
 | 
				
			||||||
                "favicon": false,
 | 
					                "favicon": false,
 | 
				
			||||||
                "flatpickr": false,
 | 
					                "flatpickr": false,
 | 
				
			||||||
                "hash_util": false,
 | 
					 | 
				
			||||||
                "hashchange": false,
 | 
					                "hashchange": false,
 | 
				
			||||||
                "helpers": false,
 | 
					                "helpers": false,
 | 
				
			||||||
                "history": false,
 | 
					                "history": false,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,7 +91,6 @@ rewiremock.enable();
 | 
				
			|||||||
const huddle_data = zrequire("huddle_data");
 | 
					const huddle_data = zrequire("huddle_data");
 | 
				
			||||||
const compose_fade = zrequire("compose_fade");
 | 
					const compose_fade = zrequire("compose_fade");
 | 
				
			||||||
zrequire("unread");
 | 
					zrequire("unread");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const narrow = zrequire("narrow");
 | 
					const narrow = zrequire("narrow");
 | 
				
			||||||
const presence = zrequire("presence");
 | 
					const presence = zrequire("presence");
 | 
				
			||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,9 @@ const compose_pm_pill = {__esModule: true};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
rewiremock("../../static/js/compose_pm_pill").with(compose_pm_pill);
 | 
					rewiremock("../../static/js/compose_pm_pill").with(compose_pm_pill);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const hash_util = set_global("hash_util", {});
 | 
					const hash_util = {__esModule: true};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rewiremock("../../static/js/hash_util").with(hash_util);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rewiremock("../../static/js/reload_state").with({
 | 
					rewiremock("../../static/js/reload_state").with({
 | 
				
			||||||
    is_in_progress: () => false,
 | 
					    is_in_progress: () => false,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,6 @@ set_global("Image", Image);
 | 
				
			|||||||
const doc = "";
 | 
					const doc = "";
 | 
				
			||||||
set_global("document", doc);
 | 
					set_global("document", doc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const emoji = zrequire("emoji", "shared/js/emoji");
 | 
					const emoji = zrequire("emoji", "shared/js/emoji");
 | 
				
			||||||
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
 | 
					const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
 | 
				
			||||||
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
 | 
					const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,6 @@ rewiremock("katex").with({
 | 
				
			|||||||
rewiremock.enable();
 | 
					rewiremock.enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const markdown_config = zrequire("markdown_config");
 | 
					const markdown_config = zrequire("markdown_config");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
zrequire("message_store");
 | 
					zrequire("message_store");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const markdown = zrequire("markdown");
 | 
					const markdown = zrequire("markdown");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,6 @@ const {run_test} = require("../zjsunit/test");
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const peer_data = zrequire("peer_data");
 | 
					const peer_data = zrequire("peer_data");
 | 
				
			||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set_global("page_params", {
 | 
					set_global("page_params", {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,6 @@ rewiremock.enable();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
zrequire("presence");
 | 
					zrequire("presence");
 | 
				
			||||||
zrequire("buddy_data");
 | 
					zrequire("buddy_data");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
const pm_conversations = zrequire("pm_conversations");
 | 
					const pm_conversations = zrequire("pm_conversations");
 | 
				
			||||||
const pm_list = zrequire("pm_list");
 | 
					const pm_list = zrequire("pm_list");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,6 @@ rewiremock("clipboard").with(ClipboardJS);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
rewiremock.enable();
 | 
					rewiremock.enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
zrequire("narrow");
 | 
					zrequire("narrow");
 | 
				
			||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
zrequire("presence");
 | 
					zrequire("presence");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ set_global("unread", {
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
set_global("hash_util", {
 | 
					rewiremock("../../static/js/hash_util").with({
 | 
				
			||||||
    by_stream_uri: () => "https://www.example.com",
 | 
					    by_stream_uri: () => "https://www.example.com",
 | 
				
			||||||
    by_stream_topic_uri: () => "https://www.example.com",
 | 
					    by_stream_topic_uri: () => "https://www.example.com",
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,6 @@ const page_params = set_global("page_params", {
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const color_data = zrequire("color_data");
 | 
					const color_data = zrequire("color_data");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const stream_topic_history = zrequire("stream_topic_history");
 | 
					const stream_topic_history = zrequire("stream_topic_history");
 | 
				
			||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
const stream_color = zrequire("stream_color");
 | 
					const stream_color = zrequire("stream_color");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ stub_templates(() => noop);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
rewiremock("../../static/js/channel").with({});
 | 
					rewiremock("../../static/js/channel").with({});
 | 
				
			||||||
set_global("hashchange", {update_browser_history: noop});
 | 
					set_global("hashchange", {update_browser_history: noop});
 | 
				
			||||||
set_global("hash_util", {
 | 
					rewiremock("../../static/js/hash_util").with({
 | 
				
			||||||
    stream_edit_uri: noop,
 | 
					    stream_edit_uri: noop,
 | 
				
			||||||
    by_stream_uri: noop,
 | 
					    by_stream_uri: noop,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,6 @@ rewiremock.enable();
 | 
				
			|||||||
const {Filter} = zrequire("Filter", "js/filter");
 | 
					const {Filter} = zrequire("Filter", "js/filter");
 | 
				
			||||||
const stream_sort = zrequire("stream_sort");
 | 
					const stream_sort = zrequire("stream_sort");
 | 
				
			||||||
const stream_color = zrequire("stream_color");
 | 
					const stream_color = zrequire("stream_color");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const unread = zrequire("unread");
 | 
					const unread = zrequire("unread");
 | 
				
			||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
const scroll_util = zrequire("scroll_util");
 | 
					const scroll_util = zrequire("scroll_util");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const {strict: assert} = require("assert");
 | 
					const {strict: assert} = require("assert");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const rewiremock = require("rewiremock/node");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const {stub_templates} = require("../zjsunit/handlebars");
 | 
					const {stub_templates} = require("../zjsunit/handlebars");
 | 
				
			||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
					const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
				
			||||||
const {run_test} = require("../zjsunit/test");
 | 
					const {run_test} = require("../zjsunit/test");
 | 
				
			||||||
@@ -19,10 +21,12 @@ set_global("location", {
 | 
				
			|||||||
    hash: `#streams/${denmark_stream_id}/announce`,
 | 
					    hash: `#streams/${denmark_stream_id}/announce`,
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set_global("hash_util", {
 | 
					rewiremock("../../static/js/hash_util").with({
 | 
				
			||||||
    by_stream_uri: () => {},
 | 
					    by_stream_uri: () => {},
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rewiremock.enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
const subs = zrequire("subs");
 | 
					const subs = zrequire("subs");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -205,3 +209,4 @@ run_test("redraw_left_panel", (override) => {
 | 
				
			|||||||
    assert(!$(".right .settings").visible());
 | 
					    assert(!$(".right .settings").visible());
 | 
				
			||||||
    assert($(".nothing-selected").visible());
 | 
					    assert($(".nothing-selected").visible());
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					rewiremock.disable();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,6 @@ set_global("message_list", {});
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
rewiremock.enable();
 | 
					rewiremock.enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
const unread = zrequire("unread");
 | 
					const unread = zrequire("unread");
 | 
				
			||||||
const stream_topic_history = zrequire("stream_topic_history");
 | 
					const stream_topic_history = zrequire("stream_topic_history");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ const peer_data = zrequire("peer_data");
 | 
				
			|||||||
const people = zrequire("people");
 | 
					const people = zrequire("people");
 | 
				
			||||||
const stream_data = zrequire("stream_data");
 | 
					const stream_data = zrequire("stream_data");
 | 
				
			||||||
zrequire("narrow");
 | 
					zrequire("narrow");
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const emoji = zrequire("emoji", "shared/js/emoji");
 | 
					const emoji = zrequire("emoji", "shared/js/emoji");
 | 
				
			||||||
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
 | 
					const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,7 +109,6 @@ rewiremock.enable();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const util = zrequire("util");
 | 
					const util = zrequire("util");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
zrequire("hash_util");
 | 
					 | 
				
			||||||
zrequire("message_view_header");
 | 
					zrequire("message_view_header");
 | 
				
			||||||
zrequire("presence");
 | 
					zrequire("presence");
 | 
				
			||||||
zrequire("search_pill_widget");
 | 
					zrequire("search_pill_widget");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const compose_fade = require("./compose_fade");
 | 
					const compose_fade = require("./compose_fade");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const people = require("./people");
 | 
					const people = require("./people");
 | 
				
			||||||
const user_status = require("./user_status");
 | 
					const user_status = require("./user_status");
 | 
				
			||||||
const util = require("./util");
 | 
					const util = require("./util");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,6 @@ import "../ui";
 | 
				
			|||||||
import "../composebox_typeahead";
 | 
					import "../composebox_typeahead";
 | 
				
			||||||
import "../hotkey";
 | 
					import "../hotkey";
 | 
				
			||||||
import "../notifications";
 | 
					import "../notifications";
 | 
				
			||||||
import "../hash_util";
 | 
					 | 
				
			||||||
import "../hashchange";
 | 
					import "../hashchange";
 | 
				
			||||||
import "../message_flags";
 | 
					import "../message_flags";
 | 
				
			||||||
import "../starred_messages";
 | 
					import "../starred_messages";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import render_buddy_list_tooltip_content from "../templates/buddy_list_tooltip_c
 | 
				
			|||||||
import * as channel from "./channel";
 | 
					import * as channel from "./channel";
 | 
				
			||||||
import * as compose from "./compose";
 | 
					import * as compose from "./compose";
 | 
				
			||||||
import * as compose_state from "./compose_state";
 | 
					import * as compose_state from "./compose_state";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as message_edit from "./message_edit";
 | 
					import * as message_edit from "./message_edit";
 | 
				
			||||||
import * as message_edit_history from "./message_edit_history";
 | 
					import * as message_edit_history from "./message_edit_history";
 | 
				
			||||||
import * as muting_ui from "./muting_ui";
 | 
					import * as muting_ui from "./muting_ui";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ const compose_fade = require("./compose_fade");
 | 
				
			|||||||
const compose_pm_pill = require("./compose_pm_pill");
 | 
					const compose_pm_pill = require("./compose_pm_pill");
 | 
				
			||||||
const compose_state = require("./compose_state");
 | 
					const compose_state = require("./compose_state");
 | 
				
			||||||
const drafts = require("./drafts");
 | 
					const drafts = require("./drafts");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const message_viewport = require("./message_viewport");
 | 
					const message_viewport = require("./message_viewport");
 | 
				
			||||||
const narrow_state = require("./narrow_state");
 | 
					const narrow_state = require("./narrow_state");
 | 
				
			||||||
const notifications = require("./notifications");
 | 
					const notifications = require("./notifications");
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -22,7 +22,6 @@ declare let emoji: any;
 | 
				
			|||||||
declare let emoji_picker: any;
 | 
					declare let emoji_picker: any;
 | 
				
			||||||
declare let favicon: any;
 | 
					declare let favicon: any;
 | 
				
			||||||
declare let hashchange: any;
 | 
					declare let hashchange: any;
 | 
				
			||||||
declare let hash_util: any;
 | 
					 | 
				
			||||||
declare let helpers: any;
 | 
					declare let helpers: any;
 | 
				
			||||||
declare let home_msg_list: any;
 | 
					declare let home_msg_list: any;
 | 
				
			||||||
declare let hotspots: any;
 | 
					declare let hotspots: any;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,14 @@
 | 
				
			|||||||
"use strict";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
 | 
					import * as people from "./people";
 | 
				
			||||||
 | 
					import * as stream_data from "./stream_data";
 | 
				
			||||||
 | 
					import * as ui_report from "./ui_report";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const narrow_state = require("./narrow_state");
 | 
					export function get_hash_category(hash) {
 | 
				
			||||||
const people = require("./people");
 | 
					 | 
				
			||||||
const stream_data = require("./stream_data");
 | 
					 | 
				
			||||||
const ui_report = require("./ui_report");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
exports.get_hash_category = function (hash) {
 | 
					 | 
				
			||||||
    // given "#streams/subscribed", returns "streams"
 | 
					    // given "#streams/subscribed", returns "streams"
 | 
				
			||||||
    return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
 | 
					    return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.get_hash_section = function (hash) {
 | 
					export function get_hash_section(hash) {
 | 
				
			||||||
    // given "#settings/your-account", returns "your-account"
 | 
					    // given "#settings/your-account", returns "your-account"
 | 
				
			||||||
    // given '#streams/5/social", returns "5"
 | 
					    // given '#streams/5/social", returns "5"
 | 
				
			||||||
    if (!hash) {
 | 
					    if (!hash) {
 | 
				
			||||||
@@ -20,16 +18,16 @@ exports.get_hash_section = function (hash) {
 | 
				
			|||||||
    const parts = hash.replace(/\/$/, "").split(/\//);
 | 
					    const parts = hash.replace(/\/$/, "").split(/\//);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return parts[1] || "";
 | 
					    return parts[1] || "";
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Some browsers zealously URI-decode the contents of
 | 
					// Some browsers zealously URI-decode the contents of
 | 
				
			||||||
// window.location.hash.  So we hide our URI-encoding
 | 
					// window.location.hash.  So we hide our URI-encoding
 | 
				
			||||||
// by replacing % with . (like MediaWiki).
 | 
					// by replacing % with . (like MediaWiki).
 | 
				
			||||||
exports.encodeHashComponent = function (str) {
 | 
					export function encodeHashComponent(str) {
 | 
				
			||||||
    return encodeURIComponent(str).replace(/\./g, "%2E").replace(/%/g, ".");
 | 
					    return encodeURIComponent(str).replace(/\./g, "%2E").replace(/%/g, ".");
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.encode_operand = function (operator, operand) {
 | 
					export function encode_operand(operator, operand) {
 | 
				
			||||||
    if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
 | 
					    if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
 | 
				
			||||||
        const slug = people.emails_to_slug(operand);
 | 
					        const slug = people.emails_to_slug(operand);
 | 
				
			||||||
        if (slug) {
 | 
					        if (slug) {
 | 
				
			||||||
@@ -38,29 +36,29 @@ exports.encode_operand = function (operator, operand) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (operator === "stream") {
 | 
					    if (operator === "stream") {
 | 
				
			||||||
        return exports.encode_stream_name(operand);
 | 
					        return encode_stream_name(operand);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return exports.encodeHashComponent(operand);
 | 
					    return encodeHashComponent(operand);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.encode_stream_id = function (stream_id) {
 | 
					export function encode_stream_id(stream_id) {
 | 
				
			||||||
    // stream_data appends the stream name, but it does not do the
 | 
					    // stream_data appends the stream name, but it does not do the
 | 
				
			||||||
    // URI encoding piece
 | 
					    // URI encoding piece
 | 
				
			||||||
    const slug = stream_data.id_to_slug(stream_id);
 | 
					    const slug = stream_data.id_to_slug(stream_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return exports.encodeHashComponent(slug);
 | 
					    return encodeHashComponent(slug);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.encode_stream_name = function (operand) {
 | 
					export function encode_stream_name(operand) {
 | 
				
			||||||
    // stream_data prefixes the stream id, but it does not do the
 | 
					    // stream_data prefixes the stream id, but it does not do the
 | 
				
			||||||
    // URI encoding piece
 | 
					    // URI encoding piece
 | 
				
			||||||
    operand = stream_data.name_to_slug(operand);
 | 
					    operand = stream_data.name_to_slug(operand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return exports.encodeHashComponent(operand);
 | 
					    return encodeHashComponent(operand);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.decodeHashComponent = function (str) {
 | 
					export function decodeHashComponent(str) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        // This fails for URLs containing
 | 
					        // This fails for URLs containing
 | 
				
			||||||
        // foo.foo or foo%foo due to our fault in special handling
 | 
					        // foo.foo or foo%foo due to our fault in special handling
 | 
				
			||||||
@@ -73,9 +71,9 @@ exports.decodeHashComponent = function (str) {
 | 
				
			|||||||
        ui_report.error(i18n.t("Invalid URL"), undefined, $("#home-error"), 2000);
 | 
					        ui_report.error(i18n.t("Invalid URL"), undefined, $("#home-error"), 2000);
 | 
				
			||||||
        return "";
 | 
					        return "";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.decode_operand = function (operator, operand) {
 | 
					export function decode_operand(operator, operand) {
 | 
				
			||||||
    if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
 | 
					    if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
 | 
				
			||||||
        const emails = people.slug_to_emails(operand);
 | 
					        const emails = people.slug_to_emails(operand);
 | 
				
			||||||
        if (emails) {
 | 
					        if (emails) {
 | 
				
			||||||
@@ -83,32 +81,27 @@ exports.decode_operand = function (operator, operand) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    operand = exports.decodeHashComponent(operand);
 | 
					    operand = decodeHashComponent(operand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (operator === "stream") {
 | 
					    if (operator === "stream") {
 | 
				
			||||||
        return stream_data.slug_to_name(operand);
 | 
					        return stream_data.slug_to_name(operand);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return operand;
 | 
					    return operand;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.by_stream_uri = function (stream_id) {
 | 
					export function by_stream_uri(stream_id) {
 | 
				
			||||||
    return "#narrow/stream/" + exports.encode_stream_id(stream_id);
 | 
					    return "#narrow/stream/" + encode_stream_id(stream_id);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.by_stream_topic_uri = function (stream_id, topic) {
 | 
					export function by_stream_topic_uri(stream_id, topic) {
 | 
				
			||||||
    return (
 | 
					    return "#narrow/stream/" + encode_stream_id(stream_id) + "/topic/" + encodeHashComponent(topic);
 | 
				
			||||||
        "#narrow/stream/" +
 | 
					}
 | 
				
			||||||
        exports.encode_stream_id(stream_id) +
 | 
					 | 
				
			||||||
        "/topic/" +
 | 
					 | 
				
			||||||
        exports.encodeHashComponent(topic)
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Encodes an operator list into the
 | 
					// Encodes an operator list into the
 | 
				
			||||||
// corresponding hash: the # component
 | 
					// corresponding hash: the # component
 | 
				
			||||||
// of the narrow URL
 | 
					// of the narrow URL
 | 
				
			||||||
exports.operators_to_hash = function (operators) {
 | 
					export function operators_to_hash(operators) {
 | 
				
			||||||
    let hash = "#";
 | 
					    let hash = "#";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (operators !== undefined) {
 | 
					    if (operators !== undefined) {
 | 
				
			||||||
@@ -123,33 +116,33 @@ exports.operators_to_hash = function (operators) {
 | 
				
			|||||||
            hash +=
 | 
					            hash +=
 | 
				
			||||||
                "/" +
 | 
					                "/" +
 | 
				
			||||||
                sign +
 | 
					                sign +
 | 
				
			||||||
                exports.encodeHashComponent(operator) +
 | 
					                encodeHashComponent(operator) +
 | 
				
			||||||
                "/" +
 | 
					                "/" +
 | 
				
			||||||
                exports.encode_operand(operator, operand);
 | 
					                encode_operand(operator, operand);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return hash;
 | 
					    return hash;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.by_sender_uri = function (reply_to) {
 | 
					export function by_sender_uri(reply_to) {
 | 
				
			||||||
    return exports.operators_to_hash([{operator: "sender", operand: reply_to}]);
 | 
					    return operators_to_hash([{operator: "sender", operand: reply_to}]);
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.pm_with_uri = function (reply_to) {
 | 
					export function pm_with_uri(reply_to) {
 | 
				
			||||||
    const slug = people.emails_to_slug(reply_to);
 | 
					    const slug = people.emails_to_slug(reply_to);
 | 
				
			||||||
    return "#narrow/pm-with/" + slug;
 | 
					    return "#narrow/pm-with/" + slug;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.huddle_with_uri = function (user_ids_string) {
 | 
					export function huddle_with_uri(user_ids_string) {
 | 
				
			||||||
    // This method is convenient for callers
 | 
					    // This method is convenient for callers
 | 
				
			||||||
    // that have already converted emails to a comma-delimited
 | 
					    // that have already converted emails to a comma-delimited
 | 
				
			||||||
    // list of user_ids.  We should be careful to keep this
 | 
					    // list of user_ids.  We should be careful to keep this
 | 
				
			||||||
    // consistent with hash_util.decode_operand.
 | 
					    // consistent with hash_util.decode_operand.
 | 
				
			||||||
    return "#narrow/pm-with/" + user_ids_string + "-group";
 | 
					    return "#narrow/pm-with/" + user_ids_string + "-group";
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.by_conversation_and_time_uri = function (message) {
 | 
					export function by_conversation_and_time_uri(message) {
 | 
				
			||||||
    const absolute_url =
 | 
					    const absolute_url =
 | 
				
			||||||
        window.location.protocol +
 | 
					        window.location.protocol +
 | 
				
			||||||
        "//" +
 | 
					        "//" +
 | 
				
			||||||
@@ -157,36 +150,34 @@ exports.by_conversation_and_time_uri = function (message) {
 | 
				
			|||||||
        "/" +
 | 
					        "/" +
 | 
				
			||||||
        window.location.pathname.split("/")[1];
 | 
					        window.location.pathname.split("/")[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const suffix = "/near/" + exports.encodeHashComponent(message.id);
 | 
					    const suffix = "/near/" + encodeHashComponent(message.id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (message.type === "stream") {
 | 
					    if (message.type === "stream") {
 | 
				
			||||||
        return (
 | 
					        return absolute_url + by_stream_topic_uri(message.stream_id, message.topic) + suffix;
 | 
				
			||||||
            absolute_url + exports.by_stream_topic_uri(message.stream_id, message.topic) + suffix
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return absolute_url + people.pm_perma_link(message) + suffix;
 | 
					    return absolute_url + people.pm_perma_link(message) + suffix;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.stream_edit_uri = function (sub) {
 | 
					export function stream_edit_uri(sub) {
 | 
				
			||||||
    const hash = `#streams/${sub.stream_id}/${exports.encodeHashComponent(sub.name)}`;
 | 
					    const hash = `#streams/${sub.stream_id}/${encodeHashComponent(sub.name)}`;
 | 
				
			||||||
    return hash;
 | 
					    return hash;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.search_public_streams_notice_url = function () {
 | 
					export function search_public_streams_notice_url() {
 | 
				
			||||||
    // Computes the URL of the current narrow if streams:public were added.
 | 
					    // Computes the URL of the current narrow if streams:public were added.
 | 
				
			||||||
    const operators = narrow_state.filter().operators();
 | 
					    const operators = narrow_state.filter().operators();
 | 
				
			||||||
    const public_operator = {operator: "streams", operand: "public"};
 | 
					    const public_operator = {operator: "streams", operand: "public"};
 | 
				
			||||||
    return exports.operators_to_hash([public_operator].concat(operators));
 | 
					    return operators_to_hash([public_operator].concat(operators));
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.parse_narrow = function (hash) {
 | 
					export function parse_narrow(hash) {
 | 
				
			||||||
    let i;
 | 
					    let i;
 | 
				
			||||||
    const operators = [];
 | 
					    const operators = [];
 | 
				
			||||||
    for (i = 1; i < hash.length; i += 2) {
 | 
					    for (i = 1; i < hash.length; i += 2) {
 | 
				
			||||||
        // We don't construct URLs with an odd number of components,
 | 
					        // We don't construct URLs with an odd number of components,
 | 
				
			||||||
        // but the user might write one.
 | 
					        // but the user might write one.
 | 
				
			||||||
        let operator = exports.decodeHashComponent(hash[i]);
 | 
					        let operator = decodeHashComponent(hash[i]);
 | 
				
			||||||
        // Do not parse further if empty operator encountered.
 | 
					        // Do not parse further if empty operator encountered.
 | 
				
			||||||
        if (operator === "") {
 | 
					        if (operator === "") {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
@@ -204,10 +195,8 @@ exports.parse_narrow = function (hash) {
 | 
				
			|||||||
            operator = operator.slice(1);
 | 
					            operator = operator.slice(1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const operand = exports.decode_operand(operator, raw_operand);
 | 
					        const operand = decode_operand(operator, raw_operand);
 | 
				
			||||||
        operators.push({negated, operator, operand});
 | 
					        operators.push({negated, operator, operand});
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return operators;
 | 
					    return operators;
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
window.hash_util = exports;
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const drafts = require("./drafts");
 | 
					const drafts = require("./drafts");
 | 
				
			||||||
const floating_recipient_bar = require("./floating_recipient_bar");
 | 
					const floating_recipient_bar = require("./floating_recipient_bar");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const info_overlay = require("./info_overlay");
 | 
					const info_overlay = require("./info_overlay");
 | 
				
			||||||
const invite = require("./invite");
 | 
					const invite = require("./invite");
 | 
				
			||||||
const message_viewport = require("./message_viewport");
 | 
					const message_viewport = require("./message_viewport");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as people from "./people";
 | 
					import * as people from "./people";
 | 
				
			||||||
import * as stream_data from "./stream_data";
 | 
					import * as stream_data from "./stream_data";
 | 
				
			||||||
import * as user_groups from "./user_groups";
 | 
					import * as user_groups from "./user_groups";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import render_single_message from "../templates/single_message.hbs";
 | 
				
			|||||||
import * as compose from "./compose";
 | 
					import * as compose from "./compose";
 | 
				
			||||||
import * as compose_fade from "./compose_fade";
 | 
					import * as compose_fade from "./compose_fade";
 | 
				
			||||||
import * as condense from "./condense";
 | 
					import * as condense from "./condense";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as message_edit from "./message_edit";
 | 
					import * as message_edit from "./message_edit";
 | 
				
			||||||
import * as message_viewport from "./message_viewport";
 | 
					import * as message_viewport from "./message_viewport";
 | 
				
			||||||
import * as narrow_state from "./narrow_state";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
import _ from "lodash";
 | 
					import _ from "lodash";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import * as floating_recipient_bar from "./floating_recipient_bar";
 | 
					import * as floating_recipient_bar from "./floating_recipient_bar";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as loading from "./loading";
 | 
					import * as loading from "./loading";
 | 
				
			||||||
import * as message_viewport from "./message_viewport";
 | 
					import * as message_viewport from "./message_viewport";
 | 
				
			||||||
import * as narrow_state from "./narrow_state";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as narrow_state from "./narrow_state";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
import * as people from "./people";
 | 
					import * as people from "./people";
 | 
				
			||||||
import * as pm_conversations from "./pm_conversations";
 | 
					import * as pm_conversations from "./pm_conversations";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,7 @@ import render_user_profile_modal from "../templates/user_profile_modal.hbs";
 | 
				
			|||||||
import * as compose_state from "./compose_state";
 | 
					import * as compose_state from "./compose_state";
 | 
				
			||||||
import * as condense from "./condense";
 | 
					import * as condense from "./condense";
 | 
				
			||||||
import * as feature_flags from "./feature_flags";
 | 
					import * as feature_flags from "./feature_flags";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as message_edit from "./message_edit";
 | 
					import * as message_edit from "./message_edit";
 | 
				
			||||||
import * as message_edit_history from "./message_edit_history";
 | 
					import * as message_edit_history from "./message_edit_history";
 | 
				
			||||||
import * as message_viewport from "./message_viewport";
 | 
					import * as message_viewport from "./message_viewport";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ const render_recent_topics_filters = require("../templates/recent_topics_filters
 | 
				
			|||||||
const render_recent_topics_body = require("../templates/recent_topics_table.hbs");
 | 
					const render_recent_topics_body = require("../templates/recent_topics_table.hbs");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const drafts = require("./drafts");
 | 
					const drafts = require("./drafts");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const ListWidget = require("./list_widget");
 | 
					const ListWidget = require("./list_widget");
 | 
				
			||||||
const {localstorage} = require("./localstorage");
 | 
					const {localstorage} = require("./localstorage");
 | 
				
			||||||
const muting = require("./muting");
 | 
					const muting = require("./muting");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const channel = require("./channel");
 | 
					const channel = require("./channel");
 | 
				
			||||||
const compose = require("./compose");
 | 
					const compose = require("./compose");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const notifications = require("./notifications");
 | 
					const notifications = require("./notifications");
 | 
				
			||||||
const people = require("./people");
 | 
					const people = require("./people");
 | 
				
			||||||
const transmit = require("./transmit");
 | 
					const transmit = require("./transmit");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
import * as color_data from "./color_data";
 | 
					import * as color_data from "./color_data";
 | 
				
			||||||
import {FoldDict} from "./fold_dict";
 | 
					import {FoldDict} from "./fold_dict";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as peer_data from "./peer_data";
 | 
					import * as peer_data from "./peer_data";
 | 
				
			||||||
import * as people from "./people";
 | 
					import * as people from "./people";
 | 
				
			||||||
import * as settings_config from "./settings_config";
 | 
					import * as settings_config from "./settings_config";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ import render_subscription_settings from "../templates/subscription_settings.hbs
 | 
				
			|||||||
import render_subscription_stream_privacy_modal from "../templates/subscription_stream_privacy_modal.hbs";
 | 
					import render_subscription_stream_privacy_modal from "../templates/subscription_stream_privacy_modal.hbs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import * as channel from "./channel";
 | 
					import * as channel from "./channel";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as ListWidget from "./list_widget";
 | 
					import * as ListWidget from "./list_widget";
 | 
				
			||||||
import * as narrow_state from "./narrow_state";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
import * as overlays from "./overlays";
 | 
					import * as overlays from "./overlays";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ const _ = require("lodash");
 | 
				
			|||||||
const render_stream_privacy = require("../templates/stream_privacy.hbs");
 | 
					const render_stream_privacy = require("../templates/stream_privacy.hbs");
 | 
				
			||||||
const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");
 | 
					const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const keydown_util = require("./keydown_util");
 | 
					const keydown_util = require("./keydown_util");
 | 
				
			||||||
const {ListCursor} = require("./list_cursor");
 | 
					const {ListCursor} = require("./list_cursor");
 | 
				
			||||||
const narrow_state = require("./narrow_state");
 | 
					const narrow_state = require("./narrow_state");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import render_topic_sidebar_actions from "../templates/topic_sidebar_actions.hbs
 | 
				
			|||||||
import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbs";
 | 
					import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import * as channel from "./channel";
 | 
					import * as channel from "./channel";
 | 
				
			||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as message_edit from "./message_edit";
 | 
					import * as message_edit from "./message_edit";
 | 
				
			||||||
import * as muting from "./muting";
 | 
					import * as muting from "./muting";
 | 
				
			||||||
import * as muting_ui from "./muting_ui";
 | 
					import * as muting_ui from "./muting_ui";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ const render_subscriptions = require("../templates/subscriptions.hbs");
 | 
				
			|||||||
const channel = require("./channel");
 | 
					const channel = require("./channel");
 | 
				
			||||||
const components = require("./components");
 | 
					const components = require("./components");
 | 
				
			||||||
const compose_state = require("./compose_state");
 | 
					const compose_state = require("./compose_state");
 | 
				
			||||||
 | 
					const hash_util = require("./hash_util");
 | 
				
			||||||
const loading = require("./loading");
 | 
					const loading = require("./loading");
 | 
				
			||||||
const message_live_update = require("./message_live_update");
 | 
					const message_live_update = require("./message_live_update");
 | 
				
			||||||
const overlays = require("./overlays");
 | 
					const overlays = require("./overlays");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import * as hash_util from "./hash_util";
 | 
				
			||||||
import * as muting from "./muting";
 | 
					import * as muting from "./muting";
 | 
				
			||||||
import * as narrow_state from "./narrow_state";
 | 
					import * as narrow_state from "./narrow_state";
 | 
				
			||||||
import * as stream_topic_history from "./stream_topic_history";
 | 
					import * as stream_topic_history from "./stream_topic_history";
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user