From ceae8bb39aee2fc5b836d66804fd5e0364f4cfcc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 12 Apr 2022 15:24:23 +0100 Subject: [PATCH] Hide the reply in thread button in deployments where beta is forcibly disabled (#8294) --- .../views/messages/MessageActionBar.tsx | 147 ++++++++++-------- src/i18n/strings/en_EN.json | 2 +- 2 files changed, 83 insertions(+), 66 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.tsx b/src/components/views/messages/MessageActionBar.tsx index 6af8625ab64..80f9b6daf86 100644 --- a/src/components/views/messages/MessageActionBar.tsx +++ b/src/components/views/messages/MessageActionBar.tsx @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { ReactElement, useEffect } from 'react'; +import React, { ReactElement, useContext, 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'; @@ -45,6 +45,7 @@ import { Key } from "../../../Keyboard"; import { ALTERNATE_KEY_NAME } from "../../../accessibility/KeyboardShortcuts"; import { UserTab } from '../dialogs/UserTab'; import { Action } from '../../../dispatcher/actions'; +import SdkConfig from "../../../SdkConfig"; interface IOptionsButtonProps { mxEvent: MatrixEvent; @@ -154,6 +155,76 @@ const ReactButton: React.FC = ({ mxEvent, reactions, onFocusC ; }; +interface IReplyInThreadButton { + mxEvent: MatrixEvent; +} + +const ReplyInThreadButton = ({ mxEvent }: IReplyInThreadButton) => { + const context = useContext(CardContext); + + const relationType = mxEvent?.getRelation()?.rel_type; + const hasARelation = !!relationType && relationType !== RelationType.Thread; + const firstTimeSeeingThreads = localStorage.getItem("mx_seen_feature_thread") === null && + !SettingsStore.getValue("feature_thread"); + + const onClick = (): void => { + if (localStorage.getItem("mx_seen_feature_thread") === null) { + localStorage.setItem("mx_seen_feature_thread", "true"); + } + + if (!SettingsStore.getValue("feature_thread")) { + dis.dispatch({ + action: Action.ViewUserSettings, + initialTabId: UserTab.Labs, + }); + } else if (mxEvent.isThreadRelation) { + showThread({ + rootEvent: mxEvent.getThread().rootEvent, + initialEvent: mxEvent, + scroll_into_view: true, + highlighted: true, + push: context.isCard, + }); + } else { + showThread({ + rootEvent: mxEvent, + push: context.isCard, + }); + } + }; + + return +
+ { !hasARelation + ? _t("Reply in thread") + : _t("Can't create a thread from an event with an existing relation") } +
+ { !hasARelation && ( +
+ { SettingsStore.getValue("feature_thread") + ? _t("Beta feature") + : _t("Beta feature. Click to learn more.") + } +
+ ) } + } + + title={!hasARelation + ? _t("Reply in thread") + : _t("Can't create a thread from an event with an existing relation")} + + onClick={onClick} + > + { firstTimeSeeingThreads && ( +
+ ) } + ; +}; + interface IMessageActionBarProps { mxEvent: MatrixEvent; reactions?: Relations; @@ -222,32 +293,6 @@ export default class MessageActionBar extends React.PureComponent { - if (localStorage.getItem("mx_seen_feature_thread") === null) { - localStorage.setItem("mx_seen_feature_thread", "true"); - } - - if (!SettingsStore.getValue("feature_thread")) { - dis.dispatch({ - action: Action.ViewUserSettings, - initialTabId: UserTab.Labs, - }); - } else if (this.props.mxEvent.isThreadRelation) { - showThread({ - rootEvent: this.props.mxEvent.getThread().rootEvent, - initialEvent: this.props.mxEvent, - scroll_into_view: true, - highlighted: true, - push: isCard, - }); - } else { - showThread({ - rootEvent: this.props.mxEvent, - push: isCard, - }); - } - }; - private onEditClick = (): void => { editEvent(this.props.mxEvent, this.context.timelineRenderingType, this.props.getRelationsForEvent); }; @@ -257,6 +302,15 @@ export default class MessageActionBar extends React.PureComponent; - const relationType = this.props.mxEvent?.getRelation()?.rel_type; - const hasARelation = !!relationType && relationType !== RelationType.Thread; - const firstTimeSeeingThreads = localStorage.getItem("mx_seen_feature_thread") === null && - !SettingsStore.getValue("feature_thread"); - const threadTooltipButton = - { context => - -
- { !hasARelation - ? _t("Reply in thread") - : _t("Can't create a thread from an event with an existing relation") } -
- { !hasARelation && ( -
- { SettingsStore.getValue("feature_thread") - ? _t("Beta feature") - : _t("Beta feature. Click to learn more.") - } -
- ) } - } - - title={!hasARelation - ? _t("Reply in thread") - : _t("Can't create a thread from an event with an existing relation")} - - onClick={this.onThreadClick.bind(null, context.isCard)} - > - { firstTimeSeeingThreads && ( -
- ) } - - } - ; + const threadTooltipButton = ; // We show a different toolbar for failed events, so detect that first. const mxEvent = this.props.mxEvent; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 6040b4baacb..c5769f9902a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2080,11 +2080,11 @@ "Go": "Go", "Error processing audio message": "Error processing audio message", "React": "React", - "Edit": "Edit", "Reply in thread": "Reply in thread", "Can't create a thread from an event with an existing relation": "Can't create a thread from an event with an existing relation", "Beta feature": "Beta feature", "Beta feature. Click to learn more.": "Beta feature. Click to learn more.", + "Edit": "Edit", "Reply": "Reply", "Collapse quotes": "Collapse quotes", "Expand quotes": "Expand quotes",