mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +00:00
Clear timeouts on component close.
This commit is contained in:
@@ -178,6 +178,7 @@ export const ReactionsProvider = ({
|
|||||||
|
|
||||||
// This effect handles any *live* reaction/redactions in the room.
|
// This effect handles any *live* reaction/redactions in the room.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const reactionTimeouts = new Set<NodeJS.Timeout>();
|
||||||
const handleReactionEvent = (event: MatrixEvent): void => {
|
const handleReactionEvent = (event: MatrixEvent): void => {
|
||||||
if (event.isSending()) {
|
if (event.isSending()) {
|
||||||
// Skip any events that are still sending.
|
// Skip any events that are still sending.
|
||||||
@@ -240,10 +241,12 @@ export const ReactionsProvider = ({
|
|||||||
// We've still got a reaction from this user, ignore it to prevent spamming
|
// We've still got a reaction from this user, ignore it to prevent spamming
|
||||||
return reactions;
|
return reactions;
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
// Clear the reaction after some time.
|
// Clear the reaction after some time.
|
||||||
setReactions(({ [sender]: _unused, ...remaining }) => remaining);
|
setReactions(({ [sender]: _unused, ...remaining }) => remaining);
|
||||||
|
reactionTimeouts.delete(timeout);
|
||||||
}, REACTION_ACTIVE_TIME_MS);
|
}, REACTION_ACTIVE_TIME_MS);
|
||||||
|
reactionTimeouts.add(timeout);
|
||||||
return {
|
return {
|
||||||
...reactions,
|
...reactions,
|
||||||
[sender]: reaction,
|
[sender]: reaction,
|
||||||
@@ -297,6 +300,7 @@ export const ReactionsProvider = ({
|
|||||||
room.off(MatrixRoomEvent.Timeline, handleReactionEvent);
|
room.off(MatrixRoomEvent.Timeline, handleReactionEvent);
|
||||||
room.off(MatrixRoomEvent.Redaction, handleReactionEvent);
|
room.off(MatrixRoomEvent.Redaction, handleReactionEvent);
|
||||||
room.off(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent);
|
room.off(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent);
|
||||||
|
reactionTimeouts.forEach((t) => clearTimeout(t));
|
||||||
};
|
};
|
||||||
}, [room, addRaisedHand, removeRaisedHand, memberships, raisedHands]);
|
}, [room, addRaisedHand, removeRaisedHand, memberships, raisedHands]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user