diff options
Diffstat (limited to 'src/components/profile/ProfilePreview.tsx')
-rw-r--r-- | src/components/profile/ProfilePreview.tsx | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index 9c953e7d..abc29422 100644 --- a/src/components/profile/ProfilePreview.tsx +++ b/src/components/profile/ProfilePreview.tsx @@ -7,12 +7,15 @@ import { StyleSheet, ViewProps, TouchableOpacity, + Alert, } from 'react-native'; import {useNavigation} from '@react-navigation/native'; import RNFetchBlob from 'rn-fetch-blob'; import AsyncStorage from '@react-native-community/async-storage'; import {AVATAR_PHOTO_ENDPOINT} from '../../constants'; import {UserType} from '../../types'; +import {AuthContext} from '../../routes/'; +import {isUserBlocked} from '../../services'; const NO_USER: UserType = { userId: '', username: '', @@ -38,6 +41,7 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ style, }) => { const navigation = useNavigation(); + const {user: loggedInUser, logout} = React.useContext(AuthContext); const [avatarURI, setAvatarURI] = useState<string | null>(null); const [user, setUser] = useState<UserType>(NO_USER); useEffect(() => { @@ -80,6 +84,16 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ * Cache maintains 10 recently searched users, popping off the oldest one if * needed to make space. */ + + const checkIfUserIsBlocked = async (userId: string) => { + const token = await AsyncStorage.getItem('token'); + if (!token) { + logout(); + return false; + } + return await isUserBlocked(userId, loggedInUser.userId, token); + }; + const addToRecentlyStoredAndNavigateToProfile = async () => { let user: ProfilePreviewType = { id, @@ -87,7 +101,14 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ first_name, last_name, }; + try { + //If the logged in user is blocked by the user being viewed, do not proceed. + const isUserBlocked = await checkIfUserIsBlocked(user.id); + if (isUserBlocked) { + Alert.alert('You cannot view this profile'); + return; + } if (!isComment) { const jsonValue = await AsyncStorage.getItem( '@recently_searched_users', |