Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
return Contacts.getAll((error, result) => {
// The native code sometimes sends strings instead of errors:
if (error) return reject(typeof error === 'string' ? new Error(error) : error)
return resolve(result)
})
})
}
const ContactsContainer = createContainer((props) => {
//get all phone contacts, then generate to contacts collection
RNContacts.getAll((err, contacts) => {
if(err === 'denied'){
// x.x
} else {
let phoneNumbers = [];
contacts.forEach((contact)=>{
contact.phoneNumbers.forEach((phone)=>{
if(phone.number){
const formatedPhoneNumber = "+" + phone.number.replace(new RegExp(/[-\/\\^$*+?.()|[\]{}]/g, 'g'), '').replace(/\s/g,'');
phoneNumbers.push(formatedPhoneNumber);
}
});
});
phoneNumbers = [...new Set(phoneNumbers)];
Meteor.call('contacts.generate', phoneNumbers);
}
});
loadContacts() {
Contacts.getAll((err, contacts) => {
if (err === "denied") {
console.warn("Permission to access contacts was denied");
} else {
this.setState({ contacts });
}
});
}
deleteContact () {
Contacts.getAll((err, contacts) => {
let contactToDelete = _.find(
contacts,
(contact) => contact.givenName
&& contact.givenName.indexOf(PREFIX) === 0
)
if (!contactToDelete) {
contactToDelete = contacts[0]
}
console.log('attempting to delete', contactToDelete)
Contacts.deleteContact(contactToDelete, (err, data) => {
Contacts.getAll((err, newContactList) => {
console.log('resultant list', newContactList)
invariant(
newContactList.length === contacts.length -1,
'getAll should return one less result'
)
updateContact () {
Contacts.getAll((err, data) => {
console.log('data', data)
let originalRecord = _.cloneDeep(data[0])
let pendingRecord = _.cloneDeep(data[0])
if (originalRecord.familyName) {
pendingRecord.familyName = (
originalRecord.familyName
+ Math.floor(Math.random() * 999999)
).slice(0, 20)
} else {
pendingRecord.familyName = '' + Math.floor(Math.random() * 999)
}
pendingRecord.emailAddresses.push({
email: 'addedFromRNContacts@example.com',
type: 'work'
})
console.log('begin updateContact')
Contacts.deleteContact(contactToDelete, (err, data) => {
Contacts.getAll((err, newContactList) => {
console.log('resultant list', newContactList)
invariant(
newContactList.length === contacts.length -1,
'getAll should return one less result'
)
invariant(
!_.find(newContactList, {recordID: contactToDelete.recordID}),
'contact should not longer exist'
)
})
})
})
export function getAllContacts(cb) {
return Contacts.getAll((err, contacts) => {
if (err && err.type === 'permissionDenied') {
console.error('Nope!');
} else {
cb(contacts);
}
});
}
/** *****************************************************
return new Promise((resolve) => {
Contacts.getAll(async (error, contacts) => {
if (error === 'denied') {
resolve(contactList);
}
contacts.forEach(
(contact) => {
if (contact.phoneNumbers.length > 0) {
const contactName = `${contact.givenName ? contact.givenName : ''}${contact.familyName ? ` ${contact.familyName}` : ''}`;
contact.phoneNumbers.forEach(phoneBook =>
contactList.push({
name: contactName,
phoneNumber: phoneBook.number,
}),
);
}