mattermost-mobile/app/screens/channel/channel.tsx
Elias Nahum a5a1e53827
Biometric prompt, Jailbreak / Root detection and screenshot prevention (#8645)
* Handle biometric authentication

* jailbreak/root detection and biometric small fixes

* remove server from initializeSecurityManager and fix loginEntry

* Add screen capture prevention and other small fixes

* added unit tests to SecurityManager

* added shielded nativeID to protect views

* use MobilePreventScreenCapture instead of MobileAllowScreenshots in config type definition

* Apply Swizzle for screen capture on iOS

* Apply patch to bottom sheet to prevent screen captures

* fix ios sendReply

* Fix SDWebImage swizzle to use the correct session

* Fix potential crash on Android when using hardware keyboard

* rename patch for network library to remove warning

* add temp emm reference

* fix initializeSecurityManager tests

* fix translations

* use siteName for jailbreak detection when connecting to a new server

* fix i18n typo

* do not query the entire config from the db only the required fields

* migrate manage_apps to use defineMessages

* use TestHelper.wait in tests

* use defineMessages for security manager

* fix missing else statement for gm_to_channel

* created a TestHelper function to mockQuery and replace as jest.Mock with jest.mocked

* fix unit tests

* fix unit tests (again) and include setting the test environment to UTC

* Fix keyboard disappearing on iOS

* update react-native-emm
2025-03-13 14:07:41 -04:00

161 lines
5.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useEffect, useState} from 'react';
import {type LayoutChangeEvent, StyleSheet, View} from 'react-native';
import {type Edge, SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
import {storeLastViewedChannelIdAndServer, removeLastViewedChannelIdAndServer} from '@actions/app/global';
import FloatingCallContainer from '@calls/components/floating_call_container';
import FreezeScreen from '@components/freeze_screen';
import PostDraft from '@components/post_draft';
import {ExtraKeyboardProvider} from '@context/extra_keyboard';
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
import {useChannelSwitch} from '@hooks/channel_switch';
import {useIsTablet} from '@hooks/device';
import {useDefaultHeaderHeight} from '@hooks/header';
import {useTeamSwitch} from '@hooks/team_switch';
import SecurityManager from '@managers/security_manager';
import {popTopScreen} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import ChannelPostList from './channel_post_list';
import ChannelHeader from './header';
import useGMasDMNotice from './use_gm_as_dm_notice';
import type PreferenceModel from '@typings/database/models/servers/preference';
import type {AvailableScreens} from '@typings/screens/navigation';
type ChannelProps = {
channelId: string;
componentId?: AvailableScreens;
showJoinCallBanner: boolean;
isInACall: boolean;
isCallsEnabledInChannel: boolean;
groupCallsAllowed: boolean;
showIncomingCalls: boolean;
isTabletView?: boolean;
dismissedGMasDMNotice: PreferenceModel[];
currentUserId: string;
channelType: ChannelType;
hasGMasDMFeature: boolean;
includeBookmarkBar?: boolean;
};
const edges: Edge[] = ['left', 'right'];
const styles = StyleSheet.create({
flex: {
flex: 1,
},
});
const Channel = ({
channelId,
componentId,
showJoinCallBanner,
isInACall,
isCallsEnabledInChannel,
groupCallsAllowed,
showIncomingCalls,
isTabletView,
dismissedGMasDMNotice,
channelType,
currentUserId,
hasGMasDMFeature,
includeBookmarkBar,
}: ChannelProps) => {
useGMasDMNotice(currentUserId, channelType, dismissedGMasDMNotice, hasGMasDMFeature);
const isTablet = useIsTablet();
const insets = useSafeAreaInsets();
const [shouldRenderPosts, setShouldRenderPosts] = useState(false);
const switchingTeam = useTeamSwitch();
const switchingChannels = useChannelSwitch();
const defaultHeight = useDefaultHeaderHeight();
const [containerHeight, setContainerHeight] = useState(0);
const shouldRender = !switchingTeam && !switchingChannels && shouldRenderPosts && Boolean(channelId);
const handleBack = useCallback(() => {
popTopScreen(componentId);
}, [componentId]);
useAndroidHardwareBackHandler(componentId, handleBack);
const marginTop = defaultHeight + (isTablet ? 0 : -insets.top);
useEffect(() => {
// This is done so that the header renders
// and the screen does not look totally blank
const raf = requestAnimationFrame(() => {
setShouldRenderPosts(Boolean(channelId));
});
// This is done to give time to the WS event
const t = setTimeout(() => {
EphemeralStore.removeSwitchingToChannel(channelId);
}, 500);
storeLastViewedChannelIdAndServer(channelId);
return () => {
cancelAnimationFrame(raf);
clearTimeout(t);
removeLastViewedChannelIdAndServer();
EphemeralStore.removeSwitchingToChannel(channelId);
};
}, [channelId]);
const onLayout = useCallback((e: LayoutChangeEvent) => {
setContainerHeight(e.nativeEvent.layout.height);
}, []);
const showFloatingCallContainer = showJoinCallBanner || isInACall || showIncomingCalls;
return (
<FreezeScreen>
<SafeAreaView
style={styles.flex}
mode='margin'
edges={edges}
testID='channel.screen'
onLayout={onLayout}
nativeID={componentId ? SecurityManager.getShieldScreenId(componentId) : undefined}
>
<ChannelHeader
channelId={channelId}
componentId={componentId}
callsEnabledInChannel={isCallsEnabledInChannel}
groupCallsAllowed={groupCallsAllowed}
isTabletView={isTabletView}
shouldRenderBookmarks={shouldRender}
/>
{shouldRender &&
<ExtraKeyboardProvider>
<View style={[styles.flex, {marginTop}]}>
<ChannelPostList
channelId={channelId}
nativeID={channelId}
/>
</View>
<PostDraft
channelId={channelId}
testID='channel.post_draft'
containerHeight={containerHeight}
isChannelScreen={true}
canShowPostPriority={true}
/>
</ExtraKeyboardProvider>
}
{showFloatingCallContainer && shouldRender &&
<FloatingCallContainer
channelId={channelId}
showJoinCallBanner={showJoinCallBanner}
showIncomingCalls={showIncomingCalls}
isInACall={isInACall}
includeBookmarkBar={includeBookmarkBar}
/>
}
</SafeAreaView>
</FreezeScreen>
);
};
export default Channel;