diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-12 10:02:00 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-27 19:41:59 +0100 |
commit | f67a5cc9b3bea0a0308e0dec7f804ebb32485618 (patch) | |
tree | 09656a3ad6f39b71d387130066bacb9a463eb085 /src/models | |
parent | ae80cf1a5a8f3d72cba1a2d65a9c2468c94619b1 (diff) |
Add ABLABEL and ITEMX.property support
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/contact.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/models/contact.js b/src/models/contact.js index 2d383dd9..14ea06ff 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -35,6 +35,40 @@ const isEmpty = value => { return (Array.isArray(value) && value.join('') === '') || (!Array.isArray(value) && value === '') } +/** + * Parse a jCal and update the global designset + * if any grouped property is found + * + * @param {Array} jCal the contact ICAL.js jCal + * @returns {Boolean} + */ +const updateDesignSet = jCal => { + let result = false + jCal[1].forEach(prop => { + const propGroup = prop[0].split('.') + + // if this is a grouped property, update the designSet + if (propGroup.length === 2 && ( + ICAL.design.vcard.property[propGroup[1]] + || ICAL.design.vcard3.property[propGroup[1]] + )) { + // force update the main design sets + if (ICAL.design.vcard.property[propGroup[1]]) { + ICAL.design.vcard.property[prop[0]] + = ICAL.design.vcard.property[propGroup[1]] + result = true + } + if (ICAL.design.vcard3.property[propGroup[1]]) { + ICAL.design.vcard3.property[prop[0]] + = ICAL.design.vcard3.property[propGroup[1]] + + result = true + } + } + }) + return result +} + export default class Contact { /** @@ -54,6 +88,12 @@ export default class Contact { throw new Error('Only one contact is allowed in the vcard data') } + // add grouped properties to the design set + // if any found, refresh the contact jCal + if (updateDesignSet(jCal)) { + jCal = ICAL.parse(vcard) + } + this.jCal = jCal this.addressbook = addressbook this.vCard = new ICAL.Component(this.jCal) |