From 2c8ae9693b699ec17462a374db2f45a20fe87963 Mon Sep 17 00:00:00 2001 From: Gigiaj Date: Wed, 16 Apr 2025 20:43:56 -0500 Subject: [PATCH] Remove extra comments and unneeded helper function --- src/app/pages/call/CallActivation.tsx | 37 +++++---------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/app/pages/call/CallActivation.tsx b/src/app/pages/call/CallActivation.tsx index dca77a1f..7e8f4580 100644 --- a/src/app/pages/call/CallActivation.tsx +++ b/src/app/pages/call/CallActivation.tsx @@ -1,44 +1,25 @@ import React, { useEffect } from 'react'; -import { useParams } from 'react-router-dom'; // Or your router's equivalent hook +import { useParams } from 'react-router-dom'; import { logger } from 'matrix-js-sdk/lib/logger'; -import { useCallState } from '../client/CallProvider'; // Adjust path if needed -import { useMatrixClient } from '../../hooks/useMatrixClient'; // Adjust path if needed +import { useCallState } from '../client/CallProvider'; +import { useMatrixClient } from '../../hooks/useMatrixClient'; -// Helper function (replace with your actual implementation) -// This function determines if a room ID corresponds to a call/voice channel -const isRoomVoiceChannel = (roomId: string, mx: ReturnType): boolean => { - if (!mx) return false; - const room = mx.getRoom(roomId); - // Example check - use your specific logic (e.g., checking room type, state events) - return room?.isCallRoom?.() ?? false; -}; - -/** - * This component runs an effect to automatically activate the call state - * when the user navigates to a room designated as a call/voice channel. - */ export function CallActivationEffect() { - // Get the currently viewed room ID from the router const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>(); - // Get the call state and setter from context const { activeCallRoomId, setActiveCallRoomId } = useCallState(); - // Get the Matrix client instance const mx = useMatrixClient(); + const room = mx.getRoom(viewedRoomId); useEffect(() => { - // Ensure we have the necessary data to proceed if (!viewedRoomId || !mx) { logger.error('CallActivationEffect: Missing viewedRoomId or MatrixClient.'); return; } - // Check if the currently viewed room is a voice/call channel - const isViewingCallChannel = isRoomVoiceChannel(viewedRoomId, mx); + const isViewingCallRoom = room?.isCallRoom?.() ?? false; - if (isViewingCallChannel) { - // If the user is viewing a call channel and it's not already the - // one active in the persistent container, activate it. + if (isViewingCallRoom) { if (viewedRoomId !== activeCallRoomId) { logger.info(`CallActivationEffect: Auto-activating call for viewed room: ${viewedRoomId}`); setActiveCallRoomId(viewedRoomId); @@ -48,11 +29,7 @@ export function CallActivationEffect() { ); } } - // No 'else' block needed here if we want the call to persist when navigating - // to a non-call room. If you wanted to auto-hangup on navigating away, - // you would add: else if (activeCallRoomId === viewedRoomId) { setActiveCallRoomId(null); } - }, [viewedRoomId, activeCallRoomId, setActiveCallRoomId, mx]); // Effect dependencies + }, [viewedRoomId, activeCallRoomId, setActiveCallRoomId, mx, room]); - // This component doesn't render any UI itself return null; }