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

Commit

Permalink
Disable redacting reactions if we don't have sufficient permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
SimonBrandner committed Jun 5, 2022
1 parent 41ee47f commit 85a284a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/views/messages/ReactionsRowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import dis from "../../../dispatcher/dispatcher";
import ReactionsRowButtonTooltip from "./ReactionsRowButtonTooltip";
import AccessibleButton from "../elements/AccessibleButton";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { MatrixClientPeg } from "../../../MatrixClientPeg";

const canRedact = (roomId: string, mxEvent: MatrixEvent): boolean => {
const client = MatrixClientPeg.get();
const room = client.getRoom(roomId);
return room.currentState.maySendRedactionForEvent(mxEvent, client.getUserId());
};

interface IProps {
// The event we're displaying reactions for
Expand All @@ -47,6 +54,7 @@ interface IState {

export default class ReactionsRowButton extends React.PureComponent<IProps, IState> {
static contextType = MatrixClientContext;
public context!: React.ContextType<typeof MatrixClientContext>;

state = {
tooltipRendered: false,
Expand All @@ -56,8 +64,11 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
onClick = () => {
const { mxEvent, myReactionEvent, content } = this.props;
if (myReactionEvent) {
const roomId = mxEvent.getRoomId();
if (!canRedact(roomId, myReactionEvent)) return;

this.context.redactEvent(
mxEvent.getRoomId(),
roomId,
myReactionEvent.getId(),
);
} else {
Expand Down Expand Up @@ -126,7 +137,7 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
className={classes}
aria-label={label}
onClick={this.onClick}
disabled={this.props.disabled}
disabled={this.props.disabled || (myReactionEvent && !canRedact(mxEvent.getRoomId(), myReactionEvent))}
onMouseOver={this.onMouseOver}
onMouseLeave={this.onMouseLeave}
>
Expand Down

0 comments on commit 85a284a

Please sign in to comment.