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

View file

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

View file

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

View file

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

View file

@ -144,12 +144,15 @@ trait Contacts
{ {
foreach ($aProperties as $aItem) 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 = new \RainLoop\Providers\AddressBook\Classes\Property();
$oProp->Type = (int) $aItem[0]; $oProp->Type = (int) $aItem['type'];
$oProp->Value = $aItem[1]; $oProp->Value = \trim($aItem['value']);
$oProp->TypeStr = empty($aItem[2]) ? '': $aItem[2]; $oProp->TypeStr = $aItem['typeStr'] ?? '';
$oContact->Properties[] = $oProp; $oContact->Properties[] = $oProp;
} }

View file

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

View file

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