Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api_docs: Add initial article on Zulip URLs.
Tim Abbottbcf67fc0f8da
diff --git a/api_docs/message-formatting.md b/api_docs/message-formatting.mdindex a4704a3d6cf..82be7e138d2 100644--- a/api_docs/message-formatting.md+++ b/api_docs/message-formatting.md@@ -26,7 +26,9 @@ features.## Links to channels, topics, and messagesZulip's markup supports special readable Markdown syntax for [linking-to channels, topics, and messages](/help/link-to-a-message-or-conversation).+to channels, topics, and+messages](/help/link-to-a-message-or-conversation). See also [Zulip+URLs](/api/zulip-urls)Sample HTML formats are as follows:``` htmldiff --git a/api_docs/sidebar_index.md b/api_docs/sidebar_index.mdindex 13aee7c7e24..ca36d16156d 100644--- a/api_docs/sidebar_index.md+++ b/api_docs/sidebar_index.md@@ -25,6 +25,7 @@* [Roles and permissions](/api/roles-and-permissions)* [Group-setting values](/api/group-setting-values)* [Message formatting](/api/message-formatting)+* [Zulip URLs](/api/zulip-urls)* [Client libraries](/api/client-libraries)* [API changelog](/api/changelog)diff --git a/api_docs/zulip-urls.md b/api_docs/zulip-urls.mdnew file mode 100644index 00000000000..8a5f0279c17--- /dev/null+++ b/api_docs/zulip-urls.md@@ -0,0 +1,109 @@+# Zulip URLs++This page details how to properly construct and parse the URLs that+the Zulip web app uses for various types of views.++Because other clients needs to be able to resolve and process these+links in order to implement equivalent behavior that navigates+directly in say the mobile apps, it's important to have a clear+specification of exactly how these URLs work.++Essentially all of the data is encoded in the URL fragment (`#`) part+of a URL; the protocol, host and path will just be the canonical URL+for the Zulip server (In these examples,+`https://zulip.example.com/`).++## Message feed views++Most links in Zulip are to message feed views, and for that reason+these have the most developed syntax and legacy behavior.++Message feed URLs always start with `#narrow/`, follow by one or more+[search operator/operand pairs](/api/construct-narrow), separated by+`/`s. The operator may be negated by putting a `-` at the start of+it. For example:++`https://zulip.example.com/#narrow/is/starred/sender/17/-channel/14`++is the feed of starred messages sent by user ID to everywhere but+channel 14. The search documentation covers the valid operators and+their meaning.++See also the relevant [message formatting+documentation](/api/message-formatting) for details on Markdown+representations of Zulip-internal links that will be translated into+HTML containing links that use these URLs.++Here, we describe some special encoding rules.++### Operand encoding and decoding++Strings in operands are URL-encoded, and then additional substitution+rules are applied to avoid over-zealous browser handling of certain+characters in the URL fragment:++- `%` => `.`+- `(` => `.28`+- `)` => `.29`+- `.` => `.2E`++They can decoded by applying the reverse transformation: Replace all+`.` characters with `%`, and then do standard URL-decoding.++### Encoding channels++Channel operands must be encoded in one of the two modern fully+supported formats:++- `42`: Just the ID of the channel. Clients should simply parse the+ channel ID to look up the channel, which is of course not guaranteed+ to be accessible to the acting user or even exist.+- `42-channel-name`. The ID of the channel, with a human-readable hint+ of the channel name. Clients generating Zulip URLs are recommended+ to include channel name hints where there is a readable URL-encoding+ of the channel name, but to skip doing so for channel names written+ in non-ascii languages or where otherwise the slug would not make+ the URL nicer for humans. Clients must parse this format by+ discarding everything after the `-` and treating it identically to+ the simpler integer-only format. Note that means nothing enforces+ that the string have anything to do with the channel name;+ functionally, it just an optional hint.++These two formats allow Zulip URLs to stably refer to a specific+channel, even though channels can be renamed, while still allowing the+URLs to have user-friendly name hints most of the time.++There is an additional legacy format that was used prior to 2018 that+clients are required to support:++- `channel-name`: Legacy format of just the channel name, URL-encoded+ and with spaces replaced with dashes. The legacy format should never+ take precedence over the modern format, so a link with+ `2016-election` as the slug must be parsed as the channel with ID+ 2016, even if theoretically it could have been originally intended+ as referring to a channel named `2016 election`.++Clients are not recommended to ever generate this legacy format.++## zulip:// links for mobile login++Zulip's single-sign on login process for the mobile app ends with a+redirect to `zulip://login` with the following query parameters:++- `email`: The email address for the authenticated account.+- `otp_encrypted_api_key`: The API key for the client, encrypted using+ the `mobile_flow_otp` that the client provided when initiating the+ login attempt.+- `realm`: The full URL of the Zulip organization.+- `user_id`: The Zulip user ID for the authenticated account.++**Changes**: The `user_id` field was added to the set of included+query parameters in Zulip 5.0 (feature level 128).++## Related articles++* [Message formatting API](/api/message-formatting)+* [Construct a narrow](/api/construct-narrow) for search.+* [Markdown formatting help](/help/format-your-message-using-markdown)+* [Send a message](/api/send-message)+diff --git a/web/src/hash_parser.ts b/web/src/hash_parser.tsindex 14057b45dba..7542189aba1 100644--- a/web/src/hash_parser.ts+++ b/web/src/hash_parser.ts@@ -1,3 +1,5 @@+// See the Zulip URL spec at https://zulip.com/api/zulip-urls+import {type NarrowTerm, narrow_operator_schema} from "./state_data.ts";export function get_hash_category(hash?: string): string {diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex ea550e9d4ca..60a81a7d20d 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -1,3 +1,5 @@+// See the Zulip URL spec at https://zulip.com/api/zulip-urls+import assert from "minimalistic-assert";import * as z from "zod/mini";diff --git a/web/src/topic_link_util.ts b/web/src/topic_link_util.tsindex 28484236574..8d561ecbbc8 100644--- a/web/src/topic_link_util.ts+++ b/web/src/topic_link_util.ts@@ -1,3 +1,5 @@+// See the Zulip URL spec at https://zulip.com/api/zulip-urls+//// Keep this synchronized with zerver/lib/topic_link_util.pyimport assert from "minimalistic-assert";diff --git a/zerver/lib/topic_link_util.py b/zerver/lib/topic_link_util.pyindex 3187fcccddd..912d6d4fe84 100644--- a/zerver/lib/topic_link_util.py+++ b/zerver/lib/topic_link_util.py@@ -1,3 +1,5 @@+# See the Zulip URL spec at https://zulip.com/api/zulip-urls+## Keep this synchronized with web/src/topic_link_util.tsimport rediff --git a/zerver/lib/url_decoding.py b/zerver/lib/url_decoding.pyindex a6736da7a49..d5629421475 100644--- a/zerver/lib/url_decoding.py+++ b/zerver/lib/url_decoding.py@@ -1,3 +1,5 @@+# See the Zulip URL spec at https://zulip.com/api/zulip-urls+from urllib.parse import unquote, urlsplitfrom django.conf import settingsdiff --git a/zerver/lib/url_encoding.py b/zerver/lib/url_encoding.pyindex 572612ca26c..1e97dcd31ec 100644--- a/zerver/lib/url_encoding.py+++ b/zerver/lib/url_encoding.py@@ -1,3 +1,5 @@+# See the Zulip URL spec at https://zulip.com/api/zulip-urls+import urllib.parsefrom typing import Anyfrom urllib.parse import urlsplit