Global configuration flag for media previews (#29582)
* Modify useMediaVisible to take a room. * Add initial support for a account data level key. * Update controls. * Update settings * Lint and fixes * make some tests go happy * lint * i18n * update preferences * prettier * Update settings tab. * update screenshot * Update docs * Rewrite controller * Rewrite tons of tests * Rewrite RoomAvatar to be a functional component This is so we can use hooks to determine the setting state. * lint * lint * Tidy up comments * Apply media visible hook to inline images. * Move conditionals. * copyright all the things * Review changes * Update html utils to properly discard media. * Types fix * Fixing tests that break settings getValue expectations * Fix logic around media preview calculation * Fix room header tests * Fixup tests for timelinePanel * Clear settings in matrixchat * Update tests to use SettingsStore where possible. * fix bug * revert changes to client.ts * copyright years * Add header * Add a test for MediaPreviewAccountSettingsTab * Mark initMatrixClient as optional * Improve on types * Ensure we do not set the account data twice. * lint * Review changes * Ensure we include the client on rendered messages. * Fix test * update labels * clean designs * update settings tab * update snapshot * copyright * prevent mutation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019-2024 New Vector Ltd.
|
||||
Copyright 2019-2025 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.
|
||||
@@ -22,6 +22,7 @@ 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 {
|
||||
room: Room;
|
||||
@@ -92,6 +93,9 @@ export default class GeneralRoomSettingsTab extends React.Component<IProps, ISta
|
||||
|
||||
<SettingsSection heading={_t("room_settings|general|other_section")}>
|
||||
{urlPreviewSettings}
|
||||
<SettingsSubsection heading={_t("common|moderation_and_safety")} legacy={false}>
|
||||
<MediaPreviewAccountSettings roomId={room.roomId} />
|
||||
</SettingsSubsection>
|
||||
{leaveSection}
|
||||
</SettingsSection>
|
||||
</SettingsTab>
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
Copyright 2025 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, { type ChangeEventHandler, useCallback } from "react";
|
||||
import { Field, HelpMessage, InlineField, Label, RadioInput, Root } from "@vector-im/compound-web";
|
||||
|
||||
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch";
|
||||
import { type MediaPreviewConfig, MediaPreviewValue } from "../../../../../@types/media_preview";
|
||||
import { _t } from "../../../../../languageHandler";
|
||||
import { useSettingValue } from "../../../../../hooks/useSettings";
|
||||
import SettingsStore from "../../../../../settings/SettingsStore";
|
||||
import { SettingLevel } from "../../../../../settings/SettingLevel";
|
||||
|
||||
export const MediaPreviewAccountSettings: React.FC<{ roomId?: string }> = ({ roomId }) => {
|
||||
const currentMediaPreview = useSettingValue("mediaPreviewConfig", roomId);
|
||||
|
||||
const changeSetting = useCallback(
|
||||
(newValue: MediaPreviewConfig) => {
|
||||
SettingsStore.setValue(
|
||||
"mediaPreviewConfig",
|
||||
roomId ?? null,
|
||||
roomId ? SettingLevel.ROOM_ACCOUNT : SettingLevel.ACCOUNT,
|
||||
newValue,
|
||||
);
|
||||
},
|
||||
[roomId],
|
||||
);
|
||||
|
||||
const avatarOnChange = useCallback(
|
||||
(c: boolean) => {
|
||||
changeSetting({
|
||||
...currentMediaPreview,
|
||||
// Switch is inverted. "Hide avatars..."
|
||||
invite_avatars: c ? MediaPreviewValue.Off : MediaPreviewValue.On,
|
||||
});
|
||||
},
|
||||
[changeSetting, currentMediaPreview],
|
||||
);
|
||||
|
||||
const mediaPreviewOnChangeOff = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
||||
(event) => {
|
||||
if (!event.target.checked) {
|
||||
return;
|
||||
}
|
||||
changeSetting({
|
||||
...currentMediaPreview,
|
||||
media_previews: MediaPreviewValue.Off,
|
||||
});
|
||||
},
|
||||
[changeSetting, currentMediaPreview],
|
||||
);
|
||||
|
||||
const mediaPreviewOnChangePrivate = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
||||
(event) => {
|
||||
if (!event.target.checked) {
|
||||
return;
|
||||
}
|
||||
changeSetting({
|
||||
...currentMediaPreview,
|
||||
media_previews: MediaPreviewValue.Private,
|
||||
});
|
||||
},
|
||||
[changeSetting, currentMediaPreview],
|
||||
);
|
||||
|
||||
const mediaPreviewOnChangeOn = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
||||
(event) => {
|
||||
if (!event.target.checked) {
|
||||
return;
|
||||
}
|
||||
changeSetting({
|
||||
...currentMediaPreview,
|
||||
media_previews: MediaPreviewValue.On,
|
||||
});
|
||||
},
|
||||
[changeSetting, currentMediaPreview],
|
||||
);
|
||||
|
||||
return (
|
||||
<Root className="mx_MediaPreviewAccountSetting_Form">
|
||||
{!roomId && (
|
||||
<LabelledToggleSwitch
|
||||
className="mx_MediaPreviewAccountSetting_ToggleSwitch"
|
||||
label={_t("settings|media_preview|hide_avatars")}
|
||||
value={currentMediaPreview.invite_avatars === MediaPreviewValue.Off}
|
||||
onChange={avatarOnChange}
|
||||
/>
|
||||
)}
|
||||
{/* Explict label here because htmlFor is not supported for linking to radiogroups */}
|
||||
<Field
|
||||
id="mx_media_previews"
|
||||
role="radiogroup"
|
||||
name="media_previews"
|
||||
aria-label={_t("settings|media_preview|media_preview_label")}
|
||||
>
|
||||
<Label>{_t("settings|media_preview|media_preview_label")}</Label>
|
||||
<HelpMessage className="mx_MediaPreviewAccountSetting_RadioHelp">
|
||||
{_t("settings|media_preview|media_preview_description")}
|
||||
</HelpMessage>
|
||||
<InlineField
|
||||
name="media_preview_off"
|
||||
className="mx_MediaPreviewAccountSetting_Radio"
|
||||
control={
|
||||
<RadioInput
|
||||
id="mx_media_previews_off"
|
||||
checked={currentMediaPreview.media_previews === MediaPreviewValue.Off}
|
||||
onChange={mediaPreviewOnChangeOff}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Label htmlFor="mx_media_previews_off">{_t("settings|media_preview|hide_media")}</Label>
|
||||
</InlineField>
|
||||
{!roomId && (
|
||||
<InlineField
|
||||
name="mx_media_previews_private"
|
||||
className="mx_MediaPreviewAccountSetting_Radio"
|
||||
control={
|
||||
<RadioInput
|
||||
id="mx_media_previews_private"
|
||||
checked={currentMediaPreview.media_previews === MediaPreviewValue.Private}
|
||||
onChange={mediaPreviewOnChangePrivate}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Label htmlFor="mx_media_previews_private">
|
||||
{_t("settings|media_preview|show_in_private")}
|
||||
</Label>
|
||||
</InlineField>
|
||||
)}
|
||||
<InlineField
|
||||
name="media_preview_on"
|
||||
className="mx_MediaPreviewAccountSetting_Radio"
|
||||
control={
|
||||
<RadioInput
|
||||
id="mx_media_previews_on"
|
||||
checked={currentMediaPreview.media_previews === MediaPreviewValue.On}
|
||||
onChange={mediaPreviewOnChangeOn}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Label htmlFor="mx_media_previews_on">{_t("settings|media_preview|show_media")}</Label>
|
||||
</InlineField>
|
||||
</Field>
|
||||
</Root>
|
||||
);
|
||||
};
|
||||
@@ -32,6 +32,7 @@ import SpellCheckSettings from "../../SpellCheckSettings";
|
||||
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch";
|
||||
import * as TimezoneHandler from "../../../../../TimezoneHandler";
|
||||
import { type BooleanSettingKey } from "../../../../../settings/Settings.tsx";
|
||||
import { MediaPreviewAccountSettings } from "./MediaPreviewAccountSettings.tsx";
|
||||
|
||||
interface IProps {
|
||||
closeSettingsFn(success: boolean): void;
|
||||
@@ -116,7 +117,7 @@ const SpellCheckSection: React.FC = () => {
|
||||
};
|
||||
|
||||
export default class PreferencesUserSettingsTab extends React.Component<IProps, IState> {
|
||||
private static ROOM_LIST_SETTINGS: BooleanSettingKey[] = ["breadcrumbs", "showAvatarsOnInvites"];
|
||||
private static ROOM_LIST_SETTINGS: BooleanSettingKey[] = ["breadcrumbs"];
|
||||
|
||||
private static SPACES_SETTINGS: BooleanSettingKey[] = ["Spaces.allRoomsInHome"];
|
||||
|
||||
@@ -146,7 +147,6 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
"urlPreviewsEnabled",
|
||||
"autoplayGifs",
|
||||
"autoplayVideo",
|
||||
"showImages",
|
||||
];
|
||||
|
||||
private static TIMELINE_SETTINGS: BooleanSettingKey[] = [
|
||||
@@ -335,6 +335,10 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
||||
{this.renderGroup(PreferencesUserSettingsTab.TIMELINE_SETTINGS)}
|
||||
</SettingsSubsection>
|
||||
|
||||
<SettingsSubsection heading={_t("common|moderation_and_safety")} legacy={false}>
|
||||
<MediaPreviewAccountSettings />
|
||||
</SettingsSubsection>
|
||||
|
||||
<SettingsSubsection heading={_t("settings|preferences|room_directory_heading")}>
|
||||
{this.renderGroup(PreferencesUserSettingsTab.ROOM_DIRECTORY_SETTINGS)}
|
||||
</SettingsSubsection>
|
||||
|
||||
Reference in New Issue
Block a user