diff --git a/dev/App/User.js b/dev/App/User.js index 0da39b022..282b98fa4 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -104,8 +104,8 @@ class AppUser extends AbstractApp { if (rl.hash.check()) { this.reload(); } - Remote.jsVersion((iError, oData) => { - if (!iError && oData && !oData.Result) { + Remote.jsVersion(iError => { + if (100 < iError) { this.reload(); } }, Settings.app('version')); @@ -473,7 +473,7 @@ class AppUser extends AbstractApp { AccountUserStore.loading(false); IdentityUserStore.loading(false); - if (!iError && oData.Result) { + if (!iError) { const counts = {}, sAccountEmail = AccountUserStore.email(); let parentEmail = SettingsGet('ParentEmail') || sAccountEmail; @@ -521,7 +521,7 @@ class AppUser extends AbstractApp { Remote.templates((iError, data) => { TemplateUserStore.templates.loading(false); - if (!iError && data.Result && isArray(data.Result.Templates)) { + if (!iError && isArray(data.Result.Templates)) { delegateRunOnDestroy(TemplateUserStore.templates()); TemplateUserStore.templates( @@ -537,8 +537,6 @@ class AppUser extends AbstractApp { Remote.quota((iError, data) => { if ( !iError && - data && - data.Result && isArray(data.Result) && 1 < data.Result.length && isPosNumeric(data.Result[0], true) && @@ -557,7 +555,7 @@ class AppUser extends AbstractApp { if (folder && folder.trim()) { Remote.folderInformation( (iError, data) => { - if (!iError && data && data.Result && data.Result.Hash && data.Result.Folder) { + if (!iError && data.Result.Hash && data.Result.Folder) { let uid = '', check = false, unreadCountChange = false; @@ -636,7 +634,7 @@ class AppUser extends AbstractApp { const folders = FolderUserStore.getNextFolderNames(refreshFolders); if (isNonEmptyArray(folders)) { Remote.folderInformationMultiply((iError, oData) => { - if (!iError && oData && oData.Result && oData.Result.List && isNonEmptyArray(oData.Result.List)) { + if (!iError && isNonEmptyArray(oData.Result.List)) { const utc = Date.now(); oData.Result.List.forEach(item => { const hash = getFolderHash(item.Folder), @@ -759,7 +757,7 @@ class AppUser extends AbstractApp { */ getAutocomplete(query, autocompleteCallback) { Remote.suggestions((iError, data) => { - if (!iError && data && isArray(data.Result)) { + if (!iError && isArray(data.Result)) { autocompleteCallback( data.Result.map(item => (item && item[0] ? new EmailModel(item[0], item[1]) : null)).filter(v => v) ); diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index 230be3ddd..f9d818fb4 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -68,8 +68,8 @@ export function defaultOptionsAfterRender(domItem, item) { * @returns {mixed} */ export function settingsSaveHelperSimpleFunction(koTrigger, context) { - return (type, data) => { - koTrigger.call(context, data && data.Result ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult); + return iError => { + koTrigger.call(context, iError ? SaveSettingsStep.FalseResult : SaveSettingsStep.TrueResult); setTimeout(() => koTrigger.call(context, SaveSettingsStep.Idle), 1000); }; } diff --git a/dev/Settings/Admin/Branding.js b/dev/Settings/Admin/Branding.js index 96c4d4f6a..8c9152c59 100644 --- a/dev/Settings/Admin/Branding.js +++ b/dev/Settings/Admin/Branding.js @@ -10,31 +10,23 @@ export class BrandingAdminSettings { this.title = ko.observable(SettingsGet('Title')).idleTrigger(); this.loadingDesc = ko.observable(SettingsGet('LoadingDescription')).idleTrigger(); this.faviconUrl = ko.observable(SettingsGet('FaviconUrl')).idleTrigger(); - } - onBuild() { - setTimeout(() => { - const f1 = settingsSaveHelperSimpleFunction(this.title.trigger, this), - f2 = settingsSaveHelperSimpleFunction(this.loadingDesc.trigger, this), - f3 = settingsSaveHelperSimpleFunction(this.faviconUrl.trigger, this); + this.title.subscribe(value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.title.trigger, this), { + 'Title': value.trim() + }) + ); - this.title.subscribe((value) => { - Remote.saveAdminConfig(f1, { - 'Title': value.trim() - }); - }); + this.loadingDesc.subscribe(value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.loadingDesc.trigger, this), { + 'LoadingDescription': value.trim() + }) + ); - this.loadingDesc.subscribe((value) => { - Remote.saveAdminConfig(f2, { - 'LoadingDescription': value.trim() - }); - }); - - this.faviconUrl.subscribe((value) => { - Remote.saveAdminConfig(f3, { - 'FaviconUrl': value.trim() - }); - }); - }, 50); + this.faviconUrl.subscribe(value => + Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.faviconUrl.trigger, this), { + 'FaviconUrl': value.trim() + }) + ); } } diff --git a/dev/Settings/Admin/Contacts.js b/dev/Settings/Admin/Contacts.js index 2fe0eb088..2083051d3 100644 --- a/dev/Settings/Admin/Contacts.js +++ b/dev/Settings/Admin/Contacts.js @@ -133,7 +133,7 @@ export class ContactsAdminSettings { this.testContactsError(false); this.testContactsErrorMessage(''); - if (!iError && data && data.Result && data.Result.Result) { + if (!iError && data.Result.Result) { this.testContactsSuccess(true); } else { this.testContactsError(true); diff --git a/dev/Settings/Admin/Domains.js b/dev/Settings/Admin/Domains.js index 3562742f2..6e93797de 100644 --- a/dev/Settings/Admin/Domains.js +++ b/dev/Settings/Admin/Domains.js @@ -46,7 +46,7 @@ export class DomainsAdminSettings { } onDomainLoadRequest(iError, oData) { - if (!iError && oData && oData.Result) { + if (!iError) { showScreenPopup(DomainPopupView, [oData.Result]); } } diff --git a/dev/Settings/Admin/Plugins.js b/dev/Settings/Admin/Plugins.js index 9c0a3f80a..aca7842ee 100644 --- a/dev/Settings/Admin/Plugins.js +++ b/dev/Settings/Admin/Plugins.js @@ -54,7 +54,7 @@ export class PluginsAdminSettings { } onPluginLoadRequest(iError, data) { - if (!iError && data && data.Result) { + if (!iError) { showScreenPopup(PluginPopupView, [data.Result]); } } diff --git a/dev/Settings/Admin/Security.js b/dev/Settings/Admin/Security.js index 9fbf2e3ed..300e0ebd3 100644 --- a/dev/Settings/Admin/Security.js +++ b/dev/Settings/Admin/Security.js @@ -130,7 +130,9 @@ export class SecurityAdminSettings { } onNewAdminPasswordResponse(iError, data) { - if (!iError && data && data.Result) { + if (iError) { + this.adminPasswordUpdateError(true); + } else { this.adminPassword(''); this.adminPasswordNew(''); this.adminPasswordNew2(''); @@ -138,8 +140,6 @@ export class SecurityAdminSettings { this.adminPasswordUpdateSuccess(true); this.weakPassword(!!data.Result.Weak); - } else { - this.adminPasswordUpdateError(true); } } diff --git a/dev/Settings/User/Accounts.js b/dev/Settings/User/Accounts.js index 33ee8578a..a55e9a09a 100644 --- a/dev/Settings/User/Accounts.js +++ b/dev/Settings/User/Accounts.js @@ -54,7 +54,7 @@ export class AccountsUserSettings { this.accounts.remove((account) => accountToRemove === account); Remote.accountDelete((iError, data) => { - if (!iError && data && data.Result && data.Reload) { + if (!iError && data.Reload) { rl.route.root(); setTimeout(() => location.reload(), 1); } else { diff --git a/dev/Settings/User/Security.js b/dev/Settings/User/Security.js index 6d12fe73c..c2609bdd8 100644 --- a/dev/Settings/User/Security.js +++ b/dev/Settings/User/Security.js @@ -43,11 +43,12 @@ export class SecurityUserSettings { onBuild() { if (this.capaAutoLogout) { - setTimeout(() => { - const f0 = settingsSaveHelperSimpleFunction(this.autoLogout.trigger, this); - - this.autoLogout.subscribe(Remote.saveSettingsHelper('AutoLogout', pInt, f0)); - }); + setTimeout(() => + this.autoLogout.subscribe(Remote.saveSettingsHelper( + 'AutoLogout', pInt, + settingsSaveHelperSimpleFunction(this.autoLogout.trigger, this) + )) + ); } } } diff --git a/dev/Stores/Admin/Domain.js b/dev/Stores/Admin/Domain.js index 6eb303e84..37d1c62ba 100644 --- a/dev/Stores/Admin/Domain.js +++ b/dev/Stores/Admin/Domain.js @@ -9,7 +9,7 @@ DomainAdminStore.fetch = () => { DomainAdminStore.loading(true); Remote.domainList((iError, data) => { DomainAdminStore.loading(false); - if (!iError && data && data.Result) { + if (!iError) { DomainAdminStore( Object.entries(data.Result).map(([name, [enabled, alias]]) => ({ name: name, diff --git a/dev/Stores/Admin/Package.js b/dev/Stores/Admin/Package.js index 9bfbf6cd4..2753dea47 100644 --- a/dev/Stores/Admin/Package.js +++ b/dev/Stores/Admin/Package.js @@ -12,7 +12,7 @@ PackageAdminStore.fetch = () => { PackageAdminStore.loading(true); Remote.packagesList((iError, data) => { PackageAdminStore.loading(false); - if (!iError && data && data.Result) { + if (!iError) { PackageAdminStore.real(!!data.Result.Real); let list = []; diff --git a/dev/Stores/Admin/Plugin.js b/dev/Stores/Admin/Plugin.js index 22ede8f84..6b4bc50e2 100644 --- a/dev/Stores/Admin/Plugin.js +++ b/dev/Stores/Admin/Plugin.js @@ -11,7 +11,7 @@ PluginAdminStore.fetch = () => { PluginAdminStore.loading(true); Remote.pluginList((iError, data) => { PluginAdminStore.loading(false); - if (!iError && data && data.Result) { + if (!iError) { PluginAdminStore( data.Result.map(item => ({ name: item.Name, diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 2caa29f41..36522afe6 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -605,7 +605,7 @@ class ComposePopupView extends AbstractViewPopup { this.saving(false); - if (!iError && oData && oData.Result) { + if (!iError) { if (oData.Result.NewFolder && oData.Result.NewUid) { result = true; @@ -1032,7 +1032,7 @@ class ComposePopupView extends AbstractViewPopup { const downloads = this.getAttachmentsDownloadsForUpload(); if (isNonEmptyArray(downloads)) { Remote.messageUploadAttachments((iError, oData) => { - if (!iError && oData && oData.Result) { + if (!iError) { Object.entries(oData.Result).forEach(([tempName, id]) => { const attachment = this.getAttachmentById(id); if (attachment) { diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 39fb0db49..6faf64ab9 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -225,8 +225,6 @@ class ContactsPopupView extends AbstractViewPopup { if ( !iError && - oData && - oData.Result && oData.Result.RequestUid === requestUid && 0 < pInt(oData.Result.ResultID) ) { @@ -457,16 +455,14 @@ class ContactsPopupView extends AbstractViewPopup { let count = 0, list = []; - if (!iError && data && data.Result && data.Result.List) { - if (isNonEmptyArray(data.Result.List)) { - data.Result.List.forEach(item => { - item = ContactModel.reviveFromJson(item); - item && list.push(item); - }); + if (!iError && isNonEmptyArray(data.Result.List)) { + data.Result.List.forEach(item => { + item = ContactModel.reviveFromJson(item); + item && list.push(item); + }); - count = pInt(data.Result.Count); - count = 0 < count ? count : 0; - } + count = pInt(data.Result.Count); + count = 0 < count ? count : 0; } this.contactsCount(count); diff --git a/dev/View/Popup/Domain.js b/dev/View/Popup/Domain.js index 0a086c929..3c5ea7925 100644 --- a/dev/View/Popup/Domain.js +++ b/dev/View/Popup/Domain.js @@ -206,7 +206,12 @@ class DomainPopupView extends AbstractViewPopup { onTestConnectionResponse(iError, oData) { this.testing(false); - if (!iError && oData.Result) { + if (iError) { + this.testingImapError(true); + this.testingSieveError(true); + this.testingSmtpError(true); + this.sieveSettings(false); + } else { let bImap = false, bSieve = false; @@ -239,11 +244,6 @@ class DomainPopupView extends AbstractViewPopup { } else if (bSieve && !bImap) { this.sieveSettings(true); } - } else { - this.testingImapError(true); - this.testingSieveError(true); - this.testingSmtpError(true); - this.sieveSettings(false); } } diff --git a/dev/View/Popup/Template.js b/dev/View/Popup/Template.js index 08fc82552..aa700ff64 100644 --- a/dev/View/Popup/Template.js +++ b/dev/View/Popup/Template.js @@ -124,7 +124,6 @@ class TemplatePopupView extends AbstractViewPopup { if ( !iError && - data && TemplateModel.validJson(data.Result) && null != data.Result.Body ) { diff --git a/dev/View/Popup/TwoFactorConfiguration.js b/dev/View/Popup/TwoFactorConfiguration.js index d3135720d..ab1a3d23e 100644 --- a/dev/View/Popup/TwoFactorConfiguration.js +++ b/dev/View/Popup/TwoFactorConfiguration.js @@ -36,6 +36,7 @@ class TwoFactorConfigurationPopupView extends AbstractViewPopup { this.capaTwoFactor = Settings.capa(Capa.TwoFactor); + const fn = iError => iError && this.viewEnable_(false); this.addComputables({ viewEnable: { read: this.viewEnable_, @@ -43,21 +44,12 @@ class TwoFactorConfigurationPopupView extends AbstractViewPopup { value = !!value; if (value && this.twoFactorTested()) { this.viewEnable_(value); - Remote.enableTwoFactor((iError, data) => { - if (iError || !data || !data.Result) { - this.viewEnable_(false); - } - }, true); + Remote.enableTwoFactor(fn, value); } else { if (!value) { this.viewEnable_(value); } - - Remote.enableTwoFactor((iError, data) => { - if (iError || !data || !data.Result) { - this.viewEnable_(false); - } - }, false); + Remote.enableTwoFactor(fn, false); } } }, @@ -152,7 +144,17 @@ class TwoFactorConfigurationPopupView extends AbstractViewPopup { this.processing(false); this.clearing(false); - if (!iError && oData && oData.Result) { + if (iError) { + this.viewUser(''); + this.viewEnable_(false); + this.twoFactorStatus(false); + this.twoFactorTested(false); + + this.viewSecret(''); + this.viewBackupCodes(''); + this.viewUrlTitle(''); + this.viewUrl(''); + } else { this.viewUser(pString(oData.Result.User)); this.viewEnable_(!!oData.Result.Enable); this.twoFactorStatus(!!oData.Result.IsSet); @@ -163,30 +165,20 @@ class TwoFactorConfigurationPopupView extends AbstractViewPopup { this.viewUrlTitle(pString(oData.Result.UrlTitle)); this.viewUrl(qr.toDataURL({ level: 'M', size: 8, value: this.getQr() })); - } else { - this.viewUser(''); - this.viewEnable_(false); - this.twoFactorStatus(false); - this.twoFactorTested(false); - - this.viewSecret(''); - this.viewBackupCodes(''); - this.viewUrlTitle(''); - this.viewUrl(''); } } onShowSecretResult(iError, data) { this.secreting(false); - if (!iError && data && data.Result) { - this.viewSecret(pString(data.Result.Secret)); - this.viewUrlTitle(pString(data.Result.UrlTitle)); - this.viewUrl(qr.toDataURL({ level: 'M', size: 6, value: this.getQr() })); - } else { + if (iError) { this.viewSecret(''); this.viewUrlTitle(''); this.viewUrl(''); + } else { + this.viewSecret(pString(data.Result.Secret)); + this.viewUrlTitle(pString(data.Result.UrlTitle)); + this.viewUrl(qr.toDataURL({ level: 'M', size: 6, value: this.getQr() })); } } diff --git a/dev/View/Popup/TwoFactorTest.js b/dev/View/Popup/TwoFactorTest.js index 67335bb43..6b8949255 100644 --- a/dev/View/Popup/TwoFactorTest.js +++ b/dev/View/Popup/TwoFactorTest.js @@ -24,9 +24,9 @@ class TwoFactorTestPopupView extends AbstractViewPopup { testCodeCommand() { this.testing(true); - Remote.testTwoFactor((iError, data) => { + Remote.testTwoFactor(iError => { this.testing(false); - this.codeStatus(!iError && data && !!data.Result); + this.codeStatus(!iError); if (this.koTestedTrigger && this.codeStatus()) { this.koTestedTrigger(true); diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index 87acdc9b9..303cdcc36 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -850,8 +850,8 @@ export class MessageListMailBoxUserView extends AbstractViewRight { addRequestedMessage(message.folder, message.uid); Remote.message( - (iError, data) => { - const next = !!(!iError && data && data.Result); + iError => { + const next = !iError; setTimeout(() => { this.bPrefetch = false; next && this.prefetchNextTick();