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.

shared: Move internal_url.ts to web/src.

Shubham Padia97145ca82d74
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 4738153a400..8ba5e7a4bc6 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -1,13 +1,13 @@
import _ from "lodash";
import assert from "minimalistic-assert";
-import * as internal_url from "../shared/src/internal_url.ts";
import * as resolved_topic from "../shared/src/resolved_topic.ts";
import render_search_description from "../templates/search_description.hbs";
import * as blueslip from "./blueslip.ts";
import * as hash_parser from "./hash_parser.ts";
import {$t} from "./i18n.ts";
+import * as internal_url from "./internal_url.ts";
import * as message_parser from "./message_parser.ts";
import * as message_store from "./message_store.ts";
import type {Message} from "./message_store.ts";
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index 58550eeeb27..fb6f274fe1d 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -1,10 +1,9 @@
import assert from "minimalistic-assert";
import * as z from "zod/mini";
-import * as internal_url from "../shared/src/internal_url.ts";
-
import * as blueslip from "./blueslip.ts";
import * as channel_folders from "./channel_folders.ts";
+import * as internal_url from "./internal_url.ts";
import type {Message} from "./message_store.ts";
import {page_params} from "./page_params.ts";
import * as people from "./people.ts";
diff --git a/web/shared/src/internal_url.ts b/web/src/internal_url.ts
similarity index 88%
rename from web/shared/src/internal_url.ts
rename to web/src/internal_url.ts
index be6b925c96f..79cdae00d84 100644
--- a/web/shared/src/internal_url.ts
+++ b/web/src/internal_url.ts
@@ -11,7 +11,10 @@ const hashReplacements = new Map([
// window.location.hash. So we hide our URI-encoding
// by replacing % with . (like MediaWiki).
export function encodeHashComponent(str: string): string {
- return encodeURIComponent(str).replace(/[%().]/g, (matched) => hashReplacements.get(matched)!);
+ return encodeURIComponent(str).replaceAll(
+ /[%().]/g,
+ (matched) => hashReplacements.get(matched)!,
+ );
}
export function decodeHashComponent(str: string): string {
@@ -20,7 +23,7 @@ export function decodeHashComponent(str: string): string {
// of such characters when encoding. This can also,
// fail independent of our fault.
// Here we let the calling code handle the exception.
- return decodeURIComponent(str.replace(/\./g, "%"));
+ return decodeURIComponent(str.replaceAll(".", "%"));
}
export function stream_id_to_slug(
@@ -31,10 +34,7 @@ export function stream_id_to_slug(
// The name part of the URL doesn't really matter, so we try to
// make it pretty.
-
- // TODO: Convert this to replaceAll once mobile no longer supports
- // browsers that don't have it.
- name = name.replace(/ /g, "-");
+ name = name.replaceAll(" ", "-");
return `${stream_id}-${name}`;
}
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.ts
index 3ef0fb0a4bf..8d9ac92f31b 100644
--- a/web/src/message_list_view.ts
+++ b/web/src/message_list_view.ts
@@ -3,7 +3,6 @@ import $ from "jquery";
import _ from "lodash";
import assert from "minimalistic-assert";
-import * as internal_url from "../shared/src/internal_url.ts";
import * as resolved_topic from "../shared/src/resolved_topic.ts";
import render_bookend from "../templates/bookend.hbs";
import render_login_to_view_image_button from "../templates/login_to_view_image_button.hbs";
@@ -18,6 +17,7 @@ import * as compose_fade from "./compose_fade.ts";
import * as condense from "./condense.ts";
import * as hash_util from "./hash_util.ts";
import {$t} from "./i18n.ts";
+import * as internal_url from "./internal_url.ts";
import * as message_edit from "./message_edit.ts";
import type {MessageList} from "./message_list.ts";
import * as message_list_tooltips from "./message_list_tooltips.ts";
diff --git a/web/src/people.ts b/web/src/people.ts
index 713acd23817..942928b4b25 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -2,13 +2,13 @@ import md5 from "blueimp-md5";
import assert from "minimalistic-assert";
import * as z from "zod/mini";
-import * as internal_url from "../shared/src/internal_url.ts";
import * as typeahead from "../shared/src/typeahead.ts";
import * as blueslip from "./blueslip.ts";
import * as channel from "./channel.ts";
import {FoldDict} from "./fold_dict.ts";
import {$t} from "./i18n.ts";
+import * as internal_url from "./internal_url.ts";
import type {DisplayRecipientUser, Message, MessageWithBooleans} from "./message_store.ts";
import * as message_user_ids from "./message_user_ids.ts";
import * as muted_users from "./muted_users.ts";
diff --git a/web/tests/internal_url.test.cjs b/web/tests/internal_url.test.cjs
index 01b4c272653..1ddebaa2a71 100644
--- a/web/tests/internal_url.test.cjs
+++ b/web/tests/internal_url.test.cjs
@@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const {zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
-const internal_url = zrequire("../shared/src/internal_url");
+const internal_url = zrequire("internal_url");
run_test("test encodeHashComponent", () => {
const decoded = "https://www.zulipexample.com";