From d49536968882a7ad842de7f5d4f0ebc291462a42 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 21 Feb 2023 16:02:22 +0100 Subject: [PATCH] Cleanup IdentityModel handling --- dev/App/User.js | 15 ++------------- dev/Model/Identity.js | 6 +++--- dev/View/Popup/Identity.js | 1 - .../app/libraries/RainLoop/Model/Identity.php | 19 ++++++++++--------- .../templates/Views/User/PopupsIdentity.html | 3 ++- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/dev/App/User.js b/dev/App/User.js index a0fd68a57..bfb6cbd44 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -1,7 +1,7 @@ import 'External/User/ko'; import { SMAudio } from 'Common/Audio'; -import { isArray, pString, pInt } from 'Common/Utils'; +import { isArray, pInt } from 'Common/Utils'; import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility } from 'Common/UtilsUser'; import { @@ -160,18 +160,7 @@ export class AppUser extends AbstractApp { items = oData.Result.Identities; IdentityUserStore(isArray(items) - ? items.map(identityData => { - const identity = new IdentityModel( - pString(identityData.Id), - pString(identityData.Email) - ); - identity.name(pString(identityData.Name)); - identity.replyTo(pString(identityData.ReplyTo)); - identity.bcc(pString(identityData.Bcc)); - identity.signature(pString(identityData.Signature)); - identity.signatureInsertBefore(!!identityData.SignatureInsertBefore); - return identity; - }) + ? items.map(identityData => IdentityModel.reviveFromJson(identityData)) : [] ); } diff --git a/dev/Model/Identity.js b/dev/Model/Identity.js index c5328594b..481fe492f 100644 --- a/dev/Model/Identity.js +++ b/dev/Model/Identity.js @@ -6,12 +6,12 @@ export class IdentityModel extends AbstractModel { * @param {string} id * @param {string} email */ - constructor(id, email) { + constructor() { super(); addObservablesTo(this, { - id: id || '', - email: email, + id: '', + email: '', name: '', replyTo: '', diff --git a/dev/View/Popup/Identity.js b/dev/View/Popup/Identity.js index c4f2d3c8e..42de75bad 100644 --- a/dev/View/Popup/Identity.js +++ b/dev/View/Popup/Identity.js @@ -63,7 +63,6 @@ export class IdentityPopupView extends AbstractViewPopup { const data = new FormData(form); data.set('Id', this.id); data.set('Signature', this.signature()); - data.set('SignatureInsertBefore', this.signatureInsertBefore() ? 1 : 0); Remote.request('IdentityUpdate', iError => { this.submitRequest(false); if (iError) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php index 45ddf142d..921d73b6d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Identity.php @@ -103,8 +103,7 @@ class Identity implements \JsonSerializable $this->sReplyTo = !empty($aData['ReplyTo']) ? $aData['ReplyTo'] : ''; $this->sBcc = !empty($aData['Bcc']) ? $aData['Bcc'] : ''; $this->sSignature = !empty($aData['Signature']) ? $aData['Signature'] : ''; - $this->bSignatureInsertBefore = isset($aData['SignatureInsertBefore']) ? - !empty($aData['SignatureInsertBefore']) : true; + $this->bSignatureInsertBefore = !empty($aData['SignatureInsertBefore']); return true; } @@ -112,6 +111,7 @@ class Identity implements \JsonSerializable return false; } + // Used to store public function ToSimpleJSON(): array { return array( @@ -129,13 +129,14 @@ class Identity implements \JsonSerializable public function jsonSerialize() { return array( - 'Id' => $this->sId, - 'Email' => Utils::IdnToUtf8($this->sEmail), - 'Name' => $this->sName, - 'ReplyTo' => $this->sReplyTo, - 'Bcc' => $this->sBcc, - 'Signature' => $this->sSignature, - 'SignatureInsertBefore' => $this->bSignatureInsertBefore + '@Object' => 'Object/Identity', + 'id' => $this->sId, + 'email' => Utils::IdnToUtf8($this->sEmail), + 'name' => $this->sName, + 'replyTo' => $this->sReplyTo, + 'bcc' => $this->sBcc, + 'signature' => $this->sSignature, + 'signatureInsertBefore' => $this->bSignatureInsertBefore ); } diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html index 39f0d5034..844c7c280 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsIdentity.html @@ -56,7 +56,8 @@ name: 'Checkbox', params: { label: 'POPUPS_IDENTITY/LABEL_SIGNATURE_INSERT_BEFORE', - value: signatureInsertBefore + value: signatureInsertBefore, + name: 'SignatureInsertBefore' } }">