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

Commit 097c40b

Browse files
authored
Disable quick reactions button when no permissions (#7412)
1 parent a9d1f6e commit 097c40b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/components/views/messages/ReactionsRow.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ limitations under the License.
1616

1717
import React from "react";
1818
import classNames from "classnames";
19-
import { EventType } from "matrix-js-sdk/src/@types/event";
2019
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2120
import { Relations } from "matrix-js-sdk/src/models/relations";
2221

@@ -27,7 +26,7 @@ import { ContextMenuTooltipButton } from "../../../accessibility/context_menu/Co
2726
import ContextMenu, { aboveLeftOf, useContextMenu } from "../../structures/ContextMenu";
2827
import ReactionPicker from "../emojipicker/ReactionPicker";
2928
import ReactionsRowButton from "./ReactionsRowButton";
30-
import MatrixClientContext from "../../../contexts/MatrixClientContext";
29+
import RoomContext from "../../../contexts/RoomContext";
3130

3231
// The maximum number of reactions to initially show on a message.
3332
const MAX_ITEMS_WHEN_LIMITED = 8;
@@ -76,10 +75,12 @@ interface IState {
7675

7776
@replaceableComponent("views.messages.ReactionsRow")
7877
export default class ReactionsRow extends React.PureComponent<IProps, IState> {
79-
static contextType = MatrixClientContext;
78+
static contextType = RoomContext;
79+
public context!: React.ContextType<typeof RoomContext>;
8080

81-
constructor(props, context) {
81+
constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
8282
super(props, context);
83+
this.context = context;
8384

8485
this.state = {
8586
myReactions: this.getMyReactions(),
@@ -143,7 +144,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
143144
if (!reactions) {
144145
return null;
145146
}
146-
const userId = this.context.getUserId();
147+
const userId = this.context.room.client.getUserId();
147148
const myReactions = reactions.getAnnotationsBySender()[userId];
148149
if (!myReactions) {
149150
return null;
@@ -165,6 +166,11 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
165166
return null;
166167
}
167168

169+
const cli = this.context.room.client;
170+
const room = cli.getRoom(mxEvent.getRoomId());
171+
const isPeeking = room.getMyMembership() !== "join";
172+
const canReact = !isPeeking && this.context.canReact;
173+
168174
let items = reactions.getSortedAnnotationsByKey().map(([content, events]) => {
169175
const count = events.size;
170176
if (!count) {
@@ -183,6 +189,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
183189
mxEvent={mxEvent}
184190
reactionEvents={events}
185191
myReactionEvent={myReactionEvent}
192+
disabled={!canReact}
186193
/>;
187194
}).filter(item => !!item);
188195

@@ -203,11 +210,8 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
203210
</a>;
204211
}
205212

206-
const cli = this.context;
207-
208213
let addReactionButton;
209-
const room = cli.getRoom(mxEvent.getRoomId());
210-
if (room.getMyMembership() === "join" && room.currentState.maySendEvent(EventType.Reaction, cli.getUserId())) {
214+
if (room.getMyMembership() === "join" && this.context.canReact) {
211215
addReactionButton = <ReactButton mxEvent={mxEvent} reactions={reactions} />;
212216
}
213217

src/components/views/messages/ReactionsRowButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ interface IProps {
3737
reactionEvents: Set<MatrixEvent>;
3838
// A possible Matrix event if the current user has voted for this type
3939
myReactionEvent?: MatrixEvent;
40+
// Whether to prevent quick-reactions by clicking on this reaction
41+
disabled?: boolean;
4042
}
4143

4244
interface IState {
@@ -121,12 +123,12 @@ export default class ReactionsRowButton extends React.PureComponent<IProps, ISta
121123
label = reactors;
122124
}
123125
}
124-
const isPeeking = room.getMyMembership() !== "join";
126+
125127
return <AccessibleButton
126128
className={classes}
127129
aria-label={label}
128130
onClick={this.onClick}
129-
disabled={isPeeking}
131+
disabled={this.props.disabled}
130132
onMouseOver={this.onMouseOver}
131133
onMouseLeave={this.onMouseLeave}
132134
>

0 commit comments

Comments
 (0)