From b967bd77710bce7b92ae0863df52cce345abd4e4 Mon Sep 17 00:00:00 2001
From: Shravya Ramesh <shravs1208@gmail.com>
Date: Fri, 9 Apr 2021 12:20:25 -0700
Subject: connecting user during login

---
 src/components/profile/Content.tsx | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

(limited to 'src/components/profile/Content.tsx')

diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx
index 05098d14..0d2a0331 100644
--- a/src/components/profile/Content.tsx
+++ b/src/components/profile/Content.tsx
@@ -1,4 +1,10 @@
-import React, {useCallback, useEffect, useRef, useState} from 'react';
+import React, {
+  useCallback,
+  useContext,
+  useEffect,
+  useRef,
+  useState,
+} from 'react';
 import {LayoutChangeEvent, RefreshControl, StyleSheet} from 'react-native';
 import Animated, {
   useSharedValue,
@@ -31,6 +37,7 @@ import ProfileCutout from './ProfileCutout';
 import ProfileHeader from './ProfileHeader';
 import PublicProfile from './PublicProfile';
 import {useScrollToTop} from '@react-navigation/native';
+import {ChatContext} from '../../App';
 
 interface ContentProps {
   userXId: string | undefined;
@@ -52,6 +59,8 @@ const Content: React.FC<ContentProps> = ({userXId, screenType}) => {
   );
   const state: RootState = useStore().getState();
 
+  const {chatClient} = useContext(ChatContext);
+
   /*
    * Used to imperatively scroll to the top when presenting the moment tutorial.
    */
@@ -75,7 +84,7 @@ const Content: React.FC<ContentProps> = ({userXId, screenType}) => {
     const refrestState = async () => {
       setRefreshing(true);
       if (!userXId) {
-        await userLogin(dispatch, loggedInUser);
+        await userLogin(dispatch, loggedInUser, chatClient);
       } else {
         await fetchUserX(dispatch, user, screenType);
       }
-- 
cgit v1.2.3-70-g09d2


From 45041863a432ed5ba02f896f0c4f3c23ae7830ed Mon Sep 17 00:00:00 2001
From: Shravya Ramesh <shravs1208@gmail.com>
Date: Fri, 9 Apr 2021 14:37:06 -0700
Subject: removed chat client inside userlogin

---
 src/components/profile/Content.tsx                    |  2 +-
 src/screens/onboarding/CategorySelection.tsx          |  2 +-
 src/screens/onboarding/InvitationCodeVerification.tsx |  2 +-
 src/store/reducers/userReducer.ts                     |  5 +----
 src/utils/users.ts                                    | 10 +---------
 5 files changed, 5 insertions(+), 16 deletions(-)

(limited to 'src/components/profile/Content.tsx')

diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx
index 0d2a0331..0052b61d 100644
--- a/src/components/profile/Content.tsx
+++ b/src/components/profile/Content.tsx
@@ -84,7 +84,7 @@ const Content: React.FC<ContentProps> = ({userXId, screenType}) => {
     const refrestState = async () => {
       setRefreshing(true);
       if (!userXId) {
-        await userLogin(dispatch, loggedInUser, chatClient);
+        await userLogin(dispatch, loggedInUser);
       } else {
         await fetchUserX(dispatch, user, screenType);
       }
diff --git a/src/screens/onboarding/CategorySelection.tsx b/src/screens/onboarding/CategorySelection.tsx
index 1407575c..ab5ff3be 100644
--- a/src/screens/onboarding/CategorySelection.tsx
+++ b/src/screens/onboarding/CategorySelection.tsx
@@ -170,7 +170,7 @@ const CategorySelection: React.FC<CategorySelectionProps> = ({
         dispatch(updateIsOnboardedUser(true));
         const token = await getTokenOrLogout(dispatch);
         await postMomentCategories(selectedCategories, token);
-        userLogin(dispatch, {userId: userId, username: username}, chatClient);
+        userLogin(dispatch, {userId: userId, username: username});
       } else {
         dispatch(
           updateMomentCategories(
diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx
index 774a7a11..6bc0ac9d 100644
--- a/src/screens/onboarding/InvitationCodeVerification.tsx
+++ b/src/screens/onboarding/InvitationCodeVerification.tsx
@@ -79,7 +79,7 @@ const InvitationCodeVerification: React.FC<InvitationCodeVerificationProps> = ({
           const username = route.params.username;
           await AsyncStorage.setItem('userId', userId);
           await AsyncStorage.setItem('username', username);
-          userLogin(dispatch, {userId, username}, chatClient);
+          userLogin(dispatch, {userId, username});
         } else {
           Alert.alert(ERROR_INVALID_INVITATION_CODE);
         }
diff --git a/src/store/reducers/userReducer.ts b/src/store/reducers/userReducer.ts
index 0b958cac..a8789c1d 100644
--- a/src/store/reducers/userReducer.ts
+++ b/src/store/reducers/userReducer.ts
@@ -75,9 +75,6 @@ const userDataSlice = createSlice({
       state.avatar = '';
       state.cover = '';
     },
-    setChatClientReady: (state, action) => {
-      state.chatClientReady = action.payload.chatClientReady;
-    },
   },
 });
 
@@ -93,6 +90,6 @@ export const {
   setReplyPosted,
   setSuggestedPeopleImage,
   clearHeaderAndProfileImages,
-  setChatClientReady,
+  // setChatClientReady,
 } = userDataSlice.actions;
 export const userDataReducer = userDataSlice.reducer;
diff --git a/src/utils/users.ts b/src/utils/users.ts
index ec09198d..7148eb79 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -22,7 +22,6 @@ import {
   ScreenType,
   UserType,
 } from './../types/types';
-import {connectChatAccount} from './messages';
 
 const loadData = async (dispatch: AppDispatch, user: UserType) => {
   await Promise.all([
@@ -43,11 +42,7 @@ const loadData = async (dispatch: AppDispatch, user: UserType) => {
  * @param dispatch This is the dispatch object from the redux store
  * @param user The user if at all any
  */
-export const userLogin = async (
-  dispatch: AppDispatch,
-  user: UserType,
-  chatClient?,
-) => {
+export const userLogin = async (dispatch: AppDispatch, user: UserType) => {
   try {
     let localUser = {...user};
     if (!user.userId) {
@@ -67,9 +62,6 @@ export const userLogin = async (
         AsyncStorage.setItem('username', user.username),
       ]);
     }
-    if (chatClient) {
-      connectChatAccount(localUser.userId, chatClient, dispatch);
-    }
     await loadData(dispatch, localUser);
   } catch (error) {
     console.log(error);
-- 
cgit v1.2.3-70-g09d2

