Skip to content

Commit

Permalink
Add REV on update
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Mar 4, 2019
1 parent bdd9383 commit 60f306c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/mixins/PropertyMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/
import debounce from 'debounce'
import Contact from 'Models/contact'

export default {
props: {
Expand Down Expand Up @@ -66,6 +67,10 @@ export default {
options: {
type: Array,
default: () => []
},
contact: {
type: Contact,
default: null
}
},

Expand All @@ -88,13 +93,22 @@ export default {
action: this.deleteProperty
}
return [...this.propModel.actions ? this.propModel.actions : [], del]
},
rev() {
return this.contact && this.contact.rev
? this.contact.rev.toUnixTime()
: 0
}
},

watch: {
/**
* Since we're updating a local data based on the value prop,
* we need to make sure to update the local data on pop change
* we need to make sure to update the local data on contact change
* in case the v-Node is reused
*
* Unfortunately we do not want to update when the main
* vuex contact is updated.
*/
value: function() {
this.localValue = this.value
Expand Down
28 changes: 28 additions & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export default class Contact {
console.info('This contact did not have a proper uid. Setting a new one for ', this)
this.vCard.addPropertyWithValue('uid', uuid())
}

// if no rev set, init one
if (!this.vCard.hasProperty('rev')) {
const rev = new ICAL.VCardTime()
rev.fromUnixTime(Date.now() / 1000)
this.rev = rev
}
}

/**
Expand Down Expand Up @@ -137,6 +144,27 @@ export default class Contact {
return true
}

/**
* Return the rev
*
* @readonly
* @memberof Contact
*/
get rev() {
return this.vCard.getFirstPropertyValue('rev')
}

/**
* Set the rev
*
* @param {string} rev the rev to set
* @memberof Contact
*/
set rev(rev) {
this.vCard.updatePropertyWithValue('rev', rev)
return true
}

/**
* Return the key
*
Expand Down
5 changes: 5 additions & 0 deletions src/store/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ const actions = {
// Checking contact validity 🙈
validate(contact)

// Update REV
const rev = new ICAL.VCardTime()
rev.fromUnixTime(Date.now() / 1000)
contact.rev = rev

let vData = ICAL.stringify(contact.vCard.jCal)

// if no dav key, contact does not exists on server
Expand Down
15 changes: 13 additions & 2 deletions src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,21 @@ export default {

methods: {
async newContact() {
let contact = new Contact(`BEGIN:VCARD\nVERSION:4.0\nPRODID:-//Nextcloud Contacts v${oca_contacts.versionstring}\nEND:VCARD`, this.defaultAddressbook)
const properties = rfcProps.properties(this)
const rev = new ICAL.VCardTime()
const contact = new Contact(`
BEGIN:VCARD
VERSION:4.0
PRODID:-//Nextcloud Contacts v${oca_contacts.versionstring}
END:VCARD
`.trim().replace(/\t/gm, ''),
this.defaultAddressbook)

contact.fullName = t('contacts', 'New contact')
rev.fromUnixTime(Date.now() / 1000)
contact.rev = rev

// itterate over all properties (filter is not usable on objects and we need the key of the property)
const properties = rfcProps.properties(this)
for (let name in properties) {
if (properties[name].default) {
let defaultData = properties[name].defaultValue
Expand Down

0 comments on commit 60f306c

Please sign in to comment.