From 3d26676ea1e818b585b4b224f643524994a0e893 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 14:40:03 -0700 Subject: Connecting during login, app entry, msg btn tap --- src/components/profile/ProfileBody.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/components') diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index e23249fa..eebdb167 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -21,6 +21,7 @@ import {NO_PROFILE} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; import { + connectChatAccount, getUserAsProfilePreviewType, SCREEN_HEIGHT, SCREEN_WIDTH, @@ -96,16 +97,20 @@ const ProfileBody: React.FC = ({ }; const onPressMessage = async () => { - if (!chatClient.user) { - // TODO: Add refresh control to retry establishing chat connection - Alert.alert('Unable to connect chat'); + let connected: boolean = !chatClient.user; + if (!connected) { + connected = await connectChatAccount(loggedInUserId, chatClient); + if (!connected) { + Alert.alert('Unable to connect chat'); + } + } else { + const channel = chatClient.channel('messaging', { + members: [loggedInUserId, String(userXId)], + }); + channel.create(); + setChannel(channel); + navigation.navigate('Chat'); } - const channel = chatClient.channel('messaging', { - members: [loggedInUserId, String(userXId)], - }); - channel.create(); - setChannel(channel); - navigation.navigate('Chat'); }; return ( -- cgit v1.2.3-70-g09d2