aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/screens/chat/ChatListScreen.tsx21
-rw-r--r--src/store/actions/user.ts2
2 files changed, 13 insertions, 10 deletions
diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx
index 8fa6998c..0d180b98 100644
--- a/src/screens/chat/ChatListScreen.tsx
+++ b/src/screens/chat/ChatListScreen.tsx
@@ -1,10 +1,13 @@
+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 {ChannelList, Chat} from 'stream-chat-react-native';
import {ChatContext} from '../../App';
import {MessagesHeader} from '../../components/messages';
import {MainStackParams} from '../../routes';
+import {RootState} from '../../store/rootReducer';
type ChatListScreenNavigationProp = StackNavigationProp<
MainStackParams,
@@ -19,11 +22,13 @@ interface ChatListScreenProps {
const ChatListScreen: React.FC<ChatListScreenProps> = ({navigation}) => {
const {chatClient, setChannel} = useContext(ChatContext);
const [clientReady, setClientReady] = useState(false);
+ const state: RootState = useStore().getState();
+ const loggedInUserId = state.user.user.userId;
// TODO: (CHAT) change this filter to filter for user-ids, or usernames?!
const memoizedFilters = useMemo(
() => ({
- members: {$in: ['john']},
+ members: {$in: [loggedInUserId]},
type: 'messaging',
}),
[],
@@ -31,14 +36,12 @@ const ChatListScreen: React.FC<ChatListScreenProps> = ({navigation}) => {
useEffect(() => {
const setupClient = async () => {
- // TODO: (CHAT) change me
+ const chatToken = await AsyncStorage.getItem('chatToken');
await chatClient.connectUser(
{
- id: 'john',
- name: 'John Doe',
- image: 'https://getstream.io/random_svg/?name=John',
+ id: loggedInUserId,
},
- chatClient.devToken('john'),
+ chatToken,
);
return setClientReady(true);
};
@@ -55,9 +58,9 @@ const ChatListScreen: React.FC<ChatListScreenProps> = ({navigation}) => {
<MessagesHeader
createChannel={() => {
// TODO: (CHAT) change me
- const channel = chatClient.channel('messaging', 'travel2', {
- name: 'Awesome channel about traveling',
- members: ['john'],
+ const channel = chatClient.channel('messaging', 'test1', {
+ name: 'Awesome channel about test1',
+ members: [loggedInUserId],
});
channel.create();
}}
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts
index 4faa2206..3ebd4190 100644
--- a/src/store/actions/user.ts
+++ b/src/store/actions/user.ts
@@ -173,7 +173,7 @@ export const logout = (
try {
// do our best effort here to gracefully disconnect the user
if (client) {
- await client.disconnectUser();
+ client.disconnectUser();
}
await AsyncStorage.clear();
dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}});