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

Prevent thread creation on events with existing relation #8037

Merged
merged 3 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions res/css/views/messages/_MessageActionBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ limitations under the License.
.mx_MessageActionBar_maskButton {
width: 28px;
height: 28px;

&:disabled,
&[disabled] {
cursor: not-allowed;
opacity: .75;
}
}

.mx_MessageActionBar_maskButton::after {
Expand Down
15 changes: 12 additions & 3 deletions src/components/views/messages/MessageActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ limitations under the License.
import React, { ReactElement, useEffect } from 'react';
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames';
import { MsgType } from 'matrix-js-sdk/src/@types/event';
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 @@ -166,7 +167,7 @@ interface IMessageActionBarProps {
isQuoteExpanded?: boolean;
getRelationsForEvent?: (
eventId: string,
relationType: string,
relationType: RelationType | string,
eventType: string
) => Relations;
}
Expand Down Expand Up @@ -303,11 +304,19 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
key="cancel"
/>;

const hasARelation = !!this.props.mxEvent?.getRelation()?.rel_type;

const threadTooltipButton = <CardContext.Consumer key="thread">
{ context =>
<RovingAccessibleTooltipButton
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)}
/>
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@
"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",
"Reply": "Reply",
"Collapse quotes": "Collapse quotes",
"Expand quotes": "Expand quotes",
Expand Down