diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-29 18:17:46 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-29 18:17:46 -0400 |
commit | d5669f3d08bee68b37f51727e499e84610685422 (patch) | |
tree | 8de9664c49e63833504aafd69ca8f965249d412d /src/utils/users.ts | |
parent | d1e5d18c36af46b450ec7d019550c05b1a78f2db (diff) | |
parent | b0e4fe55be8983079f499b923e953855afeb2c64 (diff) |
Merge branch 'master' into tma739-bugfix-profile-onboarding-tutorial
# Conflicts:
# src/components/profile/Content.tsx
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r-- | src/utils/users.ts | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts index d5e44b36..22c1c1f0 100644 --- a/src/utils/users.ts +++ b/src/utils/users.ts @@ -133,7 +133,7 @@ export const loadAllSocialsForUser = async (userId: string, token?: string) => { export const getTokenOrLogout = async (dispatch: Function): Promise<string> => { const token = await AsyncStorage.getItem('token'); if (!token) { - dispatch({type: userLoggedIn.type, payload: {userId: '', username: ''}}); + dispatch(logout()); return ''; } return token; @@ -174,3 +174,35 @@ export const defaultUserProfile = () => { const defaultImage = require('../assets/images/avatar-placeholder.png'); return defaultImage; }; + +/** + * Used to determine whether the logged-in user is able to view userX's private + * information or not. + * + * @param state redux store's root state + * @param userXId target userX's id + * @param screenType current screen type + * @returns true if abel to view private info, false otherwise + */ +export const canViewProfile = ( + state: RootState, + userXId: string | undefined, + screenType: ScreenType, +) => { + // own profile + if (!userXId || state.user.user.userId === userXId) { + return true; + } + // not private + if (!(userXId && state.userX[screenType][userXId].profile.is_private)) { + return true; + } + // is friend + if ( + userXId && + state.userX[screenType][userXId].profile.friendship_status === 'friends' + ) { + return true; + } + return false; +}; |