Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7a1a2c4

Browse files
authored
Improve Threads beta around degraded mode (#8318)
* Hide MAB Threads prompt if user would have degraded mode * Confirm user wants to enable Threads beta if in degraded mode * fix * Fix copy
1 parent b8013fc commit 7a1a2c4

File tree

6 files changed

+85
-11
lines changed

6 files changed

+85
-11
lines changed

src/components/views/messages/MessageActionBar.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import React, { ReactElement, useContext, useEffect } from 'react';
2020
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
2121
import classNames from 'classnames';
2222
import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
23+
import { Thread } from 'matrix-js-sdk/src/models/thread';
2324

2425
import type { Relations } from 'matrix-js-sdk/src/models/relations';
2526
import { _t } from '../../../languageHandler';
@@ -164,11 +165,16 @@ const ReplyInThreadButton = ({ mxEvent }: IReplyInThreadButton) => {
164165

165166
const relationType = mxEvent?.getRelation()?.rel_type;
166167
const hasARelation = !!relationType && relationType !== RelationType.Thread;
167-
const firstTimeSeeingThreads = localStorage.getItem("mx_seen_feature_thread") === null &&
168-
!SettingsStore.getValue("feature_thread");
168+
const firstTimeSeeingThreads = !localStorage.getItem("mx_seen_feature_thread");
169+
const threadsEnabled = SettingsStore.getValue("feature_thread");
170+
171+
if (!threadsEnabled && !Thread.hasServerSideSupport) {
172+
// hide the prompt if the user would only have degraded mode
173+
return null;
174+
}
169175

170176
const onClick = (): void => {
171-
if (localStorage.getItem("mx_seen_feature_thread") === null) {
177+
if (firstTimeSeeingThreads) {
172178
localStorage.setItem("mx_seen_feature_thread", "true");
173179
}
174180

@@ -219,7 +225,7 @@ const ReplyInThreadButton = ({ mxEvent }: IReplyInThreadButton) => {
219225

220226
onClick={onClick}
221227
>
222-
{ firstTimeSeeingThreads && (
228+
{ firstTimeSeeingThreads && !threadsEnabled && (
223229
<div className="mx_Indicator" />
224230
) }
225231
</RovingAccessibleTooltipButton>;

src/i18n/strings/en_EN.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,10 @@
960960
"Automatically send debug logs on any error": "Automatically send debug logs on any error",
961961
"Automatically send debug logs on decryption errors": "Automatically send debug logs on decryption errors",
962962
"Automatically send debug logs when key backup is not functioning": "Automatically send debug logs when key backup is not functioning",
963+
"Partial Support for Threads": "Partial Support for Threads",
964+
"Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. <a>Learn more</a>.": "Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. <a>Learn more</a>.",
965+
"Do you want to enable threads anyway?": "Do you want to enable threads anyway?",
966+
"Yes, enable": "Yes, enable",
963967
"Collecting app version information": "Collecting app version information",
964968
"Collecting logs": "Collecting logs",
965969
"Uploading logs": "Uploading logs",

src/settings/Settings.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import IncompatibleController from "./controllers/IncompatibleController";
4242
import { ImageSize } from "./enums/ImageSize";
4343
import { MetaSpace } from "../stores/spaces";
4444
import SdkConfig from "../SdkConfig";
45+
import ThreadBetaController from './controllers/ThreadBetaController';
4546

4647
// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
4748
const LEVELS_ROOM_SETTINGS = [
@@ -222,9 +223,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
222223
"feature_thread": {
223224
isFeature: true,
224225
labsGroup: LabGroup.Messaging,
225-
// Requires a reload as we change an option flag on the `js-sdk`
226-
// And the entire sync history needs to be parsed again
227-
controller: new ReloadOnChangeController(),
226+
controller: new ThreadBetaController(),
228227
displayName: _td("Threaded messaging"),
229228
supportedLevels: LEVELS_FEATURE,
230229
default: false,

src/settings/SettingsStore.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,13 @@ export default class SettingsStore {
451451
throw new Error("User cannot set " + settingName + " at " + level + " in " + roomId);
452452
}
453453

454+
if (setting.controller && !(await setting.controller.beforeChange(level, roomId, value))) {
455+
return; // controller says no
456+
}
457+
454458
await handler.setValue(settingName, roomId, value);
455459

456-
const controller = setting.controller;
457-
if (controller) {
458-
controller.onChange(level, roomId, value);
459-
}
460+
setting.controller?.onChange(level, roomId, value);
460461
}
461462

462463
/**

src/settings/controllers/SettingController.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ export default abstract class SettingController {
4646
return null; // no override
4747
}
4848

49+
/**
50+
* Called before the setting value has been changed, can abort the change.
51+
* @param {string} level The level at which the setting has been modified.
52+
* @param {String} roomId The room ID, may be null.
53+
* @param {*} newValue The new value for the setting, may be null.
54+
* @return {boolean} Whether the settings change should be accepted.
55+
*/
56+
public async beforeChange(level: SettingLevel, roomId: string, newValue: any): Promise<boolean> {
57+
return true;
58+
}
59+
4960
/**
5061
* Called when the setting value has been changed.
5162
* @param {string} level The level at which the setting has been modified.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)