From 894ec80949ffe5845f72f3cb9a69f125fb02513f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 28 Feb 2020 17:32:03 +0100 Subject: Fix first contact sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/components/ContactDetails.vue | 21 ++++++++++++++++----- src/store/contacts.js | 38 ++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 5ce82a86..e1a433c2 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 3cb1ec7a..f2602f36 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) } -- cgit v1.2.3