mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 20:06:26 -08:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useAtom, useAtomValue } from 'jotai';
|
|
import { useCallStart } from '$hooks/useCallEmbed';
|
|
import { useMatrixClient } from '$hooks/useMatrixClient';
|
|
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
|
import { autoJoinCallIntentAtom } from '$state/callEmbed';
|
|
import { mDirectAtom } from '$state/mDirectList';
|
|
|
|
export function useAutoJoinCall() {
|
|
const mx = useMatrixClient();
|
|
const selectedRoomId = useSelectedRoom();
|
|
const [autoJoinIntent, setAutoJoinIntent] = useAtom(autoJoinCallIntentAtom);
|
|
const mDirects = useAtomValue(mDirectAtom);
|
|
const startDirectCall = useCallStart(true);
|
|
const startRoomCall = useCallStart(false);
|
|
|
|
useEffect(() => {
|
|
if (selectedRoomId && autoJoinIntent && selectedRoomId === autoJoinIntent) {
|
|
const room = mx.getRoom(selectedRoomId);
|
|
|
|
if (room) {
|
|
const startCall = mDirects.has(room.roomId) ? startDirectCall : startRoomCall;
|
|
startCall(room);
|
|
setAutoJoinIntent(null);
|
|
}
|
|
}
|
|
}, [
|
|
selectedRoomId,
|
|
autoJoinIntent,
|
|
setAutoJoinIntent,
|
|
mx,
|
|
mDirects,
|
|
startDirectCall,
|
|
startRoomCall,
|
|
]);
|
|
}
|