11import { Image } from 'expo-image' ;
2- import { type Href , Stack , useFocusEffect , useLocalSearchParams , useRouter } from 'expo-router' ;
2+ import { type Href , Redirect , Stack , useFocusEffect , useLocalSearchParams , useRouter } from 'expo-router' ;
33import { Circle } from 'lucide-react-native' ;
44import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
55import { useTranslation } from 'react-i18next' ;
@@ -27,6 +27,7 @@ import { VStack } from '@/components/ui/vstack';
2727import { ChatChannelType , ChatMessagePriority , type ChatMessageResultData , ChatMessageType , type GifResultData } from '@/models/v4/chat' ;
2828import useAuthStore from '@/stores/auth/store' ;
2929import { useChatStore } from '@/stores/chat/store' ;
30+ import { useIsChatEnabled } from '@/stores/feature-flags/store' ;
3031import { securityStore } from '@/stores/security/store' ;
3132import { useToastStore } from '@/stores/toast/store' ;
3233
@@ -38,6 +39,7 @@ export default function ChannelConversationScreen() {
3839
3940 const currentUserId = useAuthStore ( ( s ) => s . userId ) ;
4041 const isModerator = ! ! securityStore ( ( s ) => s . rights ) ?. IsAdmin ;
42+ const isChatEnabled = useIsChatEnabled ( ) ;
4143
4244 const channel = useChatStore ( ( s ) => s . channels . find ( ( c ) => c . ChatChannelId === channelId ) ) ;
4345 const messages = useChatStore ( ( s ) => ( channelId ? s . messagesByChannel [ channelId ] : undefined ) ) ;
@@ -64,7 +66,7 @@ export default function ChannelConversationScreen() {
6466 // Mount: activate channel, join hub, load history and members.
6567 useFocusEffect (
6668 useCallback ( ( ) => {
67- if ( ! channelId ) return ;
69+ if ( ! channelId || ! isChatEnabled ) return ;
6870 const store = useChatStore . getState ( ) ;
6971 store . setActiveChannel ( channelId ) ;
7072 void store . joinChannel ( channelId ) ;
@@ -73,7 +75,7 @@ export default function ChannelConversationScreen() {
7375 return ( ) => {
7476 useChatStore . getState ( ) . setActiveChannel ( null ) ;
7577 } ;
76- } , [ channelId ] )
78+ } , [ channelId , isChatEnabled ] )
7779 ) ;
7880
7981 // Fetch presence for the channel members (for the header online dot).
@@ -234,6 +236,11 @@ export default function ChannelConversationScreen() {
234236 if ( channelId ) void useChatStore . getState ( ) . loadOlderMessages ( channelId ) ;
235237 } , [ channelId ] ) ;
236238
239+ // Chat.System feature flag off: no chat for this department.
240+ if ( ! isChatEnabled ) {
241+ return < Redirect href = { '/home' as Href } /> ;
242+ }
243+
237244 const title = channel ? getChannelDisplayName ( channel , t ) : t ( 'chat.title' ) ;
238245
239246 return (
0 commit comments