Disable URL previews per-message when the message provides a hint (#33775)

* Disable URL previews if the message requests it.

* Use MSC4095

* Expose type

* Document MSC

* cleanup

* cleanup
This commit is contained in:
Will Hunt
2026-06-09 10:40:41 +00:00
committed by GitHub
parent a2a9800393
commit 925c762859
3 changed files with 42 additions and 6 deletions
+1 -1
View File
@@ -1140,7 +1140,7 @@ export const SETTINGS: Settings = {
"urlPreviewsEnabled": {
// Enabled by default and client configurable as this setting only allows unencrypted
// messages to be previewed.
supportedLevels: [SettingLevel.DEVICE, SettingLevel.ACCOUNT, SettingLevel.CONFIG],
supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.DEVICE, SettingLevel.ACCOUNT, SettingLevel.CONFIG],
supportedLevelsAreOrdered: true,
displayName: _td("settings|inline_url_previews_default"),
default: true,
@@ -37,6 +37,8 @@ export const PREVIEW_WIDTH_PX = 478;
export const PREVIEW_HEIGHT_PX = 200;
export const MIN_PREVIEW_PX = 96;
export const MIN_IMAGE_SIZE_BYTES = 8192;
// From https://github.com/matrix-org/matrix-spec-proposals/pull/4095
export const BUNDLED_LINK_PREVIEWS = "com.beeper.linkpreviews";
export enum PreviewVisibility {
/**
@@ -387,6 +389,18 @@ export class UrlPreviewGroupViewModel
* for the previously-calculated links.
*/
private async computeSnapshot(): Promise<void> {
// This uses MSC4095. If the sender has sent us an empty URL previews bundle
// then they do not want to have URL previews be visible.
const bundledLinkPreviews = this.props.mxEvent.getContent()[BUNDLED_LINK_PREVIEWS];
if (Array.isArray(bundledLinkPreviews) && bundledLinkPreviews.length === 0) {
return this.snapshot.merge({
previews: [],
totalPreviewCount: 0,
previewsLimited: false,
overPreviewLimit: false,
});
} // otherwise, we do not support bundled previews yet so will fallback to old behaviour.
const previews =
this.visibility <= PreviewVisibility.UserHidden
? []