improve compatibily with macOS contacts

Signed-off-by: Johannes Zlattinger <johannes@zlattinger.net>
This commit is contained in:
Johannes Zlattinger 2020-12-30 13:57:15 +01:00
parent 639e2a186e
commit 564f6dc756
3 changed files with 32 additions and 5 deletions

View File

@ -37,6 +37,12 @@ const isEmpty = value => {
return (Array.isArray(value) && value.join('') === '') || (!Array.isArray(value) && value === '')
}
export const ContactKindProperties = ['KIND', 'X-ADDRESSBOOKSERVER-KIND']
export const MinimalContactProperties = [
'EMAIL', 'UID', 'CATEGORIES', 'FN', 'ORG', 'N', 'X-PHONETIC-FIRST-NAME', 'X-PHONETIC-LAST-NAME',
].concat(ContactKindProperties)
export default class Contact {
/**
@ -79,7 +85,6 @@ export default class Contact {
const rev = new ICAL.VCardTime(null, null, 'date-time')
rev.fromUnixTime(Date.now() / 1000)
this.vCard.addPropertyWithValue('rev', rev)
}
}
@ -300,7 +305,13 @@ export default class Contact {
* @memberof Contact
*/
get kind() {
return this.firstIfArray(this.vCard.getFirstPropertyValue('kind'))
return this.firstIfArray(
ContactKindProperties
.map(s => s.toLowerCase())
.map(s => this.vCard.getFirstPropertyValue(s))
.flat()
.filter(k => k)
)
}
/**

View File

@ -25,7 +25,7 @@ import { showError } from '@nextcloud/dialogs'
import pLimit from 'p-limit'
import Vue from 'vue'
import Contact from '../models/contact'
import Contact, { MinimalContactProperties } from '../models/contact'
import client from '../services/cdav'
import parseVcf from '../services/parseVcf'
@ -346,8 +346,7 @@ const actions = {
*/
async getContactsFromAddressBook(context, { addressbook }) {
return addressbook.dav
.findAllAndFilterBySimpleProperties(['EMAIL', 'UID', 'CATEGORIES', 'FN', 'ORG', 'N',
'X-PHONETIC-FIRST-NAME', 'X-PHONETIC-LAST-NAME'])
.findAllAndFilterBySimpleProperties(MinimalContactProperties)
.then((response) => {
// We don't want to lose the url information
// so we need to parse one by one

View File

@ -27,6 +27,23 @@ import Vue from 'vue'
import Contact from '../models/contact'
import validate from '../services/validate'
/*
* Currently ical.js does not serialize parameters with multiple values correctly. This is
* especially problematic for the type parmeter which frequently is used with multiple values
* (e.g. "HOME" and "VOICE"). A phone number for example shoud be serialized as
* 'TEL;TYPE=HOME,VOICE:0815 123456' OR 'TEL;TYPE="HOME","VOICE":0815 123456' according to
* https://tools.ietf.org/html/rfc2426#section-4. Unfortunately currently it is serialized as
* 'TEL;TYPE="HOME,VOICE":0815 123456', which makes the value appear as a single value
* containing a comma instead of two separate values. By forcing all values being escaped by
* double quotes the string serialization can be fixed.
*
* However there is a pull request (https://github.com/mozilla-comm/ical.js/pull/460) waiting
* to be merged for ical.js. Until this fix is merged and released the following configuration
* changes apply the workaround described above.
*/
ICAL.design.vcard3.param.type.multiValueSeparateDQuote = true
ICAL.design.vcard.param.type.multiValueSeparateDQuote = true
const sortData = (a, b) => {
const nameA = typeof a.value === 'string'
? a.value.toUpperCase() // ignore upper and lowercase