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

Commit

Permalink
[Release] Fixes around threads beta in degraded mode (#8319)
Browse files Browse the repository at this point in the history
* Fix soft crash around the thread panel in degraded mode

* Better specify fallback key

* Hide MAB Threads prompt if user would have degraded mode

* Confirm user wants to enable Threads beta if in degraded mode

* Fix copy
  • Loading branch information
t3chguy authored Apr 14, 2022
1 parent 5f35609 commit 1c1d5ea
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/structures/ThreadPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const ThreadPanel: React.FC<IProps> = ({
/>
{ timelineSet && (
<TimelinePanel
key={timelineSet.getFilter().filterId}
key={timelineSet.getFilter()?.filterId ?? (roomId + ":" + filterOption)}
ref={timelinePanel}
showReadReceipts={false} // No RR support in thread's MVP
manageReadReceipts={false} // No RR support in thread's MVP
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/messages/MessageActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React, { ReactElement, useEffect } from 'react';
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames';
import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { Thread } from 'matrix-js-sdk/src/models/thread';

import type { Relations } from 'matrix-js-sdk/src/models/relations';
import { _t } from '../../../languageHandler';
Expand Down Expand Up @@ -248,6 +249,11 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
];

private get showReplyInThreadAction(): boolean {
if (!SettingsStore.getValue("feature_thread") && !Thread.hasServerSideSupport) {
// hide the prompt if the user would only have degraded mode
return null;
}

const inNotThreadTimeline = this.context.timelineRenderingType !== TimelineRenderingType.Thread;

const isAllowedMessageType = !this.forbiddenThreadHeadMsgType.includes(
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,10 @@
"Automatically send debug logs on any error": "Automatically send debug logs on any error",
"Automatically send debug logs on decryption errors": "Automatically send debug logs on decryption errors",
"Automatically send debug logs when key backup is not functioning": "Automatically send debug logs when key backup is not functioning",
"Partial Support for Threads": "Partial Support for Threads",
"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>.",
"Do you want to enable threads anyway?": "Do you want to enable threads anyway?",
"Yes, enable": "Yes, enable",
"Collecting app version information": "Collecting app version information",
"Collecting logs": "Collecting logs",
"Uploading logs": "Uploading logs",
Expand Down
5 changes: 2 additions & 3 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import IncompatibleController from "./controllers/IncompatibleController";
import { ImageSize } from "./enums/ImageSize";
import { MetaSpace } from "../stores/spaces";
import SdkConfig from "../SdkConfig";
import ThreadBetaController from './controllers/ThreadBetaController';

// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
const LEVELS_ROOM_SETTINGS = [
Expand Down Expand Up @@ -222,9 +223,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
"feature_thread": {
isFeature: true,
labsGroup: LabGroup.Messaging,
// Requires a reload as we change an option flag on the `js-sdk`
// And the entire sync history needs to be parsed again
controller: new ReloadOnChangeController(),
controller: new ThreadBetaController(),
displayName: _td("Threaded messaging"),
supportedLevels: LEVELS_FEATURE,
default: false,
Expand Down
9 changes: 5 additions & 4 deletions src/settings/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,13 @@ export default class SettingsStore {
throw new Error("User cannot set " + settingName + " at " + level + " in " + roomId);
}

if (setting.controller && !(await setting.controller.beforeChange(level, roomId, value))) {
return; // controller says no
}

await handler.setValue(settingName, roomId, value);

const controller = setting.controller;
if (controller) {
controller.onChange(level, roomId, value);
}
setting.controller?.onChange(level, roomId, value);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/settings/controllers/SettingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ export default abstract class SettingController {
return null; // no override
}

/**
* Called before the setting value has been changed, can abort the change.
* @param {string} level The level at which the setting has been modified.
* @param {String} roomId The room ID, may be null.
* @param {*} newValue The new value for the setting, may be null.
* @return {boolean} Whether the settings change should be accepted.
*/
public async beforeChange(level: SettingLevel, roomId: string, newValue: any): Promise<boolean> {
return true;
}

/**
* Called when the setting value has been changed.
* @param {string} level The level at which the setting has been modified.
Expand Down
53 changes: 53 additions & 0 deletions src/settings/controllers/ThreadBetaController.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import * as React from "react";
import { Thread } from "matrix-js-sdk/src/models/thread";

import SettingController from "./SettingController";
import PlatformPeg from "../../PlatformPeg";
import { SettingLevel } from "../SettingLevel";
import Modal from "../../Modal";
import QuestionDialog from "../../components/views/dialogs/QuestionDialog";
import { _t } from "../../languageHandler";

export default class ThreadBetaController extends SettingController {
public async beforeChange(level: SettingLevel, roomId: string, newValue: any): Promise<boolean> {
if (Thread.hasServerSideSupport || !newValue) return true; // Full support or user is disabling

const { finished } = Modal.createTrackedDialog<[boolean]>("Thread beta", "degraded mode", QuestionDialog, {
title: _t("Partial Support for Threads"),
description: <>
<p>{ _t("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>.", {}, {
a: sub => (
<a href="https://element.io/help#threads" target="_blank" rel="noreferrer noopener">{ sub }</a>
),
}) }</p>
<p>{ _t("Do you want to enable threads anyway?") }</p>
</>,
button: _t("Yes, enable"),
});
const [enable] = await finished;
return enable;
}

public onChange(level: SettingLevel, roomId: string, newValue: any) {
// Requires a reload as we change an option flag on the `js-sdk`
// And the entire sync history needs to be parsed again
PlatformPeg.get().reload();
}
}

0 comments on commit 1c1d5ea

Please sign in to comment.