|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import * as React from "react"; |
| 18 | +import { Thread } from "matrix-js-sdk/src/models/thread"; |
| 19 | + |
| 20 | +import SettingController from "./SettingController"; |
| 21 | +import PlatformPeg from "../../PlatformPeg"; |
| 22 | +import { SettingLevel } from "../SettingLevel"; |
| 23 | +import Modal from "../../Modal"; |
| 24 | +import QuestionDialog from "../../components/views/dialogs/QuestionDialog"; |
| 25 | +import { _t } from "../../languageHandler"; |
| 26 | + |
| 27 | +export default class ThreadBetaController extends SettingController { |
| 28 | + public async beforeChange(level: SettingLevel, roomId: string, newValue: any): Promise<boolean> { |
| 29 | + if (Thread.hasServerSideSupport || !newValue) return true; // Full support or user is disabling |
| 30 | + |
| 31 | + const { finished } = Modal.createTrackedDialog<[boolean]>("Thread beta", "degraded mode", QuestionDialog, { |
| 32 | + title: _t("Partial Support for Threads"), |
| 33 | + description: <> |
| 34 | + <p>{ _t("Your homeserver does not currently support threads, so this feature may be unreliable. " + |
| 35 | + "Some threaded messages may not be reliably available. <a>Learn more</a>.", {}, { |
| 36 | + a: sub => ( |
| 37 | + <a href="https://element.io/help#threads" target="_blank" rel="noreferrer noopener">{ sub }</a> |
| 38 | + ), |
| 39 | + }) }</p> |
| 40 | + <p>{ _t("Do you want to enable threads anyway?") }</p> |
| 41 | + </>, |
| 42 | + button: _t("Yes, enable"), |
| 43 | + }); |
| 44 | + const [enable] = await finished; |
| 45 | + return enable; |
| 46 | + } |
| 47 | + |
| 48 | + public onChange(level: SettingLevel, roomId: string, newValue: any) { |
| 49 | + // Requires a reload as we change an option flag on the `js-sdk` |
| 50 | + // And the entire sync history needs to be parsed again |
| 51 | + PlatformPeg.get().reload(); |
| 52 | + } |
| 53 | +} |
0 commit comments