Add initial support for a account data level key.
This commit is contained in:
@@ -8,7 +8,7 @@ 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, UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { _t, _td, type TranslationKey } from "../languageHandler";
|
||||
import DeviceIsolationModeController from "./controllers/DeviceIsolationModeController.ts";
|
||||
@@ -45,6 +45,7 @@ import { type Json, type JsonValue } from "../@types/json.ts";
|
||||
import { type RecentEmojiData } from "../emojipicker/recent.ts";
|
||||
import { type Assignable } from "../@types/common.ts";
|
||||
import { SortingAlgorithm } from "../stores/room-list-v3/skip-list/sorters/index.ts";
|
||||
import MediaPreviewConfigController from "./controllers/MediaPreviewConfigController.ts";
|
||||
|
||||
export const defaultWatchManager = new WatchManager();
|
||||
|
||||
@@ -349,6 +350,7 @@ export interface Settings {
|
||||
"Electron.alwaysShowMenuBar": IBaseSetting<boolean>;
|
||||
"Electron.showTrayIcon": IBaseSetting<boolean>;
|
||||
"Electron.enableHardwareAcceleration": IBaseSetting<boolean>;
|
||||
"mediaPreviewConfig": IBaseSetting<MediaPreviewConfig>;
|
||||
}
|
||||
|
||||
export type SettingKey = keyof Settings;
|
||||
@@ -425,6 +427,11 @@ export const SETTINGS: Settings = {
|
||||
supportedLevelsAreOrdered: true,
|
||||
default: false,
|
||||
},
|
||||
"mediaPreviewConfig": {
|
||||
controller: new MediaPreviewConfigController(),
|
||||
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
|
||||
default: MediaPreviewConfig.Private,
|
||||
},
|
||||
"feature_report_to_moderators": {
|
||||
isFeature: true,
|
||||
labsGroup: LabGroup.Moderation,
|
||||
@@ -1383,5 +1390,5 @@ export const SETTINGS: Settings = {
|
||||
supportedLevels: [SettingLevel.PLATFORM],
|
||||
displayName: _td("settings|preferences|enable_hardware_acceleration"),
|
||||
default: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
68
src/settings/controllers/MediaPreviewConfigController.ts
Normal file
68
src/settings/controllers/MediaPreviewConfigController.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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 { ClientEvent, MatrixEvent, MediaPreviewConfig, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { SettingLevel } from "../SettingLevel.ts";
|
||||
import MatrixClientBackedController from "./MatrixClientBackedController.ts";
|
||||
|
||||
|
||||
const CLIENT_KEY = "m.media_preview_config";
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
export default class MediaPreviewConfigController extends MatrixClientBackedController {
|
||||
private globalSetting: MediaPreviewConfig = MediaPreviewConfig.Private;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
private getRoomValue = (roomId: string): MediaPreviewConfig|null => {
|
||||
return this.client?.getRoom(roomId)?.getAccountData(CLIENT_KEY)?.getContent().value ?? null;
|
||||
}
|
||||
|
||||
private onAccountData = (event: MatrixEvent): void => {
|
||||
// TODO: Validate.
|
||||
const roomId = event.getRoomId();
|
||||
if (!roomId) {
|
||||
this.globalSetting = event.getContent().value;
|
||||
}
|
||||
};
|
||||
|
||||
protected async initMatrixClient(newClient: MatrixClient, oldClient?: MatrixClient): Promise<void> {
|
||||
oldClient?.off(ClientEvent.AccountData, this.onAccountData);
|
||||
newClient.on(ClientEvent.AccountData, this.onAccountData);
|
||||
const accountData = newClient.getAccountData(CLIENT_KEY);
|
||||
if (accountData) this.onAccountData(accountData);
|
||||
}
|
||||
|
||||
public getValueOverride(level: SettingLevel, roomId: string | null,): MediaPreviewConfig {
|
||||
// TODO: Use SettingLevel?
|
||||
if (roomId) {
|
||||
return this.getRoomValue(roomId) ?? this.globalSetting;
|
||||
}
|
||||
return this.globalSetting;
|
||||
}
|
||||
|
||||
public get settingDisabled(): boolean | string {
|
||||
return false;
|
||||
}
|
||||
|
||||
public onChange(_level: SettingLevel, roomId: string | null, newValue: MediaPreviewConfig): void {
|
||||
if (roomId) {
|
||||
this.client?.setRoomAccountData(roomId, "m.media_preview_config", {
|
||||
value: newValue
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.client?.setAccountDataRaw( "m.media_preview_config", {
|
||||
value: newValue
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user