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;
}

View file

@ -719,7 +719,7 @@ class RemoteUserFetch extends AbstractFetchRemote {
contactSave(fCallback, sRequestUid, sUid, aProperties) {
this.defaultRequest(fCallback, 'ContactSave', {
RequestUid: sRequestUid,
Uid: sUid.trim(),
Uid: sUid,
Properties: aProperties
});
}

View file

@ -40,13 +40,6 @@ class ContactsPopupView extends AbstractViewNext {
constructor() {
super();
const fFastClearEmptyListHelper = (list) => {
if (list && list.length) {
this.viewProperties.removeAll(list);
delegateRunOnDestroy(list);
}
};
this.bBackToCompose = false;
this.sLastComposeFocusedField = '';
@ -98,7 +91,7 @@ class ContactsPopupView extends AbstractViewNext {
this.viewHasNonEmptyRequiredProperties = ko.computed(() => {
const names = this.viewPropertiesNames(),
emails = this.viewPropertiesEmails(),
fFilter = (property) => !!trim(property.value());
fFilter = property => !!trim(property.value());
return !!(names.find(fFilter) || emails.find(fFilter));
});
@ -130,10 +123,19 @@ class ContactsPopupView extends AbstractViewNext {
this.viewPropertiesOther().filter(propertyFocused)
);
/*
// Somehow this is broken now when calling addNewProperty
const fFastClearEmptyListHelper = list => {
if (list && list.length) {
this.viewProperties.removeAll(list);
delegateRunOnDestroy(list);
}
};
this.viewPropertiesEmailsEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper);
this.viewPropertiesPhonesEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper);
this.viewPropertiesWebEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper);
this.viewPropertiesOtherEmptyAndOnFocused.subscribe(fFastClearEmptyListHelper);
*/
this.viewSaving = ko.observable(false);
@ -278,14 +280,7 @@ class ContactsPopupView extends AbstractViewNext {
this.viewSaving(true);
this.viewSaveTrigger(SaveSettingsStep.Animate);
const requestUid = Jua.randomId(),
properties = [];
this.viewProperties().forEach(oItem => {
if (oItem.type() && oItem.type() !== ContactPropertyType.FullName && trim(oItem.value())) {
properties.push([oItem.type(), oItem.value(), oItem.typeStr()]);
}
});
const requestUid = Jua.randomId();
Remote.contactSave(
(sResult, oData) => {
@ -303,25 +298,22 @@ class ContactsPopupView extends AbstractViewNext {
this.viewID(pInt(oData.Result.ResultID));
}
this.reloadContactList();
this.reloadContactList(); // TODO: remove when e-contact-foreach is dynamic
res = true;
}
setTimeout(() => {
this.viewSaveTrigger(res ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult);
}, 350);
setTimeout(() =>
this.viewSaveTrigger(res ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult)
, 350);
if (res) {
this.watchDirty(false);
setTimeout(() => {
this.viewSaveTrigger(SaveSettingsStep.Idle);
}, 1000);
setTimeout(() => this.viewSaveTrigger(SaveSettingsStep.Idle), 1000);
}
},
requestUid,
this.viewID(),
properties
this.viewProperties().map(oItem => oItem.toJSON())
);
}

View file

@ -144,12 +144,15 @@ trait Contacts
{
foreach ($aProperties as $aItem)
{
if ($aItem && isset($aItem[0], $aItem[1]) && \is_numeric($aItem[0]))
if ($aItem && isset($aItem['type'], $aItem['value'])
&& \is_numeric($aItem['type']) && (int) $aItem['type']
&& \RainLoop\Providers\AddressBook\Enumerations\PropertyType::FULLNAME != $aItem['type']
&& \strlen(\trim($aItem['value'])))
{
$oProp = new \RainLoop\Providers\AddressBook\Classes\Property();
$oProp->Type = (int) $aItem[0];
$oProp->Value = $aItem[1];
$oProp->TypeStr = empty($aItem[2]) ? '': $aItem[2];
$oProp->Type = (int) $aItem['type'];
$oProp->Value = \trim($aItem['value']);
$oProp->TypeStr = $aItem['typeStr'] ?? '';
$oContact->Properties[] = $oProp;
}

View file

@ -645,6 +645,7 @@ class Contact implements \JsonSerializable
}
return array(
'@Object' => 'Object/Contact',
'id' => $this->IdContact,
'display' => \MailSo\Base\Utils::Utf8Clear($this->Display),
'readOnly' => $this->ReadOnly,
'IdPropertyFromSearch' => $this->IdPropertyFromSearch,

View file

@ -159,6 +159,6 @@ class Property implements \JsonSerializable
'type' => $this->Type,
'typeStr' => $this->TypeStr,
'value' => \MailSo\Base\Utils::Utf8Clear($this->Value)
));
);
}
}