aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/screens/profile/SettingsScreen.tsx6
-rw-r--r--src/store/actions/user.ts16
2 files changed, 14 insertions, 8 deletions
diff --git a/src/screens/profile/SettingsScreen.tsx b/src/screens/profile/SettingsScreen.tsx
index 05e051b5..ecc3bafd 100644
--- a/src/screens/profile/SettingsScreen.tsx
+++ b/src/screens/profile/SettingsScreen.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useContext} from 'react';
import {
SafeAreaView,
SectionList,
@@ -17,6 +17,7 @@ import {BackgroundGradientType} from '../../types';
import {normalize, SCREEN_HEIGHT} from '../../utils/layouts';
import SettingsCell from './SettingsCell';
import {useNavigation} from '@react-navigation/core';
+import {ChatContext} from '../../App';
const SettingsScreen: React.FC = () => {
const dispatch = useDispatch();
@@ -24,6 +25,7 @@ const SettingsScreen: React.FC = () => {
const {suggested_people_linked} = useSelector(
(state: RootState) => state.user.profile,
);
+ const {chatClient} = useContext(ChatContext);
return (
<>
@@ -49,7 +51,7 @@ const SettingsScreen: React.FC = () => {
<TouchableOpacity
style={styles.logoutContainerStyles}
onPress={() => {
- dispatch(logout());
+ dispatch(logout(chatClient));
navigation.reset({
index: 0,
routes: [{name: 'SuggestedPeople'}],
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts
index e7d985ac..4faa2206 100644
--- a/src/store/actions/user.ts
+++ b/src/store/actions/user.ts
@@ -1,4 +1,5 @@
import AsyncStorage from '@react-native-community/async-storage';
+import {StreamChat} from 'stream-chat';
import {Action, ThunkAction} from '@reduxjs/toolkit';
import {
getProfilePic,
@@ -164,13 +165,16 @@ export const updateReplyPosted = (
}
};
-export const logout = (): ThunkAction<
- Promise<void>,
- RootState,
- unknown,
- Action<string>
-> => async (dispatch) => {
+export const logout = (
+ client?: StreamChat,
+): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
+ dispatch,
+) => {
try {
+ // do our best effort here to gracefully disconnect the user
+ if (client) {
+ await client.disconnectUser();
+ }
await AsyncStorage.clear();
dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}});
} catch (error) {