summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-09-25 12:40:22 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-09-25 14:53:28 +0200
commit7349a6fc5bf22d50ac1550f73c12ebdb7536c16f (patch)
treeb90f11c5d596e709cf17119974ce23a2352f9a4d /src
parent040992884b416d5c86e3a06731f26a5b1c68d7a8 (diff)
Contact deletion fix and warning if fetchFull fails and/of contact gone
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/components/ContactDetails.vue8
-rw-r--r--src/components/ContentList/ContentListItem.vue2
-rw-r--r--src/models/contact.js10
-rw-r--r--src/store/addressbooks.js6
-rw-r--r--src/store/contacts.js11
5 files changed, 25 insertions, 12 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue
index a0650380..f72af6ff 100644
--- a/src/components/ContactDetails.vue
+++ b/src/components/ContactDetails.vue
@@ -347,6 +347,12 @@ export default {
this.localContact = localContact
this.loadingData = false
})
+ .catch((error) => {
+ OC.Notification.showTemporary(t('contacts', 'The contact doesn\'t exists anymore on the server.'))
+ console.error(error)
+ // trigger a local deletion from the store only
+ this.$store.dispatch('deleteContact', { contact: this.contact, dav: false })
+ })
} else if (contact) {
// create empty contact and copy inner data
// wait for an update to really push the contact on the server!
@@ -362,7 +368,7 @@ export default {
* Dispatch contact deletion request
*/
deleteContact() {
- this.$store.dispatch('deleteContact', this.contact)
+ this.$store.dispatch('deleteContact', { contact: this.contact })
},
/**
diff --git a/src/components/ContentList/ContentListItem.vue b/src/components/ContentList/ContentListItem.vue
index a271e112..3e80d3f3 100644
--- a/src/components/ContentList/ContentListItem.vue
+++ b/src/components/ContentList/ContentListItem.vue
@@ -64,7 +64,7 @@ export default {
* Dispatch contact deletion request
*/
deleteContact() {
- this.$store.dispatch('deleteContact', this.contact)
+ this.$store.dispatch('deleteContact', { contact: this.contact })
},
/**
diff --git a/src/models/contact.js b/src/models/contact.js
index de1ba9a7..3836d91d 100644
--- a/src/models/contact.js
+++ b/src/models/contact.js
@@ -30,11 +30,15 @@ export default class Contact {
*
* @param {string} vcard the vcard data as string with proper new lines
* @param {object} addressbook the addressbook which the contat belongs to
- * @param {string} [url] the url of the contact
- * @param {string} [etag] the current etag of the contact
+ * @param {string} [url=''] the url of the contact
+ * @param {string} [etag=''] the current etag of the contact
* @memberof Contact
*/
- constructor(vcard = '', addressbook, url = '', etag = '') {
+ constructor(vcard, addressbook, url = '', etag = '') {
+ if (typeof vcard !== 'string' || vcard.length === 0) {
+ throw new Error('Invalid vCard')
+ }
+
let jCal = ICAL.parse(vcard)
if (jCal[0] !== 'vcard') {
throw new Error('Only one contact is allowed in the vcard data')
diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js
index b0fb217a..74a47bef 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -386,9 +386,9 @@ const actions = {
OC.Notification.showTemporary(t('contacts', 'An error occurred'))
})
}
- context.commit('deleteContactFromAddressbook', contact)
- context.commit('updateContactAddressbook', { contact, addressbook })
- context.commit('addContactToAddressbook', contact)
+ await context.commit('deleteContactFromAddressbook', contact)
+ await context.commit('updateContactAddressbook', { contact, addressbook })
+ await context.commit('addContactToAddressbook', contact)
}
}
diff --git a/src/store/contacts.js b/src/store/contacts.js
index f8c152f5..aa0805f0 100644
--- a/src/store/contacts.js
+++ b/src/store/contacts.js
@@ -206,11 +206,13 @@ const actions = {
* Delete a contact from the list and from the associated addressbook
*
* @param {Object} context the store mutations
- * @param {Contact} contact the contact to delete
+ * @param {Object} data destructuring object
+ * @param {Contact} data.contact the contact to delete
+ * @param {Boolean} [data.dav=true] trigger a dav deletion
*/
- async deleteContact(context, contact) {
+ async deleteContact(context, { contact, dav = true }) {
// only local delete if the contact doesn't exists on the server
- if (contact.dav) {
+ if (contact.dav && dav) {
await contact.dav.delete()
.catch((error) => {
console.error(error)
@@ -247,7 +249,7 @@ const actions = {
// create contact
await contact.addressbook.dav.createVCard(vData)
.then((response) => {
- contact.dav = response
+ Vue.set(contact, 'dav', response)
})
.catch((error) => { throw error })
}
@@ -271,6 +273,7 @@ const actions = {
let newContact = new Contact(contact.dav.data, contact.addressbook, contact.dav.url, contact.dav.etag)
context.commit('updateContact', newContact)
})
+ .catch((error) => { throw error })
}
}