aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-18 19:48:53 -0400
committerGitHub <noreply@github.com>2021-03-18 19:48:53 -0400
commitaa0ddb7c5a6612ff067f7dce1c6d5b083db44309 (patch)
tree89326275ce5ff4e48bc29952c60856258cd8b0ab /src/utils
parent07a15098625786451270e30e61e2d6e78c02d4db (diff)
parent9a7e34bf992e0bfa3b9ce7d83643d97fad209e6e (diff)
Merge pull request #303 from shravyaramesh/add-friends-thru-contacts
[TMA-622] Add friends from contacts
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/common.ts19
-rw-r--r--src/utils/friends.ts2
-rw-r--r--src/utils/users.ts2
3 files changed, 20 insertions, 3 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts
index c1049c42..0a76ec08 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,8 +1,9 @@
-import {NotificationType} from './../types/types';
+import {ContactType, NotificationType} from './../types/types';
import moment from 'moment';
import {Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
import AsyncStorage from '@react-native-community/async-storage';
+import {getAll} from 'react-native-contacts';
export const getToggleButtonText: (
buttonType: string,
@@ -115,3 +116,19 @@ export const shuffle = (array: any[]) => {
return array;
};
+
+export const extractContacts = async () => {
+ let retrievedContacts: Array<ContactType> = [];
+ await getAll().then((contacts) => {
+ contacts.map((contact) => {
+ contact.phoneNumbers.map((phoneNumber) => {
+ retrievedContacts.push({
+ first_name: contact.givenName,
+ last_name: contact.familyName,
+ phone_number: phoneNumber.number,
+ });
+ });
+ });
+ });
+ return retrievedContacts;
+};
diff --git a/src/utils/friends.ts b/src/utils/friends.ts
index 3398c123..55d65170 100644
--- a/src/utils/friends.ts
+++ b/src/utils/friends.ts
@@ -60,7 +60,7 @@ export const handleAddFriend = async (
dispatch: AppDispatch,
state: RootState,
) => {
- const success = await dispatch(addFriend(friend, screenType));
+ const success = await dispatch(addFriend(friend, screenType, state));
await dispatch(updateUserXFriends(friend.id, state));
await dispatch(updateUserXProfileAllScreens(friend.id, state));
return success;
diff --git a/src/utils/users.ts b/src/utils/users.ts
index af4f3813..82bcb309 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -96,7 +96,7 @@ export const userXInStore = (
userId: string,
) => {
const userX = state.userX[screen];
- return userId in userX && userX[userId].user.userId;
+ return userX && userId in userX && userX[userId].user.userId;
};
/**