From 4378df9cc0343e9869a74f6db2eaea67d103bfdf Mon Sep 17 00:00:00 2001
From: Shravya Ramesh <shravs1208@gmail.com>
Date: Thu, 8 Apr 2021 13:18:56 -0700
Subject: To test nav [wip after merging utils for chat]

---
 src/components/profile/ProfileBody.tsx | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

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

diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx
index 9b19b866..1a8d1e1a 100644
--- a/src/components/profile/ProfileBody.tsx
+++ b/src/components/profile/ProfileBody.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useContext} from 'react';
 import {LayoutChangeEvent, Linking, StyleSheet, Text, View} from 'react-native';
 import {normalize} from 'react-native-elements';
 import {useDispatch, useSelector, useStore} from 'react-redux';
@@ -20,6 +20,9 @@ import {
 } from '../../utils';
 import {FriendsButton, BasicButton} from '../common';
 import ToggleButton from './ToggleButton';
+// import {ChatContext} from '../../App';
+// import {useNavigation} from '@react-navigation/core';
+// import AsyncStorage from '@react-native-community/async-storage';
 
 interface ProfileBodyProps {
   onLayout: (event: LayoutChangeEvent) => void;
@@ -53,6 +56,9 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({
 
   const state: RootState = useStore().getState();
   const dispatch = useDispatch();
+  // const navigation = useNavigation();
+  // const {chatClient, setChannel} = useContext(ChatContext);
+  const loggedInUserId = state.user.user.userId;
 
   const handleAcceptRequest = async () => {
     await dispatch(acceptFriendRequest({id, username, first_name, last_name}));
@@ -69,7 +75,10 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({
     if (
       userXId &&
       !isBlocked &&
-      (friendship_status === 'no_record' || friendship_status === 'friends') &&
+      (friendship_status === 'no_record' ||
+        friendship_status === 'friends' ||
+        (friendship_status === 'requested' &&
+          friendship_requester_id === loggedInUserId)) &&
       canViewProfile(state, userXId, screenType)
     ) {
       return true;
@@ -78,9 +87,23 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({
     }
   };
 
-  const onPressMessage = () => {
-    // TODO: Add navigation to ChatScreen
-    console.log('Navigate to the individual chat screen');
+  const onPressMessage = async () => {
+    // TODO: Use function from util to create the channel and then navigate to screen
+    // const channelName = username + ' and ' + state.user.user.username;
+    // const chatToken = await AsyncStorage.getItem('chatToken');
+    // await chatClient.connectUser(
+    //   {
+    //     id: loggedInUserId,
+    //   },
+    //   chatToken,
+    // );
+    // const channel = chatClient.channel('messaging', {
+    //   name: channelName,
+    //   members: [loggedInUserId, String(userXId)],
+    // });
+    // channel.create();
+    // navigation.navigate('Chat');
+    console.log('Navigate to ChatScreen');
   };
 
   return (
-- 
cgit v1.2.3-70-g09d2

