@@ -30,7 +30,7 @@ import { useClientState } from "./ClientContext";
30
30
interface ReactionsContextType {
31
31
raisedHands : Record < string , Date > ;
32
32
supportsReactions : boolean ;
33
- myReactionId : string | null ;
33
+ lowerHand : ( ) => Promise < void > ;
34
34
}
35
35
36
36
const ReactionsContext = createContext < ReactionsContextType | undefined > (
@@ -80,13 +80,6 @@ export const ReactionsProvider = ({
80
80
const room = rtcSession . room ;
81
81
const myUserId = room . client . getUserId ( ) ;
82
82
83
- // Calculate our own reaction event.
84
- const myReactionId = useMemo (
85
- ( ) : string | null =>
86
- ( myUserId && raisedHands [ myUserId ] ?. reactionEventId ) ?? null ,
87
- [ raisedHands , myUserId ] ,
88
- ) ;
89
-
90
83
// Reduce the data down for the consumers.
91
84
const resultRaisedHands = useMemo (
92
85
( ) =>
@@ -235,12 +228,37 @@ export const ReactionsProvider = ({
235
228
} ;
236
229
} , [ room , addRaisedHand , removeRaisedHand , memberships , raisedHands ] ) ;
237
230
231
+ const lowerHand = useCallback ( async ( ) => {
232
+ if (
233
+ ! myUserId ||
234
+ clientState ?. state !== "valid" ||
235
+ ! clientState . authenticated ||
236
+ ! raisedHands [ myUserId ]
237
+ ) {
238
+ return ;
239
+ }
240
+ const myReactionId = raisedHands [ myUserId ] . reactionEventId ;
241
+ if ( ! myReactionId ) {
242
+ logger . warn ( `Hand raised but no reaction event to redact!` ) ;
243
+ return ;
244
+ }
245
+ try {
246
+ await clientState . authenticated . client . redactEvent (
247
+ rtcSession . room . roomId ,
248
+ myReactionId ,
249
+ ) ;
250
+ logger . debug ( "Redacted raise hand event" ) ;
251
+ } catch ( ex ) {
252
+ logger . error ( "Failed to redact reaction event" , myReactionId , ex ) ;
253
+ }
254
+ } , [ myUserId , raisedHands , clientState , rtcSession ] ) ;
255
+
238
256
return (
239
257
< ReactionsContext . Provider
240
258
value = { {
241
259
raisedHands : resultRaisedHands ,
242
260
supportsReactions,
243
- myReactionId ,
261
+ lowerHand ,
244
262
} }
245
263
>
246
264
{ children }
0 commit comments