diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-02-28 17:32:03 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-02-28 17:32:03 +0100 |
commit | 894ec80949ffe5845f72f3cb9a69f125fb02513f (patch) | |
tree | 62b7ea6562f72eae4dc9d7765c887e449aaa3169 /src | |
parent | e32b0ab41eb548602abffa4040198c932abafe77 (diff) |
Fix first contact sync
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/ContactDetails.vue | 21 | ||||
-rw-r--r-- | src/store/contacts.js | 38 |
2 files changed, 34 insertions, 25 deletions
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) } |