From 0a09c73cabc656b85465102b8e266e1a0cc1fdf2 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 11:28:36 -0700 Subject: Added a function to utils to connect a chat user --- src/utils/messages.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/utils/messages.ts') diff --git a/src/utils/messages.ts b/src/utils/messages.ts index d63f2b7a..0ef56edb 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -1,4 +1,7 @@ +import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; +import {updateChatClientReady} from '../store/actions'; +import {AppDispatch} from '../store/configureStore'; import {RootState} from '../store/rootReducer'; import {ChannelGroupedType} from '../types'; @@ -81,3 +84,23 @@ export const getMember = ( : []; return otherMembers.length === 1 ? otherMembers[0] : undefined; }; + +export const connectChatAccount = async ( + loggedInUserId: string, + chatClient, + dispatch: AppDispatch, +) => { + try { + const chatToken = await AsyncStorage.getItem('chatToken'); + chatClient.connectUser( + { + id: loggedInUserId, + }, + chatToken, + ); + dispatch(updateChatClientReady(true)); + } catch (err) { + dispatch(updateChatClientReady(true)); + console.log('Error while connecting user to Stream: ', err); + } +}; -- cgit v1.2.3-70-g09d2 From b967bd77710bce7b92ae0863df52cce345abd4e4 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 12:20:25 -0700 Subject: connecting user during login --- src/components/profile/Content.tsx | 13 ++++++++-- src/screens/chat/ChatListScreen.tsx | 28 +++++++--------------- src/screens/onboarding/CategorySelection.tsx | 6 +++-- .../onboarding/InvitationCodeVerification.tsx | 6 +++-- src/screens/onboarding/Login.tsx | 6 +++-- src/utils/messages.ts | 4 ++-- src/utils/users.ts | 12 +++++++--- 7 files changed, 43 insertions(+), 32 deletions(-) (limited to 'src/utils/messages.ts') 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 = ({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 = ({userXId, screenType}) => { const refrestState = async () => { setRefreshing(true); if (!userXId) { - await userLogin(dispatch, loggedInUser); + await userLogin(dispatch, loggedInUser, chatClient); } else { await fetchUserX(dispatch, user, screenType); } diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index 3290116b..dbdb7994 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -1,8 +1,8 @@ import AsyncStorage from '@react-native-community/async-storage'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useContext, useEffect, useMemo, useState} from 'react'; -import {SafeAreaView, StatusBar, StyleSheet, View} from 'react-native'; -import {useStore} from 'react-redux'; +import {Alert, SafeAreaView, StatusBar, StyleSheet, View} from 'react-native'; +import {useSelector, useStore} from 'react-redux'; import {ChannelList, Chat} from 'stream-chat-react-native'; import {ChatContext} from '../../App'; import {TabsGradient} from '../../components'; @@ -31,7 +31,9 @@ interface ChatListScreenProps { */ const ChatListScreen: React.FC = () => { const {chatClient} = useContext(ChatContext); - const [clientReady, setClientReady] = useState(false); + const chatClientReady = useSelector( + (state: RootState) => state.user.chatClientReady, + ); const state: RootState = useStore().getState(); const loggedInUserId = state.user.user.userId; @@ -44,22 +46,10 @@ const ChatListScreen: React.FC = () => { ); useEffect(() => { - const setupClient = async () => { - const chatToken = await AsyncStorage.getItem('chatToken'); - await chatClient.connectUser( - { - id: loggedInUserId, - }, - chatToken, - ); - return setClientReady(true); - }; - if (!clientReady) { - setupClient().catch((err) => { - console.error(err); - }); + if (!chatClientReady) { + Alert.alert('Something wrong with chat'); } - }, []); + }, [chatClientReady]); return ( @@ -75,7 +65,7 @@ const ChatListScreen: React.FC = () => { channel.create(); }} /> - {clientReady && ( + {chatClientReady && ( = ({ * Same component to be used for category selection while onboarding and while on profile */ const {screenType, user} = route.params; + const {chatClient} = useContext(ChatContext); const isOnBoarding: boolean = screenType === CategorySelectionScreenType.Onboarding; const {userId, username} = user; @@ -168,7 +170,7 @@ const CategorySelection: React.FC = ({ dispatch(updateIsOnboardedUser(true)); const token = await getTokenOrLogout(dispatch); await postMomentCategories(selectedCategories, token); - userLogin(dispatch, {userId: userId, username: username}); + userLogin(dispatch, {userId: userId, username: username}, chatClient); } else { dispatch( updateMomentCategories( diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx index e160b4b7..774a7a11 100644 --- a/src/screens/onboarding/InvitationCodeVerification.tsx +++ b/src/screens/onboarding/InvitationCodeVerification.tsx @@ -1,7 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; -import React from 'react'; +import React, {useContext} from 'react'; import {Alert, KeyboardAvoidingView, StyleSheet, View} from 'react-native'; import {Text} from 'react-native-animatable'; import { @@ -27,6 +27,7 @@ import { import {OnboardingStackParams} from '../../routes'; import {BackgroundGradientType} from '../../types'; import {SCREEN_WIDTH, userLogin} from '../../utils'; +import {ChatContext} from '../../App'; type InvitationCodeVerificationRouteProp = RouteProp< OnboardingStackParams, @@ -58,6 +59,7 @@ const InvitationCodeVerification: React.FC = ({ setValue, }); const dispatch = useDispatch(); + const {chatClient} = useContext(ChatContext); const handleInvitationCodeVerification = async () => { if (value.length === 6) { @@ -77,7 +79,7 @@ const InvitationCodeVerification: React.FC = ({ const username = route.params.username; await AsyncStorage.setItem('userId', userId); await AsyncStorage.setItem('username', username); - userLogin(dispatch, {userId, username}); + userLogin(dispatch, {userId, username}, chatClient); } else { Alert.alert(ERROR_INVALID_INVITATION_CODE); } diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index dd2bb2e4..4f2b6a64 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -1,7 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; -import React, {useEffect, useRef} from 'react'; +import React, {useContext, useEffect, useRef} from 'react'; import { Alert, Image, @@ -14,6 +14,7 @@ import { } from 'react-native'; import SplashScreen from 'react-native-splash-screen'; import {useDispatch, useSelector} from 'react-redux'; +import {ChatContext} from '../../App'; import {Background, TaggInput, TaggSquareButton} from '../../components'; import {LOGIN_ENDPOINT, usernameRegex} from '../../constants'; import { @@ -47,6 +48,7 @@ interface LoginProps { const Login: React.FC = ({navigation}: LoginProps) => { // ref for focusing on input fields const inputRef = useRef(); + const {chatClient} = useContext(ChatContext); // login form state const [form, setForm] = React.useState({ @@ -166,7 +168,7 @@ const Login: React.FC = ({navigation}: LoginProps) => { if (statusCode === 200 && data.isOnboarded) { //Stores token received in the response into client's AsynStorage try { - userLogin(dispatch, {userId: data.UserID, username}); + userLogin(dispatch, {userId: data.UserID, username}, chatClient); fcmService.sendFcmTokenToServer(); } catch (err) { Alert.alert(ERROR_INVALID_LOGIN); diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 0ef56edb..b2162d34 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -92,7 +92,7 @@ export const connectChatAccount = async ( ) => { try { const chatToken = await AsyncStorage.getItem('chatToken'); - chatClient.connectUser( + await chatClient.connectUser( { id: loggedInUserId, }, @@ -100,7 +100,7 @@ export const connectChatAccount = async ( ); dispatch(updateChatClientReady(true)); } catch (err) { - dispatch(updateChatClientReady(true)); + dispatch(updateChatClientReady(false)); console.log('Error while connecting user to Stream: ', err); } }; diff --git a/src/utils/users.ts b/src/utils/users.ts index 22c1c1f0..ec09198d 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -12,18 +12,17 @@ import { logout, } from '../store/actions'; import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates'; -import {userLoggedIn} from '../store/reducers'; import {loadUserMomentCategories} from './../store/actions/momentCategories'; import {loadUserX} from './../store/actions/userX'; import {AppDispatch} from './../store/configureStore'; import {RootState} from './../store/rootReducer'; import { ProfilePreviewType, - CategoryPreviewType, ProfileInfoType, ScreenType, UserType, } from './../types/types'; +import {connectChatAccount} from './messages'; const loadData = async (dispatch: AppDispatch, user: UserType) => { await Promise.all([ @@ -44,7 +43,11 @@ 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) => { +export const userLogin = async ( + dispatch: AppDispatch, + user: UserType, + chatClient?, +) => { try { let localUser = {...user}; if (!user.userId) { @@ -64,6 +67,9 @@ export const userLogin = async (dispatch: AppDispatch, user: UserType) => { 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 From bdd1ed17600da7b766e2b0fa97ad4cbf01234819 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 13:46:42 -0700 Subject: removed client ready from redux --- src/components/profile/ProfileBody.tsx | 6 ++-- src/routes/Routes.tsx | 2 +- src/screens/chat/ChatListScreen.tsx | 51 +++++++++++++++------------------- src/store/actions/user.ts | 15 ---------- src/store/initialStates.ts | 1 - src/utils/messages.ts | 4 +-- 6 files changed, 28 insertions(+), 51 deletions(-) (limited to 'src/utils/messages.ts') diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index dc68446b..e23249fa 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -63,7 +63,6 @@ const ProfileBody: React.FC = ({ profile, ); - const {chatClientReady} = useSelector((state: RootState) => state.user); const {chatClient, setChannel} = useContext(ChatContext); const state: RootState = useStore().getState(); @@ -97,8 +96,9 @@ const ProfileBody: React.FC = ({ }; const onPressMessage = async () => { - if (!chatClientReady) { - Alert.alert('Something wrong with chat'); + if (!chatClient.user) { + // TODO: Add refresh control to retry establishing chat connection + Alert.alert('Unable to connect chat'); } const channel = chatClient.channel('messaging', { members: [loggedInUserId, String(userXId)], diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx index 173a6a6c..adc6253b 100644 --- a/src/routes/Routes.tsx +++ b/src/routes/Routes.tsx @@ -54,7 +54,7 @@ const Routes: React.FC = () => { if (userId) { fcmService.setUpPushNotifications(); fcmService.sendFcmTokenToServer(); - connectChatAccount(loggedInUserId, chatClient, dispatch); + connectChatAccount(loggedInUserId, chatClient); } }, []); diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index dbdb7994..eb886232 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -31,9 +31,6 @@ interface ChatListScreenProps { */ const ChatListScreen: React.FC = () => { const {chatClient} = useContext(ChatContext); - const chatClientReady = useSelector( - (state: RootState) => state.user.chatClientReady, - ); const state: RootState = useStore().getState(); const loggedInUserId = state.user.user.userId; @@ -65,31 +62,29 @@ const ChatListScreen: React.FC = () => { channel.create(); }} /> - {chatClientReady && ( - - - - filters={memoizedFilters} - options={{ - presence: true, - state: true, - watch: true, - }} - sort={{last_message_at: -1}} - maxUnreadCount={99} - Preview={ChannelPreview} - /> - - - )} + + + + filters={memoizedFilters} + options={{ + presence: true, + state: true, + watch: true, + }} + sort={{last_message_at: -1}} + maxUnreadCount={99} + Preview={ChannelPreview} + /> + + diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 0ed57fe6..c7d0d5a7 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -11,7 +11,6 @@ import {getTokenOrLogout} from '../../utils'; import { clearHeaderAndProfileImages, profileCompletionStageUpdated, - setChatClientReady, setIsOnboardedUser, setNewNotificationReceived, setNewVersionAvailable, @@ -235,17 +234,3 @@ export const suggestedPeopleAnimatedTutorialFinished = ( } }; -export const updateChatClientReady = ( - chatClientReady: boolean, -): ThunkAction, RootState, unknown, Action> => async ( - dispatch, -) => { - try { - dispatch({ - type: setChatClientReady.type, - payload: {chatClientReady}, - }); - } catch (error) { - console.log(error); - } -}; diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index 546c57a9..02331eb6 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -41,7 +41,6 @@ export const EMPTY_PROFILE_PREVIEW_LIST = []; export const NO_USER_DATA = { user: NO_USER, - chatClientReady: false, profile: NO_PROFILE, avatar: undefined, cover: undefined, diff --git a/src/utils/messages.ts b/src/utils/messages.ts index b2162d34..1c83ca9f 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; -import {updateChatClientReady} from '../store/actions'; +// import {updateChatClientReady} from '../store/actions'; import {AppDispatch} from '../store/configureStore'; import {RootState} from '../store/rootReducer'; import {ChannelGroupedType} from '../types'; @@ -98,9 +98,7 @@ export const connectChatAccount = async ( }, chatToken, ); - dispatch(updateChatClientReady(true)); } catch (err) { - dispatch(updateChatClientReady(false)); console.log('Error while connecting user to Stream: ', err); } }; -- cgit v1.2.3-70-g09d2 From fbfb36b381216e0b50324064c79b0c0f5efc6a6c Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 14:38:44 -0700 Subject: new funtion to get chat token and make connection --- src/utils/messages.ts | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/utils/messages.ts') diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 1c83ca9f..6b972b83 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -1,7 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; -// import {updateChatClientReady} from '../store/actions'; -import {AppDispatch} from '../store/configureStore'; +import {loadChatTokenService} from '../services/ChatService'; import {RootState} from '../store/rootReducer'; import {ChannelGroupedType} from '../types'; @@ -88,17 +87,35 @@ export const getMember = ( export const connectChatAccount = async ( loggedInUserId: string, chatClient, - dispatch: AppDispatch, ) => { try { + await getChatToken(); const chatToken = await AsyncStorage.getItem('chatToken'); - await chatClient.connectUser( - { - id: loggedInUserId, - }, - chatToken, - ); + if (chatToken) { + await chatClient.connectUser( + { + id: loggedInUserId, + }, + chatToken, + ); + return true; + } else { + console.log('Unable to connect to stream. Empty chat token'); + return false; + } } catch (err) { console.log('Error while connecting user to Stream: ', err); + return false; + } +}; + +export const getChatToken = async () => { + try { + if (await AsyncStorage.getItem('chatToken')) { + const chatToken = await loadChatTokenService(); + AsyncStorage.setItem('chatToken', chatToken); + } + } catch (err) { + console.log(err); } }; -- cgit v1.2.3-70-g09d2 From 6527289eb6249cfd057c47d0f797133ab8052339 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 15:19:49 -0700 Subject: major issue fixed --- src/screens/chat/ChatListScreen.tsx | 17 ++++++++++++++--- src/services/ChatService.ts | 6 +++--- src/utils/messages.ts | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/utils/messages.ts') diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index eb886232..f2395f0a 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -3,6 +3,7 @@ import {StackNavigationProp} from '@react-navigation/stack'; import React, {useContext, useEffect, useMemo, useState} from 'react'; import {Alert, SafeAreaView, StatusBar, StyleSheet, View} from 'react-native'; import {useSelector, useStore} from 'react-redux'; +import {connectChatAccount} from '../../utils'; import {ChannelList, Chat} from 'stream-chat-react-native'; import {ChatContext} from '../../App'; import {TabsGradient} from '../../components'; @@ -43,10 +44,20 @@ const ChatListScreen: React.FC = () => { ); useEffect(() => { - if (!chatClientReady) { - Alert.alert('Something wrong with chat'); + let connected: boolean = !chatClient.user; + if (!connected) { + 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'); + }); } - }, [chatClientReady]); + }, []); return ( diff --git a/src/services/ChatService.ts b/src/services/ChatService.ts index da65641c..e9b1c284 100644 --- a/src/services/ChatService.ts +++ b/src/services/ChatService.ts @@ -3,7 +3,7 @@ import {CHAT_TOKEN_ENDPOINT} from '../constants/api'; export const loadChatTokenService = async () => { try { - const token = await AsyncStorage.getItem('chatToken'); + const token = await AsyncStorage.getItem('token'); const response = await fetch(CHAT_TOKEN_ENDPOINT, { method: 'GET', headers: { @@ -12,8 +12,8 @@ export const loadChatTokenService = async () => { }); const status = response.status; if (status === 200) { - const {chatToken} = await response.json(); - return chatToken; + const data = await response.json(); + return data.chatToken; } return ''; } catch (error) { diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 6b972b83..dc01d579 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -111,9 +111,10 @@ export const connectChatAccount = async ( export const getChatToken = async () => { try { - if (await AsyncStorage.getItem('chatToken')) { + const currentChatToken = await AsyncStorage.getItem('chatToken'); + if (currentChatToken === null) { const chatToken = await loadChatTokenService(); - AsyncStorage.setItem('chatToken', chatToken); + await AsyncStorage.setItem('chatToken', chatToken); } } catch (err) { console.log(err); -- cgit v1.2.3-70-g09d2 From fc569d73a1b776e9a662fc27e5e6c4e45d7f5d15 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 9 Apr 2021 18:34:07 -0400 Subject: resolved merge issues --- src/utils/messages.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/utils/messages.ts') diff --git a/src/utils/messages.ts b/src/utils/messages.ts index dc01d579..a0bbdb46 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import {loadChatTokenService} from '../services/ChatService'; import {RootState} from '../store/rootReducer'; import {ChannelGroupedType} from '../types'; +import {StreamChat} from 'stream-chat'; /** * Finds the difference in time in minutes @@ -86,7 +87,7 @@ export const getMember = ( export const connectChatAccount = async ( loggedInUserId: string, - chatClient, + chatClient: StreamChat, ) => { try { await getChatToken(); -- cgit v1.2.3-70-g09d2 From d595c4354b0a0a6892844457f3713538c75367b0 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 15:43:17 -0700 Subject: duplicate connect User calls --- src/utils/messages.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/utils/messages.ts') diff --git a/src/utils/messages.ts b/src/utils/messages.ts index a0bbdb46..49033226 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -92,7 +92,7 @@ export const connectChatAccount = async ( try { await getChatToken(); const chatToken = await AsyncStorage.getItem('chatToken'); - if (chatToken) { + if (!chatClient.user && chatToken) { await chatClient.connectUser( { id: loggedInUserId, @@ -100,6 +100,8 @@ export const connectChatAccount = async ( chatToken, ); return true; + } else if (chatClient.user) { + return true; } else { console.log('Unable to connect to stream. Empty chat token'); return false; -- cgit v1.2.3-70-g09d2 From 2a9b090ad62c2d157e06c978ba4cbc663f7c550f Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 9 Apr 2021 19:06:12 -0400 Subject: moved createChannel to messages util --- src/utils/common.ts | 18 ------------------ src/utils/messages.ts | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src/utils/messages.ts') diff --git a/src/utils/common.ts b/src/utils/common.ts index 0900a084..7ae36dc6 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -173,21 +173,3 @@ const _crestIcon = (university: UniversityType) => { return require('../assets/images/bwbadges.png'); } }; - -export const createChannel = async ( - loggedInUser: string, - id: string, - chatClient: any, -) => { - console.log(loggedInUser, id, chatClient); - try { - const channel = chatClient.channel('messaging', { - members: [loggedInUser, id], - }); - await channel.watch(); - return channel; - } catch (error) { - console.log(error); - throw error; - } -}; diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 49033226..dd29f317 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -123,3 +123,20 @@ export const getChatToken = async () => { console.log(err); } }; + +export const createChannel = async ( + loggedInUser: string, + id: string, + chatClient: any, +) => { + try { + const channel = chatClient.channel('messaging', { + members: [loggedInUser, id], + }); + await channel.watch(); + return channel; + } catch (error) { + console.log(error); + throw error; + } +}; -- cgit v1.2.3-70-g09d2