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

Fixing issue 1044 by letting the 'localContact' update #1049

Closed
wants to merge 2 commits into from
Closed
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
41 changes: 17 additions & 24 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export default {
this.fixed = false
this.loadingUpdate = true
await this.$store.dispatch('updateContact', this.localContact)
this.updateLocalContact()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this will erase any changes made during the firing of updateContact and the updateLocalContact. On small connexion this could cause some data loss. Like you're writing a note, and the update gets fired, but you keep writing. When the updateLocalContact is reached, everything you kept writing will go back to the original state of the contact (not local) 🤔

I need to check if my theory is good :)

this.loadingUpdate = false
},

Expand Down Expand Up @@ -444,24 +445,13 @@ export default {
async selectContact(key) {
// local version of the contact
this.loadingData = true
let contact = this.$store.getters.getContact(key)

let contact = this.contact
if (contact) {
// if contact exists AND if exists on server
if (contact.dav) {
try {
await this.$store.dispatch('fetchFullContact', { contact })

// create empty contact and copy inner data
let localContact = Object.assign(
Object.create(Object.getPrototypeOf(contact)),
contact
)

this.fixed = validate(localContact)

this.localContact = localContact
this.loadingData = false
this.updateLocalContact()
} catch (error) {
if (error.name === 'ParserError') {
OC.Notification.showTemporary(t('contacts', 'Syntax error. Cannot open the contact.'))
Expand All @@ -475,21 +465,24 @@ export default {
this.$store.dispatch('deleteContact', { contact: this.contact, dav: false })
}
} else {
// create empty contact and copy inner data
// wait for an update to really push the contact on the server!
let localContact = Object.assign(
Object.create(Object.getPrototypeOf(contact)),
contact
)

this.fixed = validate(localContact)

this.localContact = localContact
this.loadingData = false
this.updateLocalContact()
}
}
},

/**
* Update this.localContact and set this.fixed
*/
updateLocalContact() {
// create empty contact and copy inner data
this.localContact = Object.assign(
Object.create(Object.getPrototypeOf(this.contact)),
this.contact
)
this.fixed = validate(this.localContact)
this.loadingData = false
},

/**
* Dispatch contact deletion request
*/
Expand Down