Bugfix: Contacts management failed

It had a strange array type structure and buggy
This commit is contained in:
djmaze 2020-10-20 15:37:06 +02:00
parent 0e3275599e
commit 3a315bc543
7 changed files with 44 additions and 40 deletions

View file

@ -31,12 +31,12 @@ class ContactModel extends AbstractModel {
if (Array.isNotEmpty(this.properties)) {
this.properties.forEach(property => {
if (property) {
if (ContactPropertyType.FirstName === property[0]) {
name = (property[1] + ' ' + name).trim();
} else if (ContactPropertyType.LastName === property[0]) {
name = (name + ' ' + property[1]).trim();
} else if (!email && ContactPropertyType.Email === property[0]) {
email = property[1];
if (ContactPropertyType.FirstName === property.type()) {
name = (property.value() + ' ' + name).trim();
} else if (ContactPropertyType.LastName === property.type()) {
name = (name + ' ' + property.value()).trim();
} else if (!email && ContactPropertyType.Email === property.type()) {
email = property.value();
}
}
});
@ -59,7 +59,7 @@ class ContactModel extends AbstractModel {
let list = [];
if (Array.isNotEmpty(json.properties)) {
json.Properties.forEach(property => {
json.properties.forEach(property => {
property = ContactPropertyModel.reviveFromJson(property);
property && list.push(property);
});

View file

@ -34,11 +34,19 @@ class ContactPropertyModel extends AbstractModel {
this.regDisposables([this.placeholderValue, this.largeValue]);
}
toJSON() {
return {
type: this.type(),
typeStr: this.typeStr(),
value: this.value()
};
}
static reviveFromJson(json) {
const property = super.reviveFromJson(json);
if (property) {
property.type(pInt(property.type));
property.typeStr(pInt(property.typeStr));
property.type(pInt(json.type));
property.typeStr(pString(json.typeStr));
property.value(pString(json.value));
return property;
}