11import type { IRoom , IMessage } from '@rocket.chat/core-typings' ;
22import { useStableCallback } from '@rocket.chat/fuselage-hooks' ;
33import type { UiKitContext } from '@rocket.chat/fuselage-ui-kit' ;
4- import { useRoomToolbox } from '@rocket.chat/ui-contexts' ;
4+ import { useRoomToolbox , useRouter } from '@rocket.chat/ui-contexts' ;
55import {
66 useVideoConfDispatchOutgoing ,
77 useVideoConfIsCalling ,
@@ -10,7 +10,7 @@ import {
1010 useVideoConfLoadCapabilities ,
1111 useVideoConfSetPreferences ,
1212} from '@rocket.chat/ui-video-conf' ;
13- import type { ContextType } from 'react' ;
13+ import { useCallback , useSyncExternalStore , type ContextType } from 'react' ;
1414
1515import { useUiKitActionManager } from './useUiKitActionManager' ;
1616import { useVideoConfWarning } from '../../views/room/contextualBar/VideoConference/hooks/useVideoConfWarning' ;
@@ -24,6 +24,14 @@ export const useMessageBlockContextValue = (rid: IRoom['_id'], mid: IMessage['_i
2424 const dispatchPopup = useVideoConfDispatchOutgoing ( ) ;
2525 const loadVideoConfCapabilities = useVideoConfLoadCapabilities ( ) ;
2626
27+ // Inside a conference window, block message-block actions that would open/join another conference.
28+ const router = useRouter ( ) ;
29+ const routeName = useSyncExternalStore (
30+ router . subscribeToRouteChange ,
31+ useCallback ( ( ) => router . getRouteName ( ) , [ router ] ) ,
32+ ) ;
33+ const videoConfJoinDisabled = routeName === 'conference' ;
34+
2735 const handleOpenVideoConf = useStableCallback ( async ( rid : IRoom [ '_id' ] ) => {
2836 if ( isCalling || isRinging ) {
2937 return ;
@@ -45,6 +53,10 @@ export const useMessageBlockContextValue = (rid: IRoom['_id'], mid: IMessage['_i
4553 action : ( { appId, actionId, blockId, value } , event ) => {
4654 if ( appId === 'videoconf-core' ) {
4755 event . preventDefault ( ) ;
56+ // Don't let a user in a conference open/join another conference from a message block.
57+ if ( videoConfJoinDisabled && ( actionId === 'join' || actionId === 'callBack' ) ) {
58+ return undefined ;
59+ }
4860 setPreferences ( { mic : true , cam : false } ) ;
4961 if ( actionId === 'join' ) {
5062 return joinCall ( blockId ) ;
@@ -77,6 +89,7 @@ export const useMessageBlockContextValue = (rid: IRoom['_id'], mid: IMessage['_i
7789 } ) ;
7890 } ,
7991 rid,
92+ videoConfJoinDisabled,
8093 values : { } , // TODO: this is a hack to make the context work, but it should be removed
8194 } ;
8295} ;
0 commit comments