From 45800edf4ad648e8fafcdce4b912e75f93909e5f Mon Sep 17 00:00:00 2001 From: 7w1 Date: Thu, 9 Jul 2026 10:43:40 -0500 Subject: [PATCH] fix call button reactivity --- .changeset/fix-call-button-reactivity.md | 5 +++++ src/app/hooks/useCallStartCapabilities.ts | 25 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-call-button-reactivity.md diff --git a/.changeset/fix-call-button-reactivity.md b/.changeset/fix-call-button-reactivity.md new file mode 100644 index 000000000..8f4c124db --- /dev/null +++ b/.changeset/fix-call-button-reactivity.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +Ensure call buttons appear/disappear when relevant state events occur. diff --git a/src/app/hooks/useCallStartCapabilities.ts b/src/app/hooks/useCallStartCapabilities.ts index 8e2d55813..e2d80c581 100644 --- a/src/app/hooks/useCallStartCapabilities.ts +++ b/src/app/hooks/useCallStartCapabilities.ts @@ -1,8 +1,11 @@ -import { useMemo } from 'react'; +import { useCallback, useMemo } from 'react'; import type { Room } from '$types/matrix-sdk'; +import { EventType } from '$types/matrix-sdk'; import { useCallEmbed } from '$hooks/useCallEmbed'; import { useLivekitSupport } from '$hooks/useLivekitSupport'; import { useMatrixClient } from '$hooks/useMatrixClient'; +import { useStateEventCallback } from '$hooks/useStateEventCallback'; +import { useForceUpdate } from '$hooks/useForceUpdate'; import { webRTCSupported } from '$utils/rtc'; import { evaluateCallStartCapabilities, @@ -15,6 +18,24 @@ export const useCallStartCapabilities = (room: Room): CallStartCapabilities => { const livekitSupported = useLivekitSupport(); const rtcSupported = webRTCSupported(); const myUserId = mx.getSafeUserId(); + const [updateCount, forceUpdate] = useForceUpdate(); + + useStateEventCallback( + mx, + useCallback( + (event) => { + if (event.getRoomId() !== room.roomId) return; + const eventType = event.getType(); + if ( + eventType === (EventType.RoomPowerLevels as string) || + (eventType === (EventType.RoomMember as string) && event.getStateKey() === myUserId) + ) { + forceUpdate(); + } + }, + [room.roomId, myUserId, forceUpdate] + ) + ); return useMemo( () => @@ -25,6 +46,6 @@ export const useCallStartCapabilities = (room: Room): CallStartCapabilities => { livekitSupported, rtcSupported, }), - [room, myUserId, callEmbed?.roomId, livekitSupported, rtcSupported] + [room, myUserId, callEmbed?.roomId, livekitSupported, rtcSupported, updateCount] ); };