diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-01-25 11:33:44 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-01-25 11:35:28 +0100 |
commit | 1f864843455282d4e4a02a46ad1560ed7abe27cf (patch) | |
tree | 44592ae63ef88482c284e4d2a8731b315bf6ced8 /src/models | |
parent | d982fcf753353236cbaa65a8715cbb4097d2e49f (diff) |
Fix displayName checks and replace FN if empty on validate
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/contact.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/models/contact.js b/src/models/contact.js index 1240d3d2..f12cef50 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -285,7 +285,10 @@ export default class Contact { const org = this.vCard.getFirstPropertyValue('org') // if ordered by last or first name we need the N property - if (orderKey && n) { + // ! by checking the property we check for null AND empty string + // ! that means we can then check for empty array and be safe not to have + // ! 'xxxx'.join('') !== '' + if (orderKey && n && n.join('') !== '') { switch (orderKey) { case 'firstName': // Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P. @@ -299,20 +302,19 @@ export default class Contact { } } // otherwise the FN is enough - if (this.vCard.hasProperty('fn')) { + if (fn) { return fn } // BUT if no FN property use the N anyway - if (n) { + if (n && n.join('') !== '') { // Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P. // -> John Stevenson return n.slice(0, 2).reverse().join(' ') } // LAST chance, use the org ir that's the only thing we have - if (org) { - // Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P. - // -> John Stevenson - return org + if (org && org.join('') !== '') { + // org is supposed to be an array but is also used as plain string + return Array.isArray(org) ? org[0] : org } return '' |