@@ -30,7 +30,7 @@ import { useClientState } from "./ClientContext";
3030interface ReactionsContextType {
3131 raisedHands : Record < string , Date > ;
3232 supportsReactions : boolean ;
33- myReactionId : string | null ;
33+ lowerHand : ( ) => Promise < void > ;
3434}
3535
3636const ReactionsContext = createContext < ReactionsContextType | undefined > (
@@ -80,13 +80,6 @@ export const ReactionsProvider = ({
8080 const room = rtcSession . room ;
8181 const myUserId = room . client . getUserId ( ) ;
8282
83- // Calculate our own reaction event.
84- const myReactionId = useMemo (
85- ( ) : string | null =>
86- ( myUserId && raisedHands [ myUserId ] ?. reactionEventId ) ?? null ,
87- [ raisedHands , myUserId ] ,
88- ) ;
89-
9083 // Reduce the data down for the consumers.
9184 const resultRaisedHands = useMemo (
9285 ( ) =>
@@ -235,12 +228,37 @@ export const ReactionsProvider = ({
235228 } ;
236229 } , [ room , addRaisedHand , removeRaisedHand , memberships , raisedHands ] ) ;
237230
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+
238256 return (
239257 < ReactionsContext . Provider
240258 value = { {
241259 raisedHands : resultRaisedHands ,
242260 supportsReactions,
243- myReactionId ,
261+ lowerHand ,
244262 } }
245263 >
246264 { children }
0 commit comments