Add promise queue to avoid race condition

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2017-10-25 09:22:45 +02:00
parent 83850fa3de
commit cada30d84b
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
2 changed files with 10 additions and 3 deletions

View File

@ -76,7 +76,7 @@ angular.module('contactsApp')
};
ctrl.updateContact = function() {
ContactService.update(ctrl.contact);
ContactService.AddAndUpdate(ctrl.contact);
};
ctrl.deleteContact = function() {

View File

@ -8,6 +8,13 @@ angular.module('contactsApp')
var observerCallbacks = [];
var loadPromise = undefined;
var allUpdates = $q.when();
this.AddAndUpdate = function(contact) {
allUpdates = allUpdates.then(function() {
return contactService.update(contact);
});
};
this.registerObserverCallback = function(callback) {
observerCallbacks.push(callback);
};
@ -180,7 +187,7 @@ angular.module('contactsApp')
this.create = function(newContact, addressBook, uid, fromImport) {
addressBook = addressBook || AddressBookService.getDefaultAddressBook();
if(addressBook.readOnly) {
OC.Notification.showTemporary(t('contacts', 'You have no permission to make changes to this address book.'));
OC.Notification.showTemporary(t('contacts', 'You don\'t have permission to write to this addressbook.'));
return;
}
try {
@ -272,7 +279,7 @@ angular.module('contactsApp')
return;
}
if(addressBook.readOnly) {
OC.Notification.showTemporary(t('contacts', 'You have no permission to make changes to this address book.'));
OC.Notification.showTemporary(t('contacts', 'You don\'t have permission to write to this addressbook.'));
return;
}
contact.syncVCard();