mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-11 01:30:29 +03:00
Remove extra comments and unneeded helper function
This commit is contained in:
parent
0106fab00b
commit
2c8ae9693b
1 changed files with 7 additions and 30 deletions
|
|
@ -1,44 +1,25 @@
|
||||||
import React, { useEffect } from 'react';
|
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 { logger } from 'matrix-js-sdk/lib/logger';
|
||||||
|
|
||||||
import { useCallState } from '../client/CallProvider'; // Adjust path if needed
|
import { useCallState } from '../client/CallProvider';
|
||||||
import { useMatrixClient } from '../../hooks/useMatrixClient'; // Adjust path if needed
|
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<typeof useMatrixClient>): 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() {
|
export function CallActivationEffect() {
|
||||||
// Get the currently viewed room ID from the router
|
|
||||||
const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>();
|
const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>();
|
||||||
// Get the call state and setter from context
|
|
||||||
const { activeCallRoomId, setActiveCallRoomId } = useCallState();
|
const { activeCallRoomId, setActiveCallRoomId } = useCallState();
|
||||||
// Get the Matrix client instance
|
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
const room = mx.getRoom(viewedRoomId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Ensure we have the necessary data to proceed
|
|
||||||
if (!viewedRoomId || !mx) {
|
if (!viewedRoomId || !mx) {
|
||||||
logger.error('CallActivationEffect: Missing viewedRoomId or MatrixClient.');
|
logger.error('CallActivationEffect: Missing viewedRoomId or MatrixClient.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the currently viewed room is a voice/call channel
|
const isViewingCallRoom = room?.isCallRoom?.() ?? false;
|
||||||
const isViewingCallChannel = isRoomVoiceChannel(viewedRoomId, mx);
|
|
||||||
|
|
||||||
if (isViewingCallChannel) {
|
if (isViewingCallRoom) {
|
||||||
// If the user is viewing a call channel and it's not already the
|
|
||||||
// one active in the persistent container, activate it.
|
|
||||||
if (viewedRoomId !== activeCallRoomId) {
|
if (viewedRoomId !== activeCallRoomId) {
|
||||||
logger.info(`CallActivationEffect: Auto-activating call for viewed room: ${viewedRoomId}`);
|
logger.info(`CallActivationEffect: Auto-activating call for viewed room: ${viewedRoomId}`);
|
||||||
setActiveCallRoomId(viewedRoomId);
|
setActiveCallRoomId(viewedRoomId);
|
||||||
|
|
@ -48,11 +29,7 @@ export function CallActivationEffect() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No 'else' block needed here if we want the call to persist when navigating
|
}, [viewedRoomId, activeCallRoomId, setActiveCallRoomId, mx, room]);
|
||||||
// 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
|
|
||||||
|
|
||||||
// This component doesn't render any UI itself
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue