diff --git a/apps/web/playwright/snapshots/settings/preferences-user-settings-tab.spec.ts/Preferences-user-settings-tab-should-be-rendered-properly-1-linux.png b/apps/web/playwright/snapshots/settings/preferences-user-settings-tab.spec.ts/Preferences-user-settings-tab-should-be-rendered-properly-1-linux.png index 2a998720e9..ee058b786a 100644 Binary files a/apps/web/playwright/snapshots/settings/preferences-user-settings-tab.spec.ts/Preferences-user-settings-tab-should-be-rendered-properly-1-linux.png and b/apps/web/playwright/snapshots/settings/preferences-user-settings-tab.spec.ts/Preferences-user-settings-tab-should-be-rendered-properly-1-linux.png differ diff --git a/apps/web/src/components/structures/RoomView.tsx b/apps/web/src/components/structures/RoomView.tsx index b1fc5d8f18..3704cf5885 100644 --- a/apps/web/src/components/structures/RoomView.tsx +++ b/apps/web/src/components/structures/RoomView.tsx @@ -1380,12 +1380,12 @@ export class RoomView extends React.Component { if (data.timeline.getTimelineSet() !== room.getUnfilteredTimelineSet()) return; if (ev.getType() === "org.matrix.room.preview_urls") { - this.updatePreviewUrlVisibility(room); + this.updatePreviewUrlVisibility(); } if (ev.getType() === "m.room.encryption") { this.updateE2EStatus(room); - this.updatePreviewUrlVisibility(room); + this.updatePreviewUrlVisibility(); } // ignore anything but real-time updates at the end of the room: @@ -1541,15 +1541,14 @@ export class RoomView extends React.Component { }); } - private updatePreviewUrlVisibility(room: Room): void { + private updatePreviewUrlVisibility(): void { this.setState(({ isRoomEncrypted }) => ({ - showUrlPreview: this.getPreviewUrlVisibility(room, isRoomEncrypted), + showUrlPreview: this.getPreviewUrlVisibility(isRoomEncrypted), })); } - private getPreviewUrlVisibility({ roomId }: Room, isRoomEncrypted: boolean | null): boolean { - const key = isRoomEncrypted ? "urlPreviewsEnabled_e2ee" : "urlPreviewsEnabled"; - return SettingsStore.getValue(key, roomId); + private getPreviewUrlVisibility(isRoomEncrypted: boolean | null): boolean { + return SettingsStore.getValue(isRoomEncrypted ? "urlPreviewsEnabled_e2ee" : "urlPreviewsEnabled"); } private onRoom = (room: Room): void => { @@ -1608,9 +1607,7 @@ export class RoomView extends React.Component { } private onUrlPreviewsEnabledChange = (): void => { - if (this.state.room) { - this.updatePreviewUrlVisibility(this.state.room); - } + this.updatePreviewUrlVisibility(); }; private onRoomStateEvents = async (ev: MatrixEvent, state: RoomState): Promise => { @@ -1638,7 +1635,7 @@ export class RoomView extends React.Component { this.setState({ isRoomEncrypted, - showUrlPreview: this.getPreviewUrlVisibility(room, isRoomEncrypted), + showUrlPreview: this.getPreviewUrlVisibility(isRoomEncrypted), ...(newE2EStatus && { e2eStatus: newE2EStatus }), }); } diff --git a/apps/web/src/components/views/elements/SettingsFlag.tsx b/apps/web/src/components/views/elements/SettingsFlag.tsx index eb05301270..3e09b298ce 100644 --- a/apps/web/src/components/views/elements/SettingsFlag.tsx +++ b/apps/web/src/components/views/elements/SettingsFlag.tsx @@ -25,6 +25,7 @@ interface IProps { label?: string; isExplicit?: boolean; hideIfCannotSet?: boolean; + requires?: BooleanSettingKey[]; onChange?(checked: boolean): void; } @@ -45,6 +46,12 @@ export default class SettingsFlag extends React.Component { public componentDidMount(): void { defaultWatchManager.watchSetting(this.props.name, this.props.roomId ?? null, this.onSettingChange); + if (this.props.requires) { + // If we have any dependencies for this feature, also watch those features to ensure we catch the disabled state. + for (const flag of this.props.requires) { + defaultWatchManager.watchSetting(flag, this.props.roomId ?? null, this.onSettingChange); + } + } } public componentWillUnmount(): void { diff --git a/apps/web/src/components/views/room_settings/UrlPreviewSettings.tsx b/apps/web/src/components/views/room_settings/UrlPreviewSettings.tsx deleted file mode 100644 index d200f487eb..0000000000 --- a/apps/web/src/components/views/room_settings/UrlPreviewSettings.tsx +++ /dev/null @@ -1,152 +0,0 @@ -/* -Copyright 2024 New Vector Ltd. -Copyright 2019 The Matrix.org Foundation C.I.C. -Copyright 2018, 2019 New Vector Ltd -Copyright 2017 Travis Ralston -Copyright 2016 OpenMarket Ltd - -SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE files in the repository root for full details. -*/ - -import React, { type ReactNode, type JSX } from "react"; -import { type Room } from "matrix-js-sdk/src/matrix"; -import { InlineSpinner } from "@vector-im/compound-web"; - -import { _t } from "../../../languageHandler"; -import SettingsStore from "../../../settings/SettingsStore"; -import dis from "../../../dispatcher/dispatcher"; -import { Action } from "../../../dispatcher/actions"; -import { SettingLevel } from "../../../settings/SettingLevel"; -import SettingsFlag from "../elements/SettingsFlag"; -import SettingsFieldset from "../settings/SettingsFieldset"; -import AccessibleButton, { type ButtonEvent } from "../elements/AccessibleButton"; -import { useIsEncrypted } from "../../../hooks/useIsEncrypted.ts"; -import { useMatrixClientContext } from "../../../contexts/MatrixClientContext.tsx"; -import { useSettingValueAt } from "../../../hooks/useSettings.ts"; - -/** - * The URL preview settings for a room - */ -interface UrlPreviewSettingsProps { - /** - * The room. - */ - room: Room; -} - -export function UrlPreviewSettings({ room }: UrlPreviewSettingsProps): JSX.Element { - const { roomId } = room; - const matrixClient = useMatrixClientContext(); - const isEncrypted = useIsEncrypted(matrixClient, room); - const isLoading = isEncrypted === null; - - return ( - } - > - {isLoading ? ( - - ) : ( - <> - - - - )} - - ); -} - -/** - * Click handler for the user settings link - * @param e - */ -function onClickUserSettings(e: ButtonEvent): void { - e.preventDefault(); - e.stopPropagation(); - dis.fire(Action.ViewUserSettings); -} - -/** - * The description for the URL preview settings - */ -interface DescriptionProps { - /** - * Whether the room is encrypted - */ - isEncrypted: boolean; -} - -function Description({ isEncrypted }: DescriptionProps): JSX.Element { - const urlPreviewsEnabled = useSettingValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled"); - - let previewsForAccount: ReactNode | undefined; - if (isEncrypted) { - previewsForAccount = _t("room_settings|general|url_preview_encryption_warning"); - } else { - const button = { - a: (sub: string) => ( - - {sub} - - ), - }; - - previewsForAccount = urlPreviewsEnabled - ? _t("room_settings|general|user_url_previews_default_on", {}, button) - : _t("room_settings|general|user_url_previews_default_off", {}, button); - } - - return ( - <> -

{_t("room_settings|general|url_preview_explainer")}

-

{previewsForAccount}

- - ); -} - -/** - * The description for the URL preview settings - */ -interface PreviewsForRoomProps { - /** - * Whether the room is encrypted - */ - isEncrypted: boolean; - /** - * The room ID - */ - roomId: string; -} - -function PreviewsForRoom({ isEncrypted, roomId }: PreviewsForRoomProps): JSX.Element | null { - const urlPreviewsEnabled = useSettingValueAt( - SettingLevel.ACCOUNT, - "urlPreviewsEnabled", - roomId, - /*explicit=*/ true, - ); - if (isEncrypted) return null; - - let previewsForRoom: ReactNode; - if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, SettingLevel.ROOM)) { - previewsForRoom = ( - - ); - } else { - previewsForRoom = ( -
- {urlPreviewsEnabled - ? _t("room_settings|general|default_url_previews_on") - : _t("room_settings|general|default_url_previews_off")} -
- ); - } - - return previewsForRoom; -} diff --git a/apps/web/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.tsx b/apps/web/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.tsx index 4b04e4bcf3..15f3a3cefa 100644 --- a/apps/web/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.tsx +++ b/apps/web/src/components/views/settings/tabs/room/GeneralRoomSettingsTab.tsx @@ -15,14 +15,11 @@ import RoomProfileSettings from "../../../room_settings/RoomProfileSettings"; import AccessibleButton, { type ButtonEvent } from "../../../elements/AccessibleButton"; import dis from "../../../../../dispatcher/dispatcher"; import MatrixClientContext from "../../../../../contexts/MatrixClientContext"; -import SettingsStore from "../../../../../settings/SettingsStore"; -import { UIFeature } from "../../../../../settings/UIFeature"; import AliasSettings from "../../../room_settings/AliasSettings"; import PosthogTrackers from "../../../../../PosthogTrackers"; import { SettingsSubsection } from "../../shared/SettingsSubsection"; import SettingsTab from "../SettingsTab"; import { SettingsSection } from "../../shared/SettingsSection"; -import { UrlPreviewSettings } from "../../../room_settings/UrlPreviewSettings"; import { MediaPreviewAccountSettings } from "../user/MediaPreviewAccountSettings"; interface IProps { @@ -62,10 +59,6 @@ export default class GeneralRoomSettingsTab extends React.Component - ) : null; - let leaveSection; if (room.getMyMembership() === KnownMembership.Join) { leaveSection = ( @@ -99,7 +92,6 @@ export default class GeneralRoomSettingsTab extends React.Component - {urlPreviewSettings} diff --git a/apps/web/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/apps/web/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index cab58ee085..51ccb7bd3e 100644 --- a/apps/web/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/apps/web/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -147,11 +147,7 @@ export default class PreferencesUserSettingsTab extends React.Component + + + + + {this.renderGroup(PreferencesUserSettingsTab.IMAGES_AND_VIDEOS_SETTINGS)} diff --git a/apps/web/src/i18n/strings/en_EN.json b/apps/web/src/i18n/strings/en_EN.json index 3b20cda580..481a2ad478 100644 --- a/apps/web/src/i18n/strings/en_EN.json +++ b/apps/web/src/i18n/strings/en_EN.json @@ -2238,8 +2238,6 @@ "aliases_section": "Room Addresses", "avatar_field_label": "Room avatar", "canonical_alias_field_label": "Main address", - "default_url_previews_off": "URL previews are disabled by default for participants in this room.", - "default_url_previews_on": "URL previews are enabled by default for participants in this room.", "description_space": "Edit settings relating to your space.", "error_creating_alias_description": "There was an error creating that address. It may not be allowed by the server or a temporary failure occurred.", "error_creating_alias_title": "Error creating address", @@ -2270,12 +2268,7 @@ "published_aliases_explainer_space": "Published addresses can be used by anyone on any server to join your space.", "published_aliases_section": "Published Addresses", "save": "Save Changes", - "topic_field_label": "Room Topic", - "url_preview_encryption_warning": "In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.", - "url_preview_explainer": "When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website.", - "url_previews_section": "URL Previews", - "user_url_previews_default_off": "You have disabled URL previews by default.", - "user_url_previews_default_on": "You have enabled URL previews by default." + "topic_field_label": "Room Topic" }, "notifications": { "browse_button": "Browse", @@ -2697,9 +2690,8 @@ "unable_to_load_msisdns": "Unable to load phone numbers", "username": "Username" }, - "inline_url_previews_default": "Enable inline URL previews by default", - "inline_url_previews_room": "Enable URL previews by default for participants in this room", - "inline_url_previews_room_account": "Enable URL previews for this room (only affects you)", + "inline_url_previews_default": "Enable previews", + "inline_url_previews_encrypted": "Enable previews in encrypted rooms", "insert_trailing_colon_mentions": "Insert a trailing colon after user mentions at the start of a message", "invite_controls": { "default_label": "Allow users to invite you to rooms" @@ -2837,6 +2829,8 @@ "enable_tray_icon": "Show tray icon and minimise window to it on close", "keyboard_heading": "Keyboard shortcuts", "keyboard_view_shortcuts_button": "To view all keyboard shortcuts, click here.", + "link_previews_description": "Shows information about links underneath messages", + "link_previews_heading": "Link previews", "media_heading": "Images, GIFs and videos", "presence_description": "Share your activity and status with others.", "publish_timezone": "Publish timezone on public profile", diff --git a/apps/web/src/settings/Settings.tsx b/apps/web/src/settings/Settings.tsx index cb7fccc304..b70095125f 100644 --- a/apps/web/src/settings/Settings.tsx +++ b/apps/web/src/settings/Settings.tsx @@ -51,6 +51,7 @@ import MediaPreviewConfigController from "./controllers/MediaPreviewConfigContro import InviteRulesConfigController from "./controllers/InviteRulesConfigController.ts"; import { type ComputedInviteConfig } from "../@types/invite-rules.ts"; import BlockInvitesConfigController from "./controllers/BlockInvitesConfigController.ts"; +import RequiresSettingsController from "./controllers/RequiresSettingsController.ts"; export const defaultWatchManager = new WatchManager(); @@ -1140,22 +1141,22 @@ export const SETTINGS: Settings = { controller: new UIFeatureController(UIFeature.AdvancedEncryption), }, "urlPreviewsEnabled": { - supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM, - displayName: { - "default": _td("settings|inline_url_previews_default"), - "room-account": _td("settings|inline_url_previews_room_account"), - "room": _td("settings|inline_url_previews_room"), - }, + // Enabled by default and client configurable as this setting only allows unencrypted + // messages to be previewed. + supportedLevels: [SettingLevel.DEVICE, SettingLevel.ACCOUNT, SettingLevel.CONFIG], + supportedLevelsAreOrdered: true, + displayName: _td("settings|inline_url_previews_default"), default: true, controller: new UIFeatureController(UIFeature.URLPreviews), }, "urlPreviewsEnabled_e2ee": { - supportedLevels: [SettingLevel.ROOM_DEVICE], - displayName: { - "room-device": _td("settings|inline_url_previews_room_account"), - }, + // Can only be enabled per-device to ensure neither the homeserver nor client config + // can impact the user's choices. + supportedLevels: [SettingLevel.DEVICE], + supportedLevelsAreOrdered: true, + displayName: _td("settings|inline_url_previews_encrypted"), default: false, - controller: new UIFeatureController(UIFeature.URLPreviews), + controller: new RequiresSettingsController([UIFeature.URLPreviews, "urlPreviewsEnabled"]), }, "notificationsEnabled": { supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS, diff --git a/apps/web/src/settings/SettingsStore.ts b/apps/web/src/settings/SettingsStore.ts index 0852583fc1..c2f0eb98c8 100644 --- a/apps/web/src/settings/SettingsStore.ts +++ b/apps/web/src/settings/SettingsStore.ts @@ -654,40 +654,6 @@ export default class SettingsStore { return null; } - /** - * Migrate the setting for URL previews in e2e rooms from room account - * data to the room device level. - * - * @param isFreshLogin True if the user has just logged in, false if a previous session is being restored. - */ - private static async migrateURLPreviewsE2EE(isFreshLogin: boolean): Promise { - const MIGRATION_DONE_FLAG = "url_previews_e2ee_migration_done"; - if (localStorage.getItem(MIGRATION_DONE_FLAG)) return; - if (isFreshLogin) return; - - const client = MatrixClientPeg.safeGet(); - - while (!client.isInitialSyncComplete()) { - await new Promise((r) => client.once(ClientEvent.Sync, r)); - } - - logger.info("Performing one-time settings migration of URL previews in E2EE rooms"); - - const roomAccounthandler = LEVEL_HANDLERS[SettingLevel.ROOM_ACCOUNT]; - - for (const room of client.getRooms()) { - // We need to use the handler directly because this setting is no longer supported - // at this level at all - const val = roomAccounthandler.getValue("urlPreviewsEnabled_e2ee", room.roomId); - - if (val !== undefined) { - await SettingsStore.setValue("urlPreviewsEnabled_e2ee", room.roomId, SettingLevel.ROOM_DEVICE, val); - } - } - - localStorage.setItem(MIGRATION_DONE_FLAG, "true"); - } - /** * Migrate the setting for visible images to a setting. */ @@ -739,15 +705,6 @@ export default class SettingsStore { * Runs or queues any setting migrations needed. */ public static runMigrations(isFreshLogin: boolean): void { - // This can be removed once enough users have run a version of Element with - // this migration. A couple of months after its release should be sufficient - // (so around October 2024). - // The consequences of missing the migration are only that URL previews will - // be disabled in E2EE rooms. - SettingsStore.migrateURLPreviewsE2EE(isFreshLogin).catch((e) => { - logger.error("Failed to migrate URL previews in E2EE rooms:", e); - }); - // This can be removed once enough users have run a version of Element with // this migration. // The consequences of missing the migration are that previously shown images diff --git a/apps/web/src/settings/controllers/RequiresSettingsController.ts b/apps/web/src/settings/controllers/RequiresSettingsController.ts new file mode 100644 index 0000000000..a5bbc4b26b --- /dev/null +++ b/apps/web/src/settings/controllers/RequiresSettingsController.ts @@ -0,0 +1,34 @@ +/* +Copyright 2026 Element Creations Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE files in the repository root for full details. +*/ + +import SettingController from "./SettingController"; +import SettingsStore from "../SettingsStore"; +import type { BooleanSettingKey } from "../Settings.tsx"; + +/** + * Disables a setting & forces it's value if one or more settings are not enabled + */ +export default class RequiresSettingsController extends SettingController { + public constructor( + public readonly settingNames: BooleanSettingKey[], + private forcedValue = false, + ) { + super(); + } + + public getValueOverride(): any { + if (this.settingDisabled) { + // per the docs: we force a disabled state when the feature isn't active + return this.forcedValue; + } + return null; // no override + } + + public get settingDisabled(): boolean { + return this.settingNames.some((s) => !SettingsStore.getValue(s)); + } +} diff --git a/apps/web/src/settings/handlers/RoomAccountSettingsHandler.ts b/apps/web/src/settings/handlers/RoomAccountSettingsHandler.ts index 939c267a15..5da1a0c5f0 100644 --- a/apps/web/src/settings/handlers/RoomAccountSettingsHandler.ts +++ b/apps/web/src/settings/handlers/RoomAccountSettingsHandler.ts @@ -76,15 +76,6 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin }; public getValue(settingName: string, roomId: string): any { - // Special case URL previews - if (settingName === "urlPreviewsEnabled") { - const content = this.getSettings(roomId, "org.matrix.room.preview_urls") || {}; - - // Check to make sure that we actually got a boolean - if (typeof content["disable"] !== "boolean") return null; - return !content["disable"]; - } - // Special case allowed widgets if (settingName === "allowedWidgets") { return this.getSettings(roomId, ALLOWED_WIDGETS_EVENT_TYPE); diff --git a/apps/web/test/unit-tests/components/views/room_settings/UrlPreviewSettings-test.tsx b/apps/web/test/unit-tests/components/views/room_settings/UrlPreviewSettings-test.tsx deleted file mode 100644 index 23e9b12682..0000000000 --- a/apps/web/test/unit-tests/components/views/room_settings/UrlPreviewSettings-test.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2024 New Vector Ltd. - * - * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial - * Please see LICENSE files in the repository root for full details. - */ - -import React from "react"; -import { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix"; -import { render, screen } from "jest-matrix-react"; -import { waitFor } from "@testing-library/dom"; -import { Form } from "@vector-im/compound-web"; - -import { createTestClient, mkStubRoom, withClientContextRenderOptions } from "../../../../test-utils"; -import { UrlPreviewSettings } from "../../../../../src/components/views/room_settings/UrlPreviewSettings.tsx"; -import SettingsStore from "../../../../../src/settings/SettingsStore.ts"; -import dis from "../../../../../src/dispatcher/dispatcher.ts"; -import { Action } from "../../../../../src/dispatcher/actions.ts"; - -describe("UrlPreviewSettings", () => { - let client: MatrixClient; - let room: Room; - - beforeEach(() => { - client = createTestClient(); - room = mkStubRoom("roomId", "room", client); - }); - - afterEach(() => { - jest.restoreAllMocks(); - }); - - function renderComponent() { - return render( - - - , - withClientContextRenderOptions(client), - ); - } - - it("should display the correct preview when the setting is in a loading state", () => { - jest.spyOn(client, "getCrypto").mockReturnValue(undefined); - const { asFragment } = renderComponent(); - expect(screen.getByText("URL Previews")).toBeInTheDocument(); - - expect(asFragment()).toMatchSnapshot(); - }); - - it("should display the correct preview when the room is encrypted and the url preview is enabled", async () => { - jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true); - jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(true); - - const { asFragment } = renderComponent(); - await waitFor(() => { - expect( - screen.getByText( - "In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.", - ), - ).toBeInTheDocument(); - }); - expect(asFragment()).toMatchSnapshot(); - }); - - it("should display the correct preview when the room is unencrypted and the url preview is enabled", async () => { - jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false); - jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(true); - jest.spyOn(dis, "fire").mockReturnValue(undefined); - - const { asFragment } = renderComponent(); - await waitFor(() => { - expect(screen.getByRole("button", { name: "enabled" })).toBeInTheDocument(); - expect( - screen.getByText("URL previews are enabled by default for participants in this room."), - ).toBeInTheDocument(); - }); - expect(asFragment()).toMatchSnapshot(); - - screen.getByRole("button", { name: "enabled" }).click(); - expect(dis.fire).toHaveBeenCalledWith(Action.ViewUserSettings); - }); - - it("should display the correct preview when the room is unencrypted and the url preview is disabled", async () => { - jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false); - jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(false); - - const { asFragment } = renderComponent(); - await waitFor(() => { - expect(screen.getByRole("button", { name: "disabled" })).toBeInTheDocument(); - expect( - screen.getByText("URL previews are disabled by default for participants in this room."), - ).toBeInTheDocument(); - }); - expect(asFragment()).toMatchSnapshot(); - }); -}); diff --git a/apps/web/test/unit-tests/components/views/room_settings/__snapshots__/UrlPreviewSettings-test.tsx.snap b/apps/web/test/unit-tests/components/views/room_settings/__snapshots__/UrlPreviewSettings-test.tsx.snap deleted file mode 100644 index 473cf67a1d..0000000000 --- a/apps/web/test/unit-tests/components/views/room_settings/__snapshots__/UrlPreviewSettings-test.tsx.snap +++ /dev/null @@ -1,270 +0,0 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing - -exports[`UrlPreviewSettings should display the correct preview when the room is encrypted and the url preview is enabled 1`] = ` - -
-
- - URL Previews - -
-
-

- When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website. -

-

- In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room. -

-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-`; - -exports[`UrlPreviewSettings should display the correct preview when the room is unencrypted and the url preview is disabled 1`] = ` - -
-
- - URL Previews - -
-
-

- When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website. -

-

- - You have - -

- - URL previews by default. -

-

-
-
-
- URL previews are disabled by default for participants in this room. -
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-`; - -exports[`UrlPreviewSettings should display the correct preview when the room is unencrypted and the url preview is enabled 1`] = ` - -
-
- - URL Previews - -
-
-

- When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website. -

-

- - You have - -

- - URL previews by default. -

-

-
-
-
- URL previews are enabled by default for participants in this room. -
-
-
-
- -
-
-
-
- -
-
-
-
-
-
-`; - -exports[`UrlPreviewSettings should display the correct preview when the setting is in a loading state 1`] = ` - -
-
- - URL Previews - -
- - - -
-
-
-
-`; diff --git a/apps/web/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap b/apps/web/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap index 21d6d2dee3..febcc13a7b 100644 --- a/apps/web/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap +++ b/apps/web/test/unit-tests/components/views/settings/tabs/user/__snapshots__/PreferencesUserSettingsTab-test.tsx.snap @@ -905,9 +905,18 @@ exports[`PreferencesUserSettingsTab should render 1`] = `

- Images, GIFs and videos + Link previews

+
+
+ Shows information about links underneath messages +
+
@@ -923,7 +932,6 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` - Enable inline URL previews by default + Enable previews
@@ -955,7 +963,6 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > - Autoplay GIFs + Enable previews in encrypted rooms + + + +
+
+
+

+ Images, GIFs and videos +

+
+
@@ -1003,6 +1031,38 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` +
+
+
+
+
+ +
+
+
+
+ @@ -1029,39 +1089,6 @@ exports[`PreferencesUserSettingsTab should render 1`] = `
-
-
-
- -
-
-
-
- -
-
@@ -1091,7 +1118,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_q1SIAPqLMVXh" > - Show a placeholder for removed messages + Show typing notifications
@@ -1124,7 +1151,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_dXFDGgBsKXay" > - Show read receipts sent by other users + Show a placeholder for removed messages
@@ -1157,7 +1184,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_7Az0xw4Bs4Tt" > - Show join/leave messages (invites/removes/bans unaffected) + Show read receipts sent by other users
@@ -1190,7 +1217,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_8jmzPIlPoBCv" > - Show display name changes + Show join/leave messages (invites/removes/bans unaffected)
@@ -1223,7 +1250,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_enFRaTjdsFou" > - Show chat effects (animations when receiving e.g. confetti) + Show display name changes @@ -1256,7 +1283,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_bfwnd5rz4XNX" > - Show profile picture changes + Show chat effects (animations when receiving e.g. confetti) @@ -1289,7 +1316,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_gs5uWEzYzZrS" > - Show avatars in user, room and event mentions + Show profile picture changes @@ -1322,7 +1349,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_qWg7OgID1yRR" > - Enable big emoji in chat + Show avatars in user, room and event mentions @@ -1355,7 +1382,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` class="_label_19upo_59" for="mx_SettingsFlag_pOPewl7rtMbV" > - Jump to the bottom of the timeline when you send a message + Enable big emoji in chat @@ -1387,6 +1414,39 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` + + +
+
+
+ +
+
+
+
+ @@ -1424,7 +1484,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > @@ -1438,7 +1498,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > @@ -1452,13 +1512,13 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > A hidden media can always be shown by tapping on it @@ -1571,7 +1631,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` checked="" class="_input_udcm8_24" disabled="" - id="_r_2b_" + id="_r_2d_" role="switch" type="checkbox" /> @@ -1585,13 +1645,13 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > Your server does not implement this feature. @@ -1636,7 +1696,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` @@ -1650,7 +1710,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > @@ -1690,7 +1750,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` checked="" class="_input_udcm8_24" disabled="" - id="mx_SettingsFlag_SBSSOZDRlzlA" + id="mx_SettingsFlag_FLEpLCb0jpp6" role="switch" type="checkbox" /> @@ -1704,7 +1764,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = ` > diff --git a/apps/web/test/unit-tests/settings/SettingsStore-test.ts b/apps/web/test/unit-tests/settings/SettingsStore-test.ts index 0987569bb9..2452456bf0 100644 --- a/apps/web/test/unit-tests/settings/SettingsStore-test.ts +++ b/apps/web/test/unit-tests/settings/SettingsStore-test.ts @@ -96,63 +96,18 @@ describe("SettingsStore", () => { describe("runMigrations", () => { let client: MatrixClient; let room: Room; - let localStorageSetItemSpy: jest.SpyInstance; - let localStorageSetPromise: Promise; beforeEach(() => { client = stubClient(); room = mkStubRoom("!room:example.org", "Room", client); - room.getAccountData = jest.fn().mockReturnValue({ - getContent: jest.fn().mockReturnValue({ - urlPreviewsEnabled_e2ee: true, - }), - }); client.getRooms = jest.fn().mockReturnValue([room]); client.getRoom = jest.fn().mockReturnValue(room); - - localStorageSetPromise = new Promise((resolve) => { - localStorageSetItemSpy = jest - .spyOn(localStorage.__proto__, "setItem") - .mockImplementation(() => resolve()); - }); }); afterEach(() => { jest.restoreAllMocks(); }); - it("migrates URL previews setting for e2ee rooms", async () => { - SettingsStore.runMigrations(false); - client.emit(ClientEvent.Sync, SyncState.Prepared, null); - - expect(room.getAccountData).toHaveBeenCalled(); - - await localStorageSetPromise; - - expect(localStorageSetItemSpy!).toHaveBeenCalledWith( - `mx_setting_urlPreviewsEnabled_e2ee_${room.roomId}`, - JSON.stringify({ value: true }), - ); - }); - - it("does not migrate e2ee URL previews on a fresh login", async () => { - SettingsStore.runMigrations(true); - client.emit(ClientEvent.Sync, SyncState.Prepared, null); - - expect(room.getAccountData).not.toHaveBeenCalled(); - }); - - it("does not migrate if the device is flagged as migrated", async () => { - jest.spyOn(localStorage.__proto__, "getItem").mockImplementation((key: unknown): string | undefined => { - if (key === "url_previews_e2ee_migration_done") return JSON.stringify({ value: true }); - return undefined; - }); - SettingsStore.runMigrations(false); - client.emit(ClientEvent.Sync, SyncState.Prepared, null); - - expect(room.getAccountData).not.toHaveBeenCalled(); - }); - describe("Migrate media preview configuration", () => { beforeEach(() => { MatrixClientBackedController.matrixClient = client; diff --git a/apps/web/test/unit-tests/settings/controllers/RequiresSettingsController-test.ts b/apps/web/test/unit-tests/settings/controllers/RequiresSettingsController-test.ts new file mode 100644 index 0000000000..dafd7c8896 --- /dev/null +++ b/apps/web/test/unit-tests/settings/controllers/RequiresSettingsController-test.ts @@ -0,0 +1,33 @@ +/* +Copyright 2026 Element Creations Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE files in the repository root for full details. +*/ + +import RequiresSettingsController from "../../../../src/settings/controllers/RequiresSettingsController"; +import { SettingLevel } from "../../../../src/settings/SettingLevel"; +import SettingsStore from "../../../../src/settings/SettingsStore"; + +describe("RequiresSettingsController", () => { + afterEach(() => { + SettingsStore.reset(); + }); + + it("forces a value if a setting is false", async () => { + const forcedValue = true; + await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, true); + await SettingsStore.setValue("useCustomFontSize", null, SettingLevel.DEVICE, false); + const controller = new RequiresSettingsController(["useCompactLayout", "useCustomFontSize"], forcedValue); + expect(controller.settingDisabled).toEqual(true); + expect(controller.getValueOverride()).toEqual(forcedValue); + }); + + it("does not force a value if all settings are true", async () => { + const controller = new RequiresSettingsController(["useCompactLayout", "useCustomFontSize"]); + await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, true); + await SettingsStore.setValue("useCustomFontSize", null, SettingLevel.DEVICE, true); + expect(controller.settingDisabled).toEqual(false); + expect(controller.getValueOverride()).toEqual(null); + }); +});