/* Copyright 2024 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import { AllDevicesIsolationMode, OnlySignedDevicesIsolationMode } from "matrix-js-sdk/src/crypto-api"; import { MatrixClient } from "matrix-js-sdk/src/matrix"; import SettingController from "./SettingController"; import { MatrixClientPeg } from "../../MatrixClientPeg"; import { SettingLevel } from "../SettingLevel"; /** * A controller for the "exclude_insecure_devices" setting, which will * update the crypto stack's device isolation mode on change. */ export default class DeviceIsolationModeController extends SettingController { public onChange(level: SettingLevel, roomId: string, newValue: any): void { setDeviceIsolationMode(MatrixClientPeg.safeGet(), newValue); } } /** * Set the crypto stack's device isolation mode based on the current value of the * "exclude_insecure_devices" setting. * * @param client - MatrixClient to update to the new setting. * @param settingValue - value of the "exclude_insecure_devices" setting. */ export function setDeviceIsolationMode(client: MatrixClient, settingValue: boolean): void { client .getCrypto() ?.setDeviceIsolationMode( settingValue ? new OnlySignedDevicesIsolationMode() : new AllDevicesIsolationMode(true), ); }