diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 5ce82a865..e1a433c21 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -432,6 +432,15 @@ export default { this.loadingUpdate = true await this.$store.dispatch('updateContact', this.localContact) this.loadingUpdate = false + + // if we just created the contact, we need to force update the + // localContact to match the proper store contact + if (!this.localContact.dav) { + console.debug('New contact synced!', this.localContact) + // fetching newly created & storred contact + const contact = this.$store.getters.getContact(this.localContact.key) + await this.updateLocalContact(contact) + } }, /** @@ -481,8 +490,9 @@ export default { * @param {string} key the contact key */ async selectContact(key) { - // local version of the contact this.loadingData = true + + // local version of the contact const contact = this.$store.getters.getContact(key) if (contact) { @@ -491,7 +501,7 @@ export default { try { await this.$store.dispatch('fetchFullContact', { contact }) // clone to a local editable variable - this.updateLocalContact(contact) + await this.updateLocalContact(contact) } catch (error) { if (error.name === 'ParserError') { OC.Notification.showTemporary(t('contacts', 'Syntax error. Cannot open the contact.')) @@ -506,9 +516,11 @@ export default { } } else { // clone to a local editable variable - this.updateLocalContact(contact) + await this.updateLocalContact(contact) } } + + this.loadingData = false }, /** @@ -570,7 +582,7 @@ export default { * * @param {Contact} contact the contact to clone */ - updateLocalContact(contact) { + async updateLocalContact(contact) { // create empty contact and copy inner data const localContact = Object.assign( Object.create(Object.getPrototypeOf(contact)), @@ -580,7 +592,6 @@ export default { this.fixed = validate(localContact) this.localContact = localContact - this.loadingData = false }, onCtrlSave(e) { diff --git a/src/store/contacts.js b/src/store/contacts.js index 3cb1ec7ac..f2602f36f 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -335,31 +335,29 @@ const actions = { // if no dav key, contact does not exists on server if (!contact.dav) { // create contact - return contact.addressbook.dav.createVCard(vData) - .then(dav => { - context.commit('setContactDav', { contact, dav }) - }) - .catch(error => { throw error }) + const dav = await contact.addressbook.dav.createVCard(vData) + context.commit('setContactDav', { contact, dav }) + return } // if contact already exists if (!contact.conflict) { contact.dav.data = vData - return contact.dav.update() - .then(() => { - // all clear, let's update the store - context.commit('updateContact', contact) - }) - .catch(error => { - console.info(error) - // wrong etag, we most likely have a conflict - if (error && error.status === 412) { - // saving the new etag so that the user can manually - // trigger a fetchCompleteData without any further errors - context.commit('setContactAsConflict', { contact, etag: error.xhr.getResponseHeader('etag') }) - console.error('This contact is outdated, the server refused it', contact) - } - }) + try { + await contact.dav.update() + // all clear, let's update the store + context.commit('updateContact', contact) + } catch (error) { + console.error(error) + + // wrong etag, we most likely have a conflict + if (error && error.status === 412) { + // saving the new etag so that the user can manually + // trigger a fetchCompleteData without any further errors + context.commit('setContactAsConflict', { contact, etag: error.xhr.getResponseHeader('etag') }) + console.error('This contact is outdated, the server refused it', contact) + } + } } else { console.error('This contact is outdated, refusing to push', contact) }