aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/profile/ProfileBody.tsx23
-rw-r--r--src/routes/Routes.tsx5
-rw-r--r--src/screens/onboarding/Login.tsx6
3 files changed, 21 insertions, 13 deletions
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<ProfileBodyProps> = ({
};
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 (
diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx
index adc6253b..5ce0c771 100644
--- a/src/routes/Routes.tsx
+++ b/src/routes/Routes.tsx
@@ -54,11 +54,14 @@ const Routes: React.FC = () => {
if (userId) {
fcmService.setUpPushNotifications();
fcmService.sendFcmTokenToServer();
- connectChatAccount(loggedInUserId, chatClient);
}
}, []);
useEffect(() => {
+ connectChatAccount(loggedInUserId, chatClient);
+ }, [loggedInUserId]);
+
+ useEffect(() => {
const checkVersion = async () => {
const liveVersions = await getCurrentLiveVersions();
if (liveVersions && !liveVersions.includes(DeviceInfo.getVersion())) {
diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx
index 4f2b6a64..6d9abf82 100644
--- a/src/screens/onboarding/Login.tsx
+++ b/src/screens/onboarding/Login.tsx
@@ -29,7 +29,7 @@ import {OnboardingStackParams} from '../../routes/onboarding';
import {fcmService} from '../../services';
import {RootState} from '../../store/rootReducer';
import {BackgroundGradientType, UniversityType} from '../../types';
-import {normalize, userLogin} from '../../utils';
+import {connectChatAccount, normalize, userLogin} from '../../utils';
import UpdateRequired from './UpdateRequired';
type VerificationScreenRouteProp = RouteProp<OnboardingStackParams, 'Login'>;
@@ -162,14 +162,14 @@ const Login: React.FC<LoginProps> = ({navigation}: LoginProps) => {
await AsyncStorage.setItem('token', data.token);
await AsyncStorage.setItem('userId', data.UserID);
await AsyncStorage.setItem('username', username);
- await AsyncStorage.setItem('chatToken', data.chatToken);
}
if (statusCode === 200 && data.isOnboarded) {
//Stores token received in the response into client's AsynStorage
try {
- userLogin(dispatch, {userId: data.UserID, username}, chatClient);
+ userLogin(dispatch, {userId: data.UserID, username});
fcmService.sendFcmTokenToServer();
+ connectChatAccount(data.UserID, chatClient);
} catch (err) {
Alert.alert(ERROR_INVALID_LOGIN);
}