Cleanup more iError && data.Result

This commit is contained in:
djmaze 2021-03-18 14:48:21 +01:00
parent 87bee226b4
commit ce74b2e92f
19 changed files with 78 additions and 100 deletions

View file

@ -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)
);

View file

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

View file

@ -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()
})
);
}
}

View file

@ -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);

View file

@ -46,7 +46,7 @@ export class DomainsAdminSettings {
}
onDomainLoadRequest(iError, oData) {
if (!iError && oData && oData.Result) {
if (!iError) {
showScreenPopup(DomainPopupView, [oData.Result]);
}
}

View file

@ -54,7 +54,7 @@ export class PluginsAdminSettings {
}
onPluginLoadRequest(iError, data) {
if (!iError && data && data.Result) {
if (!iError) {
showScreenPopup(PluginPopupView, [data.Result]);
}
}

View file

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

View file

@ -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 {

View file

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

View file

@ -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,

View file

@ -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 = [];

View file

@ -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,

View file

@ -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) {

View file

@ -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);

View file

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

View file

@ -124,7 +124,6 @@ class TemplatePopupView extends AbstractViewPopup {
if (
!iError &&
data &&
TemplateModel.validJson(data.Result) &&
null != data.Result.Body
) {

View file

@ -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() }));
}
}

View file

@ -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);

View file

@ -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();