mirror of https://github.com/nextcloud/contacts
Enabling function
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
parent
162f4a9984
commit
9574097117
|
@ -108,6 +108,16 @@ angular.module('contactsApp')
|
|||
});
|
||||
});
|
||||
break;
|
||||
case 'enable':
|
||||
ctrl.loading = true;
|
||||
ContactService.appendContactsFromAddressbook(ev.addressBook, function() {
|
||||
ContactService.getAll().then(function(contacts) {
|
||||
ctrl.contactList = contacts;
|
||||
ctrl.loading = false;
|
||||
ctrl.selectNearestContact(ctrl.getSelectedId());
|
||||
});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// unknown event -> leave callback without action
|
||||
return;
|
||||
|
|
|
@ -82,15 +82,7 @@ angular.module('contactsApp')
|
|||
if(addressBook.enabled) {
|
||||
promises.push(
|
||||
AddressBookService.sync(addressBook).then(function(addressBook) {
|
||||
addressBook.objects.forEach(function(vcard) {
|
||||
try {
|
||||
var contact = new Contact(addressBook, vcard);
|
||||
contactsCache.put(contact.uid(), contact);
|
||||
} catch(error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Invalid contact received: ', vcard);
|
||||
}
|
||||
});
|
||||
contactService.appendContactsFromAddressbook(addressBook);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -343,4 +335,19 @@ angular.module('contactsApp')
|
|||
notifyObservers('groupsUpdate');
|
||||
};
|
||||
|
||||
this.appendContactsFromAddressbook = function(addressBook, callback) {
|
||||
addressBook.objects.forEach(function(vcard) {
|
||||
try {
|
||||
var contact = new Contact(addressBook, vcard);
|
||||
contactsCache.put(contact.uid(), contact);
|
||||
} catch(error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Invalid contact received: ', vcard);
|
||||
}
|
||||
});
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue