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.

emoji: Render large emoji on emoji-only messages.

Karl Stolley15f87a7b8aae
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 8cf4c127291..b90f1f73a2a 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 436**
+
+* [Message formatting](/api/message-formatting): Added new
+ specification that emoji-only messages should show enlarged emoji.
+
**Feature level 435**
* [`POST /register`](/api/register-queue): Added `server_report_message_types`
diff --git a/api_docs/message-formatting.md b/api_docs/message-formatting.md
index c5bd203ddf6..7d33b3e0153 100644
--- a/api_docs/message-formatting.md
+++ b/api_docs/message-formatting.md
@@ -125,7 +125,14 @@ can override that default based on `web_channel_default_view` setting.
Zulip's [emoji][help-emoji] support includes standard Unicode emoji, a
built-in Zulip custom emoji like `:zulip:` and [custom realm
-emoji][help-custom-emoji].
+emoji][help-custom-emoji]. To maximize legibility, emoji should be
+displayed inline with text, at the maximum size that does not
+interfere with line spacing.
+
+**Large emoji**. Clients are recommended to display single-paragraph
+messages that contain only emoji elements with a greatly increased
+size. For example, Zulip the web app scales large emoji to be 2x the
+size of other message emoji.
Unicode emoji, such as `:smiling_face:` (☺️ / `263a`), are represented
in the HTML by spans with the following format:
@@ -158,6 +165,8 @@ the Zulip server's hostname:
src="/static/generated/emoji/images/emoji/unicode/zulip.png">
```
+**Changes**: Large emoji are new in Zulip 12.0 (feature level 436).
+
## Images
When a Zulip message is sent linking to an uploaded image, Zulip will
diff --git a/version.py b/version.py
index 5536cdef8dc..b4f8df6be93 100644
--- a/version.py
+++ b/version.py
@@ -35,7 +35,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 435
+API_FEATURE_LEVEL = 436
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index b35fd87a407..6f757781a78 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -12,6 +12,8 @@ export function postprocess_content(html: string): string {
const template = inertDocument.createElement("template");
template.innerHTML = html;
+ process_emoji_only_message(template.content);
+
for (const ol of template.content.querySelectorAll("ol")) {
const list_start = Number(ol.getAttribute("start") ?? 1);
// We don't count the first item in the list, as it
@@ -304,3 +306,44 @@ export function postprocess_content(html: string): string {
return template.innerHTML;
}
+
+// Process single-paragraph messages that contain only emoji.
+function process_emoji_only_message(content: DocumentFragment): void {
+ // Exit as quickly as possible when more than one child element
+ // exists or the first child element is not a paragraph.
+ if (content.childElementCount !== 1 || content.firstElementChild?.tagName !== "P") {
+ return;
+ }
+
+ // Now we look at the collection of child nodes on the single
+ // paragraph to make sure there is no text in the paragraph's
+ // text nodes.
+ const paragraph_child_nodes = content.firstElementChild?.childNodes;
+ assert(paragraph_child_nodes !== undefined);
+ for (const node of paragraph_child_nodes) {
+ if (node.nodeName === "#text" && node.textContent?.trim() !== "") {
+ // If we find a #text node that doesn't trim down
+ // to the empty string, then the message has text
+ // content, so we should exit swiftly.
+ return;
+ }
+ }
+
+ // Having gotten this far, we check the child elements to make
+ // sure there are none other than spans for system emoji or
+ // img tags for realm emoji--both of which take the .emoji class.
+ const paragraph_child_elements = content.firstElementChild?.children;
+ assert(paragraph_child_elements !== undefined);
+ for (const element of paragraph_child_elements) {
+ if (!element.classList.contains("emoji")) {
+ // Any element without the .emoji class is obviously not
+ // emoji, so we again exit swiftly.
+ return;
+ }
+ }
+
+ // If we haven't returned by now, this is an emoji-only message,
+ // so we add .emoji-only to the paragraph element for styling
+ // the emoji in CSS.
+ content.firstElementChild?.classList.add("emoji-only");
+}
diff --git a/web/styles/rendered_markdown.css b/web/styles/rendered_markdown.css
index 575929264ab..3fd460ab9d3 100644
--- a/web/styles/rendered_markdown.css
+++ b/web/styles/rendered_markdown.css
@@ -254,6 +254,15 @@
vertical-align: var(--line-fitted-vertical-align-offset-em);
}
+ /* We double the size of emoji on emoji-only messages. As there
+ is by definition no adjacent text in these messages, there is
+ no need to adjust the `margin` or `vertical-align` properties
+ declared above. */
+ .emoji-only .emoji {
+ height: calc(var(--length-line-oversize-block) * 2);
+ width: calc(var(--length-line-oversize-block) * 2);
+ }
+
/* Mentions and alert words */
.user-group-mention,
.user-mention,
diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjs
index 3952cdee5a0..be598b808c4 100644
--- a/web/tests/postprocess_content.test.cjs
+++ b/web/tests/postprocess_content.test.cjs
@@ -13,6 +13,30 @@ const {initialize_user_settings} = zrequire("user_settings");
const user_settings = {web_font_size_px: 16};
initialize_user_settings({user_settings});
+run_test("emoji_only", () => {
+ // Test emoji-only message
+ assert.equal(
+ postprocess_content(
+ '<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>',
+ ),
+ '<p class="emoji-only"><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>',
+ );
+ // Test emoji with other text content
+ assert.equal(
+ postprocess_content(
+ '<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> hi</p>',
+ ),
+ '<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> hi</p>',
+ );
+ // Test emoji with other node content
+ assert.equal(
+ postprocess_content(
+ '<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> <strong>hi</strong></p>',
+ ),
+ '<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> <strong>hi</strong></p>',
+ );
+});
+
run_test("ordered_lists", () => {
assert.equal(
postprocess_content('<ol start="9"><li>Nine</li><li>Ten</li></ol>'),