diff options
-rw-r--r-- | src/components/profile/ProfileBody.tsx | 2 | ||||
-rw-r--r-- | src/routes/Routes.tsx | 4 | ||||
-rw-r--r-- | src/screens/chat/ChatListScreen.tsx | 22 | ||||
-rw-r--r-- | src/utils/messages.ts | 9 |
4 files changed, 18 insertions, 19 deletions
diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 527036f6..ea1e5166 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -21,7 +21,6 @@ import {NO_PROFILE} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {ScreenType} from '../../types'; import { - connectChatAccount, createChannel, getUserAsProfilePreviewType, SCREEN_HEIGHT, @@ -31,7 +30,6 @@ import {FriendsButton, BasicButton} from '../common'; import ToggleButton from './ToggleButton'; import {ChatContext} from '../../App'; import {useNavigation} from '@react-navigation/core'; -import {ChatListScreen} from '../../screens'; import {ERROR_UNABLE_CONNECT_CHAT} from '../../constants/strings'; interface ProfileBodyProps { diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx index 5ce0c771..04c081da 100644 --- a/src/routes/Routes.tsx +++ b/src/routes/Routes.tsx @@ -58,7 +58,9 @@ const Routes: React.FC = () => { }, []); useEffect(() => { - connectChatAccount(loggedInUserId, chatClient); + if (loggedInUserId) { + connectChatAccount(loggedInUserId, chatClient); + } }, [loggedInUserId]); useEffect(() => { diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index 0cbc7592..d2cfcb5d 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -56,17 +56,19 @@ const ChatListScreen: React.FC<ChatListScreenProps> = () => { }; useEffect(() => { - connectChatAccount(loggedInUserId, chatClient) - .then((success) => { - if (!success) { + if (loggedInUserId) { + connectChatAccount(loggedInUserId, chatClient) + .then((success) => { + if (!success) { + Alert.alert('Something wrong with chat'); + } + }) + .catch((err) => { + console.log('Error connecting to chat: ', err); Alert.alert('Something wrong with chat'); - } - }) - .catch((err) => { - console.log('Error connecting to chat: ', err); - Alert.alert('Something wrong with chat'); - }); - }, []); + }); + } + }, [loggedInUserId]); return ( <View style={styles.background}> diff --git a/src/utils/messages.ts b/src/utils/messages.ts index dd29f317..f4215bf0 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -114,13 +114,10 @@ export const connectChatAccount = async ( export const getChatToken = async () => { try { - const currentChatToken = await AsyncStorage.getItem('chatToken'); - if (currentChatToken === null) { - const chatToken = await loadChatTokenService(); - await AsyncStorage.setItem('chatToken', chatToken); - } + const chatToken = await loadChatTokenService(); + await AsyncStorage.setItem('chatToken', chatToken); } catch (err) { - console.log(err); + console.log('Exception while loading chat token: ', err); } }; |