Cleanup array.length checks and for() to forEach()

This commit is contained in:
djmaze 2020-07-28 12:35:41 +02:00
parent db5751cd00
commit 82bed1ed80
24 changed files with 135 additions and 169 deletions

View file

@ -111,11 +111,11 @@ class AdvancedSearchPopupView extends AbstractViewNext {
isPart.push('flagged');
}
if (0 < hasPart.length) {
if (hasPart.length) {
result.push('has:' + hasPart.join(','));
}
if (0 < isPart.length) {
if (isPart.length) {
result.push('is:' + isPart.join(','));
}

View file

@ -202,19 +202,19 @@ class ComposePopupView extends AbstractViewNext {
this.showReplyTo = ko.observable(false);
this.cc.subscribe((value) => {
if (false === this.showCc() && 0 < value.length) {
if (false === this.showCc() && value.length) {
this.showCc(true);
}
});
this.bcc.subscribe((value) => {
if (false === this.showBcc() && 0 < value.length) {
if (false === this.showBcc() && value.length) {
this.showBcc(true);
}
});
this.replyTo.subscribe((value) => {
if (false === this.showReplyTo() && 0 < value.length) {
if (false === this.showReplyTo() && value.length) {
this.showReplyTo(true);
}
});
@ -286,13 +286,13 @@ class ComposePopupView extends AbstractViewNext {
});
this.to.subscribe((value) => {
if (this.emptyToError() && 0 < value.length) {
if (this.emptyToError() && value.length) {
this.emptyToError(false);
}
});
this.attachmentsInProcess.subscribe((value) => {
if (this.attachmentsInProcessError() && isArray(value) && 0 === value.length) {
if (this.attachmentsInProcessError() && isArray(value) && value.length) {
this.attachmentsInProcessError(false);
}
});
@ -352,10 +352,10 @@ class ComposePopupView extends AbstractViewNext {
this.attachmentsInErrorError(false);
this.emptyToError(false);
if (0 < this.attachmentsInProcess().length) {
if (this.attachmentsInProcess().length) {
this.attachmentsInProcessError(true);
this.attachmentsPlace(true);
} else if (0 < this.attachmentsInError().length) {
} else if (this.attachmentsInError().length) {
this.attachmentsInErrorError(true);
this.attachmentsPlace(true);
}
@ -370,7 +370,7 @@ class ComposePopupView extends AbstractViewNext {
isArray(this.aDraftInfo) &&
3 === this.aDraftInfo.length &&
isNormal(this.aDraftInfo[2]) &&
0 < this.aDraftInfo[2].length
this.aDraftInfo[2].length
) {
sSentFolder = this.aDraftInfo[2];
}
@ -774,7 +774,7 @@ class ComposePopupView extends AbstractViewNext {
}
}
if (moments && 0 < moments.length) {
if (moments) {
moments.forEach(data => {
signature = signature.replace(data[0], momentorFormat(0, data[1]));
});
@ -1055,7 +1055,7 @@ class ComposePopupView extends AbstractViewNext {
i18n('COMPOSE/FORWARD_MESSAGE_TOP_TO') +
': ' +
sTo +
(0 < sCc.length ? '<br />' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') +
(sCc.length ? '<br />' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') +
'<br />' +
i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT') +
': ' +
@ -1379,7 +1379,7 @@ class ComposePopupView extends AbstractViewNext {
}
if (attachment) {
if ('' !== error && 0 < error.length) {
if ('' !== error && error.length) {
attachment
.waiting(false)
.uploading(false)
@ -1542,15 +1542,15 @@ class ComposePopupView extends AbstractViewNext {
*/
isEmptyForm(includeAttachmentInProgress = true) {
const withoutAttachment = includeAttachmentInProgress
? 0 === this.attachments().length
: 0 === this.attachmentsInReady().length;
? !this.attachments().length
: !this.attachmentsInReady().length;
return (
0 === this.to().length &&
0 === this.cc().length &&
0 === this.bcc().length &&
0 === this.replyTo().length &&
0 === this.subject().length &&
!this.to().length &&
!this.cc().length &&
!this.bcc().length &&
!this.replyTo().length &&
!this.subject().length &&
withoutAttachment &&
(!this.oEditor || '' === this.oEditor.getData())
);

View file

@ -152,7 +152,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
}
if (result && this.encrypt()) {
if (0 === this.encryptKeys().length) {
if (!this.encryptKeys().length) {
this.notification(i18n('PGP_NOTIFICATIONS/NO_PUBLIC_KEYS_FOUND'));
result = false;
} else if (this.encryptKeys()) {
@ -172,7 +172,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
}
});
if (result && (0 === aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length)) {
if (result && (!aPublicKeys.length || this.encryptKeys().length !== aPublicKeys.length)) {
result = false;
}
}
@ -183,22 +183,24 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
let pgpPromise = null;
try {
if (privateKey && 0 === aPublicKeys.length) {
if (aPublicKeys.length) {
if (privateKey) {
pgpPromise = PgpStore.openpgp.encrypt({
data: this.text(),
publicKeys: aPublicKeys,
privateKeys: [privateKey]
});
} else {
pgpPromise = PgpStore.openpgp.encrypt({
data: this.text(),
publicKeys: aPublicKeys
});
}
} else if (privateKey) {
pgpPromise = PgpStore.openpgp.sign({
data: this.text(),
privateKeys: [privateKey]
});
} else if (privateKey && 0 < aPublicKeys.length) {
pgpPromise = PgpStore.openpgp.encrypt({
data: this.text(),
publicKeys: aPublicKeys,
privateKeys: [privateKey]
});
} else if (!privateKey && 0 < aPublicKeys.length) {
pgpPromise = PgpStore.openpgp.encrypt({
data: this.text(),
publicKeys: aPublicKeys
});
}
} catch (e) {
log(e);
@ -380,7 +382,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
this.sign(true);
}
if (rec && 0 < rec.length) {
if (rec.length) {
this.encryptKeys(
rec.map(recEmail => {
const keys = PgpStore.findAllPublicKeysByEmailNotNative(recEmail);
@ -401,7 +403,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
)
);
if (0 < this.encryptKeys().length) {
if (this.encryptKeys().length) {
this.encrypt(true);
}
}

View file

@ -58,7 +58,7 @@ class ContactsPopupView extends AbstractViewNext {
super();
const fFastClearEmptyListHelper = (list) => {
if (list && 0 < list.length) {
if (list && list.length) {
this.viewProperties.removeAll(list);
delegateRunOnDestroy(list);
}
@ -456,7 +456,7 @@ class ContactsPopupView extends AbstractViewNext {
let currentContact = this.currentContact(),
count = this.contacts().length;
if (0 < contacts.length) {
if (contacts.length) {
contacts.forEach(contact => {
if (currentContact && currentContact.idContact === contact.idContact) {
currentContact = null;
@ -481,7 +481,7 @@ class ContactsPopupView extends AbstractViewNext {
}
deleteSelectedContacts() {
if (0 < this.contactsCheckedOrSelected().length) {
if (this.contactsCheckedOrSelected().length) {
Remote.contactsDelete(this.deleteResponse.bind(this), this.contactsCheckedOrSelectedUids());
this.removeCheckedOrSelectedContactsFromList();

View file

@ -43,13 +43,13 @@ class IdentityPopupView extends AbstractViewNext {
this.submitError = ko.observable('');
this.bcc.subscribe((value) => {
if (false === this.showBcc() && 0 < value.length) {
if (false === this.showBcc() && value.length) {
this.showBcc(true);
}
});
this.replyTo.subscribe((value) => {
if (false === this.showReplyTo() && 0 < value.length) {
if (false === this.showReplyTo() && value.length) {
this.showReplyTo(true);
}
});