diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-08-30 08:44:22 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-08-30 08:44:22 +0200 |
commit | 1f66b85acf8e09f08b466b177ced0c0f20a7fc2b (patch) | |
tree | 1d9234fd382cc775ee4c6831d974574d7b900184 /src/models | |
parent | 4d1a67a018188e997e74f835fd849c70b207abe3 (diff) |
Support vcard 3 photo syntax
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/contact.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/models/contact.js b/src/models/contact.js index c4eebecc..15f0d7e2 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -165,6 +165,27 @@ export default class Contact { } /** + * Return the version + * + * @readonly + * @memberof Contact + */ + get version() { + return this.vCard.getFirstPropertyValue('version') + } + + /** + * Set the version + * + * @param {string} version the version to set + * @memberof Contact + */ + set version(version) { + this.vCard.updatePropertyWithValue('version', version) + return true + } + + /** * Return the uid * * @readonly @@ -238,6 +259,34 @@ export default class Contact { } /** + * Return the photo usable url + * + * @readonly + * @memberof Contact + */ + get photoUrl() { + const photo = this.vCard.getFirstProperty('photo') + const encoding = photo.getFirstParameter('encoding') + + const isBinary = photo.type === 'binary' || encoding === 'b' + + if (photo && !this.photo.startsWith('data') && isBinary) { + // split on coma in case of any leftover base64 data and retrieve last part + // usually we come to this part when the base64 image type is unknown + return `data:image;base64,${this.photo.split(',').pop()}` + } + // could be just an url of the already encoded `data:image...` + try { + // eslint-disable-next-line no-new + new URL(this.photo) + return this.photo + } catch { + console.error('Invalid photo for the following contact. Ignoring...', this.contact) + return false + } + } + + /** * Return the groups * * @readonly |