From e49eb55a3da1d185dd421f155e2995c947aeb610 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 31 Oct 2024 16:17:13 +0000 Subject: [PATCH] More tidying --- src/useReactions.tsx | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/useReactions.tsx b/src/useReactions.tsx index 42827b56..b4088b6a 100644 --- a/src/useReactions.tsx +++ b/src/useReactions.tsx @@ -78,15 +78,14 @@ export const ReactionsProvider = ({ const supportsReactions = clientState?.state === "valid" && clientState.supportedFeatures.reactions; const room = rtcSession.room; + const myUserId = room.client.getUserId(); // Calculate our own reaction event. - const myReactionId = useMemo((): string | null => { - const myUserId = room.client.getUserId(); - if (myUserId) { - return raisedHands[myUserId]?.reactionEventId; - } - return null; - }, [raisedHands, room]); + const myReactionId = useMemo( + (): string | null => + (myUserId && raisedHands[myUserId]?.reactionEventId) ?? null, + [raisedHands, room], + ); // Reduce the data down for the consumers. const resultRaisedHands = useMemo( @@ -105,11 +104,9 @@ export const ReactionsProvider = ({ }, []); const removeRaisedHand = useCallback((userId: string) => { - delete raisedHands[userId]; - setRaisedHands((prevRaisedHands) => { - delete prevRaisedHands[userId]; - return { ...prevRaisedHands }; - }); + setRaisedHands( + ({ [userId]: _removed, ...remainingRaisedHands }) => remainingRaisedHands, + ); }, []); // This effect will check the state whenever the membership of the session changes. @@ -123,7 +120,7 @@ export const ReactionsProvider = ({ EventType.Reaction, ); const allEvents = relations?.getRelations() ?? []; - return allEvents.length > 0 ? allEvents[0] : undefined; + return allEvents.find((u) => u.sender === myUserId); }; // Remove any raised hands for users no longer joined to the call.