Prevent thread creation on events with existing relation (#8037)

This commit is contained in:
Germain 2022-03-11 17:51:38 +00:00 committed by GitHub
parent 4b0df21b0a
commit 7508fd975f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -65,6 +65,12 @@ limitations under the License.
.mx_MessageActionBar_maskButton { .mx_MessageActionBar_maskButton {
width: 28px; width: 28px;
height: 28px; height: 28px;
&:disabled,
&[disabled] {
cursor: not-allowed;
opacity: .75;
}
} }
.mx_MessageActionBar_maskButton::after { .mx_MessageActionBar_maskButton::after {

View file

@ -19,7 +19,7 @@ limitations under the License.
import React, { ReactElement, useEffect } from 'react'; import React, { ReactElement, useEffect } from 'react';
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event'; import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames'; import classNames from 'classnames';
import { MsgType } from 'matrix-js-sdk/src/@types/event'; import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
import type { Relations } from 'matrix-js-sdk/src/models/relations'; import type { Relations } from 'matrix-js-sdk/src/models/relations';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
@ -166,7 +166,7 @@ interface IMessageActionBarProps {
isQuoteExpanded?: boolean; isQuoteExpanded?: boolean;
getRelationsForEvent?: ( getRelationsForEvent?: (
eventId: string, eventId: string,
relationType: string, relationType: RelationType | string,
eventType: string eventType: string
) => Relations; ) => Relations;
} }
@ -303,11 +303,19 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
key="cancel" key="cancel"
/>; />;
const hasARelation = !!this.props.mxEvent?.getRelation()?.rel_type;
const threadTooltipButton = <CardContext.Consumer key="thread"> const threadTooltipButton = <CardContext.Consumer key="thread">
{ context => { context =>
<RovingAccessibleTooltipButton <RovingAccessibleTooltipButton
className="mx_MessageActionBar_maskButton mx_MessageActionBar_threadButton" className="mx_MessageActionBar_maskButton mx_MessageActionBar_threadButton"
title={_t("Reply in thread")}
disabled={hasARelation}
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)} onClick={this.onThreadClick.bind(null, context.isCard)}
/> />
} }

View file

@ -2103,6 +2103,7 @@
"React": "React", "React": "React",
"Edit": "Edit", "Edit": "Edit",
"Reply in thread": "Reply in thread", "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",
"Reply": "Reply", "Reply": "Reply",
"Collapse quotes": "Collapse quotes", "Collapse quotes": "Collapse quotes",
"Expand quotes": "Expand quotes", "Expand quotes": "Expand quotes",