Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix first contact sync #1488

Merged
merged 1 commit into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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.'))
Expand All @@ -506,9 +516,11 @@ export default {
}
} else {
// clone to a local editable variable
this.updateLocalContact(contact)
await this.updateLocalContact(contact)
}
}

this.loadingData = false
},

/**
Expand Down Expand Up @@ -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)),
Expand All @@ -580,7 +592,6 @@ export default {
this.fixed = validate(localContact)

this.localContact = localContact
this.loadingData = false
},

onCtrlSave(e) {
Expand Down
38 changes: 18 additions & 20 deletions src/store/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down