make some tests go happy
This commit is contained in:
2
src/@types/matrix-js-sdk.d.ts
vendored
2
src/@types/matrix-js-sdk.d.ts
vendored
@@ -14,7 +14,7 @@ import type { EncryptedFile } from "matrix-js-sdk/src/types";
|
||||
import type { EmptyObject } from "matrix-js-sdk/src/matrix";
|
||||
import type { DeviceClientInformation } from "../utils/device/types.ts";
|
||||
import type { UserWidget } from "../utils/WidgetUtils-types.ts";
|
||||
import { MediaPreviewConfig } from "./media_preview.ts";
|
||||
import { type MediaPreviewConfig } from "./media_preview.ts";
|
||||
|
||||
// Extend Matrix JS SDK types via Typescript declaration merging to support unspecced event fields and types
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
export enum MediaPreviewValue {
|
||||
On = "on",
|
||||
Private = "private",
|
||||
|
||||
@@ -52,7 +52,7 @@ export const transformTags: NonNullable<IOptions["transformTags"]> = {
|
||||
// images" preference is disabled. Future work might expose some UI to reveal them
|
||||
// like standalone image events have.
|
||||
// TODO: Is this a private room?
|
||||
if (!src || SettingsStore.getValue("mediaPreviewConfig").media_previews !== MediaPreviewValue.On ) {
|
||||
if (!src || SettingsStore.getValue("mediaPreviewConfig").media_previews !== MediaPreviewValue.On) {
|
||||
return { tagName, attribs: {} };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import React, { ChangeEventHandler } from "react";
|
||||
/*
|
||||
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 { useCallback } from "react";
|
||||
import { MediaPreviewConfig, MediaPreviewValue } from "../../../../../@types/media_preview";
|
||||
import { type MediaPreviewConfig, MediaPreviewValue } from "../../../../../@types/media_preview";
|
||||
import { _t } from "../../../../../languageHandler";
|
||||
import { useSettingValue } from "../../../../../hooks/useSettings";
|
||||
import SettingsStore from "../../../../../settings/SettingsStore";
|
||||
@@ -15,7 +22,7 @@ export function MediaPreviewAccountSettings() {
|
||||
(c: boolean) => {
|
||||
const newValue = {
|
||||
...currentMediaPreview,
|
||||
// N.B. Switch is inverted. "Hide avatars..."
|
||||
// Switch is inverted. "Hide avatars..."
|
||||
invite_avatars: c ? MediaPreviewValue.Off : MediaPreviewValue.On,
|
||||
} satisfies MediaPreviewConfig;
|
||||
SettingsStore.setValue("mediaPreviewConfig", null, SettingLevel.ACCOUNT, newValue);
|
||||
|
||||
@@ -6,12 +6,12 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { SettingLevel } from "../settings/SettingLevel";
|
||||
import { useSettingValue } from "./useSettings";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { useMatrixClientContext } from "../contexts/MatrixClientContext";
|
||||
import { JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
import { MediaPreviewValue } from "../@types/media_preview";
|
||||
|
||||
const PRIVATE_JOIN_RULES: JoinRule[] = [JoinRule.Invite, JoinRule.Knock, JoinRule.Restricted];
|
||||
@@ -36,18 +36,19 @@ export function useMediaVisible(eventId: string, roomId: string): [boolean, (vis
|
||||
);
|
||||
|
||||
const roomIsPrivate = useMemo(() => {
|
||||
const joinRule = client.getRoom(roomId)?.getJoinRule();
|
||||
const joinRule = client?.getRoom(roomId)?.getJoinRule();
|
||||
if (PRIVATE_JOIN_RULES.includes(joinRule as JoinRule)) {
|
||||
return true;
|
||||
} else { // All other join rules, and unknown will default to hiding.
|
||||
} else {
|
||||
// All other join rules, and unknown will default to hiding.
|
||||
return false;
|
||||
}
|
||||
}, [client, roomId])
|
||||
|
||||
}, [client, roomId]);
|
||||
|
||||
const explicitEventVisiblity = eventVisibility[eventId];
|
||||
// Always prefer the explicit per-event user preference here.
|
||||
if (eventVisibility[eventId]) {
|
||||
return [true, setMediaVisible];
|
||||
if (explicitEventVisiblity !== undefined) {
|
||||
return [explicitEventVisiblity, setMediaVisible];
|
||||
} else if (mediaPreviewSetting.media_previews === MediaPreviewValue.Off) {
|
||||
return [false, setMediaVisible];
|
||||
} else if (mediaPreviewSetting.media_previews === MediaPreviewValue.On) {
|
||||
@@ -59,5 +60,4 @@ export function useMediaVisible(eventId: string, roomId: string): [boolean, (vis
|
||||
console.warn("Invalid media visibility setting", mediaPreviewSetting.media_previews);
|
||||
return [false, setMediaVisible];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import React, { type ReactNode } from "react";
|
||||
import { UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/matrix";
|
||||
import { MediaPreviewConfig } from "../@types/media_preview.ts";
|
||||
|
||||
import { type MediaPreviewConfig } from "../@types/media_preview.ts";
|
||||
import { _t, _td, type TranslationKey } from "../languageHandler";
|
||||
import DeviceIsolationModeController from "./controllers/DeviceIsolationModeController.ts";
|
||||
import {
|
||||
|
||||
@@ -374,6 +374,10 @@ export default class SettingsStore {
|
||||
roomId: string | null = null,
|
||||
excludeDefault = false,
|
||||
): Settings[S]["default"] | undefined {
|
||||
if (settingName === "mediaPreviewConfig") {
|
||||
console.log("GET VALUE", SETTINGS[settingName]);
|
||||
}
|
||||
|
||||
// Verify that the setting is actually a setting
|
||||
if (!SETTINGS[settingName]) {
|
||||
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
|
||||
@@ -382,6 +386,7 @@ export default class SettingsStore {
|
||||
const setting = SETTINGS[settingName];
|
||||
const levelOrder = getLevelOrder(setting);
|
||||
|
||||
|
||||
return SettingsStore.getValueAt(levelOrder[0], settingName, roomId, false, excludeDefault);
|
||||
}
|
||||
|
||||
@@ -728,8 +733,9 @@ export default class SettingsStore {
|
||||
const showImages = handler.getValue("showImages", null);
|
||||
const showAvatarsOnInvites = handler.getValue("showAvatarsOnInvites", null);
|
||||
|
||||
const AccountHandler = LEVEL_HANDLERS[SettingLevel.ACCOUNT];
|
||||
if (showImages !== null || showAvatarsOnInvites !== null) {
|
||||
this.setValue("mediaPreviewConfig", null, SettingLevel.ACCOUNT, {
|
||||
AccountHandler.setValue("mediaPreviewConfig", null, {
|
||||
invite_avatars: showAvatarsOnInvites === false ? MediaPreviewValue.Off : MediaPreviewValue.On,
|
||||
media_previews: showImages === false ? MediaPreviewValue.Off : MediaPreviewValue.On,
|
||||
});
|
||||
|
||||
@@ -5,11 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { ClientEvent, MatrixEvent, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { AccountDataEvents } from "matrix-js-sdk/src/types";
|
||||
import { MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, MediaPreviewConfig, MediaPreviewValue } from "../../@types/media_preview.ts";
|
||||
import { ClientEvent, type MatrixEvent, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { type AccountDataEvents } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { SettingLevel } from "../SettingLevel.ts";
|
||||
import {
|
||||
MEDIA_PREVIEW_ACCOUNT_DATA_TYPE,
|
||||
type MediaPreviewConfig,
|
||||
MediaPreviewValue,
|
||||
} from "../../@types/media_preview.ts";
|
||||
import { type SettingLevel } from "../SettingLevel.ts";
|
||||
import MatrixClientBackedController from "./MatrixClientBackedController.ts";
|
||||
|
||||
/**
|
||||
@@ -62,12 +66,6 @@ export default class MediaPreviewConfigController extends MatrixClientBackedCont
|
||||
public getValueOverride(level: SettingLevel, roomId: string | null): MediaPreviewConfig {
|
||||
// TODO: Use SettingLevel?
|
||||
if (roomId) {
|
||||
console.log(
|
||||
"MediaPreviewConfigController",
|
||||
"getValueOverride",
|
||||
this.getRoomValue(roomId),
|
||||
this.globalSetting,
|
||||
);
|
||||
// Use globals for any undefined setting
|
||||
return {
|
||||
...this.getRoomValue(roomId),
|
||||
@@ -96,7 +94,7 @@ export default class MediaPreviewConfigController extends MatrixClientBackedCont
|
||||
});
|
||||
return true;
|
||||
}
|
||||
await this.client.setAccountDataRaw(MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, newValue);
|
||||
await this.client.setAccountData(MEDIA_PREVIEW_ACCOUNT_DATA_TYPE, newValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
||||
const val = event.getContent()["enabled"];
|
||||
this.watchers.notifyUpdate("recent_emoji", null, SettingLevel.ACCOUNT, val);
|
||||
} else if (event.getType() === MEDIA_PREVIEW_ACCOUNT_DATA_TYPE) {
|
||||
console.log("notifyupdate");
|
||||
this.watchers.notifyUpdate("mediaPreviewConfig", null, SettingLevel.ROOM_ACCOUNT, event.getContent());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +58,6 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
|
||||
} else if (event.getType() === ALLOWED_WIDGETS_EVENT_TYPE) {
|
||||
this.watchers.notifyUpdate("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent());
|
||||
} else if (event.getType() === MEDIA_PREVIEW_ACCOUNT_DATA_TYPE) {
|
||||
console.log("notifyupdate");
|
||||
this.watchers.notifyUpdate("mediaPreviewConfig", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent());
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user