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.

message_content: Apply media_preview_size to rendering.

Alya Abbottabbb5d294094
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts
index 0037b313cc6..3685d5140f5 100644
--- a/web/src/postprocess_content.ts
+++ b/web/src/postprocess_content.ts
@@ -276,8 +276,8 @@ export function postprocess_content(html: string): string {
// use a subtler background color than on other images
const image_min_aspect_ratio = 0.4;
// "Dinky" images are those that are shorter than the
- // 10em height reserved for thumbnails
- const image_box_em = 10;
+ // height reserved for thumbnails
+ const image_box_em = thumbnail.get_media_preview_size();
const is_dinky_image = original_height / font_size_in_use <= image_box_em;
const has_extreme_aspect_ratio =
original_width / original_height <= image_min_aspect_ratio ||
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js
index 4e86ff2b09c..35cbfac5b3e 100644
--- a/web/src/server_events_dispatch.js
+++ b/web/src/server_events_dispatch.js
@@ -91,6 +91,7 @@ import * as stream_ui_updates from "./stream_ui_updates.ts";
import * as sub_store from "./sub_store.ts";
import * as submessage from "./submessage.ts";
import * as theme from "./theme.ts";
+import * as thumbnail from "./thumbnail.ts";
import {group_setting_value_schema} from "./types.ts";
import * as typing_events from "./typing_events.ts";
import * as unread_ops from "./unread_ops.ts";
@@ -308,7 +309,7 @@ export function dispatch_normal_event(event) {
direct_message_permission_group: noop,
email_changes_disabled: settings_account.update_email_change_display,
disallow_disposable_email_addresses: noop,
- media_preview_size: noop,
+ media_preview_size: thumbnail.update_thumbnails,
inline_image_preview: noop,
inline_url_embed_preview: noop,
invite_required: noop,
diff --git a/web/src/thumbnail.ts b/web/src/thumbnail.ts
index 677ef18ce69..1703a4be6fe 100644
--- a/web/src/thumbnail.ts
+++ b/web/src/thumbnail.ts
@@ -1,5 +1,7 @@
+import $ from "jquery";
import type * as z from "zod/mini";
+import * as message_lists from "./message_lists.ts";
import {realm} from "./state_data.ts";
import type {thumbnail_format_schema} from "./state_data.ts";
@@ -10,6 +12,24 @@ export const thumbnail_formats: ThumbnailFormat[] = [];
export let preferred_format: ThumbnailFormat;
export let animated_format: ThumbnailFormat;
+const DEFAULT_PREVIEW_SIZE_EM = 10;
+
+export function set_media_preview_size_css_variable(): void {
+ const size_em = (realm.realm_media_preview_size / 100) * DEFAULT_PREVIEW_SIZE_EM;
+ $(":root").css("--media-preview-max-height", `${size_em}em`);
+}
+
+export function get_media_preview_size(): number {
+ return (realm.realm_media_preview_size / 100) * DEFAULT_PREVIEW_SIZE_EM;
+}
+
+export function update_thumbnails(): void {
+ set_media_preview_size_css_variable();
+ for (const msg_list of message_lists.all_rendered_message_lists()) {
+ msg_list.rerender();
+ }
+}
+
export function initialize(): void {
// Go looking for the size closest to 840px wide. We assume all browsers
// support webp.
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index b26132e4cc6..4ecadc19ab0 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -470,6 +470,7 @@ export async function initialize_everything(state_data) {
theme.initialize_theme_for_spectator();
}
thumbnail.initialize();
+ thumbnail.set_media_preview_size_css_variable();
widgets.initialize();
tippyjs.initialize();
compose_tooltips.initialize();
diff --git a/web/styles/app_variables.css b/web/styles/app_variables.css
index cf4e878ccbc..aee9293d79c 100644
--- a/web/styles/app_variables.css
+++ b/web/styles/app_variables.css
@@ -368,6 +368,9 @@
--user-card-popover-min-width: 200px;
--stream-card-popover-min-width: 16.4285em;
+ /* Image and video thumbnail sizing; updated via JavaScript */
+ --media-preview-max-height: 10em;
+
/* Information density and typography values */
/* The legacy values here are updated via JavaScript */
--base-font-size-px: 14px;
diff --git a/web/styles/rendered_markdown.css b/web/styles/rendered_markdown.css
index c658d720b26..94477a2377d 100644
--- a/web/styles/rendered_markdown.css
+++ b/web/styles/rendered_markdown.css
@@ -576,10 +576,11 @@
min-width: 4em;
min-height: 4em;
- /* Constrain height to 10em, but otherwise keep
+ /* Constrain height based on the organization's
+ media preview size setting, but otherwise keep
the width to the size of the gallery, and
therefore the message area. */
- max-height: 10em;
+ max-height: var(--media-preview-max-height);
max-width: 100%;
/* Allow height and width to grow as needed, though
@@ -691,9 +692,9 @@
/* Since we do not yet read height and width
values for media thumbnails, we carry forward
reasonable dimensions for a landscape thumbnail
- here. */
- height: 8em;
- width: 12em;
+ here, scaling with the image thumbnail size setting. */
+ height: var(--media-preview-max-height);
+ width: calc(var(--media-preview-max-height) * 1.5);
}
}
diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjs
index ee06d95c5d0..e7050c03a5a 100644
--- a/web/tests/dispatch.test.cjs
+++ b/web/tests/dispatch.test.cjs
@@ -47,6 +47,9 @@ const message_events = mock_esm("../src/message_events", {
update_current_view_for_topic_visibility: noop,
});
const message_lists = mock_esm("../src/message_lists");
+mock_esm("../src/thumbnail", {
+ update_thumbnails: noop,
+});
const user_topics_ui = mock_esm("../src/user_topics_ui");
const muted_users_ui = mock_esm("../src/muted_users_ui");
const narrow_title = mock_esm("../src/narrow_title");
diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjs
index 29cd1fbe406..6132a098839 100644
--- a/web/tests/postprocess_content.test.cjs
+++ b/web/tests/postprocess_content.test.cjs
@@ -5,7 +5,11 @@ const assert = require("node:assert/strict");
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
-const thumbnail = mock_esm("../src/thumbnail");
+const thumbnail = mock_esm("../src/thumbnail", {
+ get_media_preview_size() {
+ return 10;
+ },
+});
const {postprocess_content} = zrequire("postprocess_content");
const {initialize_user_settings} = zrequire("user_settings");