mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 11:56:25 -08:00
fix call button reactivity
This commit is contained in:
1 parent
16b3498b90
commit
45800edf4a
2 files changed
+28
-2
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Ensure call buttons appear/disappear when relevant state events occur.
|
||||
@@ -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]
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user