@@ -16,7 +16,6 @@ limitations under the License.
16
16
17
17
import React from "react" ;
18
18
import classNames from "classnames" ;
19
- import { EventType } from "matrix-js-sdk/src/@types/event" ;
20
19
import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
21
20
import { Relations } from "matrix-js-sdk/src/models/relations" ;
22
21
@@ -27,7 +26,7 @@ import { ContextMenuTooltipButton } from "../../../accessibility/context_menu/Co
27
26
import ContextMenu , { aboveLeftOf , useContextMenu } from "../../structures/ContextMenu" ;
28
27
import ReactionPicker from "../emojipicker/ReactionPicker" ;
29
28
import ReactionsRowButton from "./ReactionsRowButton" ;
30
- import MatrixClientContext from "../../../contexts/MatrixClientContext " ;
29
+ import RoomContext from "../../../contexts/RoomContext " ;
31
30
32
31
// The maximum number of reactions to initially show on a message.
33
32
const MAX_ITEMS_WHEN_LIMITED = 8 ;
@@ -76,10 +75,12 @@ interface IState {
76
75
77
76
@replaceableComponent ( "views.messages.ReactionsRow" )
78
77
export default class ReactionsRow extends React . PureComponent < IProps , IState > {
79
- static contextType = MatrixClientContext ;
78
+ static contextType = RoomContext ;
79
+ public context ! : React . ContextType < typeof RoomContext > ;
80
80
81
- constructor ( props , context ) {
81
+ constructor ( props : IProps , context : React . ContextType < typeof RoomContext > ) {
82
82
super ( props , context ) ;
83
+ this . context = context ;
83
84
84
85
this . state = {
85
86
myReactions : this . getMyReactions ( ) ,
@@ -143,7 +144,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
143
144
if ( ! reactions ) {
144
145
return null ;
145
146
}
146
- const userId = this . context . getUserId ( ) ;
147
+ const userId = this . context . room . client . getUserId ( ) ;
147
148
const myReactions = reactions . getAnnotationsBySender ( ) [ userId ] ;
148
149
if ( ! myReactions ) {
149
150
return null ;
@@ -165,6 +166,11 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
165
166
return null ;
166
167
}
167
168
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
+
168
174
let items = reactions . getSortedAnnotationsByKey ( ) . map ( ( [ content , events ] ) => {
169
175
const count = events . size ;
170
176
if ( ! count ) {
@@ -183,6 +189,7 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
183
189
mxEvent = { mxEvent }
184
190
reactionEvents = { events }
185
191
myReactionEvent = { myReactionEvent }
192
+ disabled = { ! canReact }
186
193
/> ;
187
194
} ) . filter ( item => ! ! item ) ;
188
195
@@ -203,11 +210,8 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
203
210
</ a > ;
204
211
}
205
212
206
- const cli = this . context ;
207
-
208
213
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 ) {
211
215
addReactionButton = < ReactButton mxEvent = { mxEvent } reactions = { reactions } /> ;
212
216
}
213
217
0 commit comments