aboutsummaryrefslogtreecommitdiff
path: root/src/utils/users.ts
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2021-01-16 10:43:03 -0800
committerGitHub <noreply@github.com>2021-01-16 10:43:03 -0800
commitae9cbb026f6128e732d36138751e319c926c72b1 (patch)
tree4946280bb00f8081370c3602a404c041a7cc28d5 /src/utils/users.ts
parent30391867438bb28cbcba9fc9ee2ff6d00027fd86 (diff)
parent23ccc2d6441aca0c89d0ba30e9d990b4aedb73cb (diff)
Merge pull request #187 from shravyaramesh/tma538-friend-requests
[TMA485] friend request frontend
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r--src/utils/users.ts41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts
index c54ea715..ca917ae4 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -1,6 +1,6 @@
import AsyncStorage from '@react-native-community/async-storage';
import {INTEGRATED_SOCIAL_LIST} from '../constants';
-import {loadSocialPosts} from '../services';
+import {isUserBlocked, loadSocialPosts} from '../services';
import {
loadAllSocials,
loadBlockedList,
@@ -9,6 +9,7 @@ import {
loadUserData,
loadUserMoments,
loadUserNotifications,
+ logout,
} from '../store/actions';
import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates';
import {userLoggedIn} from '../store/reducers';
@@ -16,7 +17,12 @@ import {loadUserMomentCategories} from './../store/actions/momentCategories';
import {loadUserX} from './../store/actions/userX';
import {AppDispatch} from './../store/configureStore';
import {RootState} from './../store/rootReducer';
-import {ScreenType, UserType} from './../types/types';
+import {
+ ProfilePreviewType,
+ ProfileType,
+ ScreenType,
+ UserType,
+} from './../types/types';
const loadData = async (dispatch: AppDispatch, user: UserType) => {
await Promise.all([
@@ -122,3 +128,34 @@ export const getTokenOrLogout = async (dispatch: Function): Promise<string> => {
}
return token;
};
+
+/**
+ * Creates ProfilePreviewType of a user using UserType && ProfileType
+ * @param passedInUser This is the UserType of the user
+ * @param passedInProfile This is the ProfileType of the user
+ */
+export const getUserAsProfilePreviewType = (
+ passedInUser: UserType,
+ passedInProfile: ProfileType,
+): ProfilePreviewType => {
+ const fullName = passedInProfile.name.split(' ');
+ return {
+ id: passedInUser.userId,
+ username: passedInUser.username,
+ first_name: fullName[0],
+ last_name: fullName[1],
+ };
+};
+
+export const checkIfUserIsBlocked = async (
+ userId: string,
+ dispatch: Function,
+ loggedInUser: UserType,
+) => {
+ const token = await AsyncStorage.getItem('token');
+ if (!token) {
+ dispatch(logout());
+ return false;
+ }
+ return await isUserBlocked(userId, loggedInUser.userId, token);
+};