diff --git a/dev/Model/Contact.js b/dev/Model/Contact.js index 91aac574e..d94c45067 100644 --- a/dev/Model/Contact.js +++ b/dev/Model/Contact.js @@ -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); }); diff --git a/dev/Model/ContactProperty.js b/dev/Model/ContactProperty.js index 7856bc224..b372180e7 100644 --- a/dev/Model/ContactProperty.js +++ b/dev/Model/ContactProperty.js @@ -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; } diff --git a/dev/Remote/User/Fetch.js b/dev/Remote/User/Fetch.js index 815aba0aa..e8d19222b 100644 --- a/dev/Remote/User/Fetch.js +++ b/dev/Remote/User/Fetch.js @@ -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 }); } diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index b2dd75619..41f1df6aa 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -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()) ); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php index 182b7fa06..c01da9b07 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php @@ -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; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php index 75117998c..3a564f7ba 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php @@ -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, diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Property.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Property.php index 01f9a3666..9cab34508 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Property.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Property.php @@ -159,6 +159,6 @@ class Property implements \JsonSerializable 'type' => $this->Type, 'typeStr' => $this->TypeStr, 'value' => \MailSo\Base\Utils::Utf8Clear($this->Value) - )); + ); } }