From 82bed1ed806e46cdbecc2194e09dee42477f1ec6 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 28 Jul 2020 12:35:41 +0200 Subject: [PATCH] Cleanup array.length checks and for() to forEach() --- README.md | 10 +++--- dev/App/Abstract.js | 2 +- dev/App/User.js | 8 ++--- dev/Common/Cache.js | 12 +++---- dev/Common/Selector.js | 6 ++-- dev/Common/Utils.js | 50 +++++++++++----------------- dev/External/ko.js | 2 +- dev/Helper/Message.js | 43 ++++++++---------------- dev/Model/Filter.js | 2 +- dev/Model/Folder.js | 2 +- dev/Model/Message.js | 15 ++++----- dev/Remote/User/Ajax.js | 6 ++-- dev/Settings/Admin/Contacts.js | 2 +- dev/Stores/User/Folder.js | 4 +-- dev/Stores/User/Message.js | 15 +++------ dev/Stores/User/Pgp.js | 8 ++--- dev/Stores/User/Template.js | 2 +- dev/View/Popup/AdvancedSearch.js | 4 +-- dev/View/Popup/Compose.js | 36 ++++++++++---------- dev/View/Popup/ComposeOpenPgp.js | 34 ++++++++++--------- dev/View/Popup/Contacts.js | 6 ++-- dev/View/Popup/Identity.js | 4 +-- dev/View/User/MailBox/MessageList.js | 25 ++++++-------- dev/View/User/MailBox/MessageView.js | 6 ++-- 24 files changed, 135 insertions(+), 169 deletions(-) diff --git a/README.md b/README.md index 33fc3bc12..67cc42c9d 100644 --- a/README.md +++ b/README.md @@ -62,22 +62,22 @@ Things might work in Edge 15-18, Firefox 47-62 and Chrome 54-68 due to one polyf |js/* |1.14.0 |native | |----------- |--------: |--------: | |admin.js |2.130.942 |1.359.501 | -|app.js |4.184.455 |3.127.807 | +|app.js |4.184.455 |3.121.743 | |boot.js | 671.522 | 109.651 | |libs.js | 647.614 | 508.324 | |polyfills.js | 325.834 | 0 | -|TOTAL js |7.960.367 |5.105.283 | +|TOTAL js |7.960.367 |5.097.142 | |js/min/* |1.14.0 |native | |----------- |--------: |--------: | |admin.js | 252.147 | 177.094 | -|app.js | 511.202 | 409.778 | +|app.js | 511.202 | 409.173 | |boot.js | 66.007 | 13.380 | |libs.js | 572.545 | 465.247 | |polyfills.js | 32.452 | 0 | -|TOTAL js/min |1.434.353 |1.065.499 | +|TOTAL js/min |1.434.353 |1.064.753 | -368.854 bytes is not much, but it feels faster. +369.600 bytes is not much, but it feels faster. ### PHP73 branch diff --git a/dev/App/Abstract.js b/dev/App/Abstract.js index 1978b3ab8..b61b7ef3f 100644 --- a/dev/App/Abstract.js +++ b/dev/App/Abstract.js @@ -122,7 +122,7 @@ class AbstractApp extends AbstractBoot { * @param {string} title */ setWindowTitle(title) { - title = isNormal(title) && 0 < title.length ? '' + title : ''; + title = isNormal(title) && title.length ? '' + title : ''; if (Settings.settingsGet('Title')) { title += (title ? ' - ' : '') + Settings.settingsGet('Title'); } diff --git a/dev/App/User.js b/dev/App/User.js index b93759afc..b375629a9 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -346,7 +346,7 @@ class AppUser extends AbstractApp { } } - this.reloadMessageList(0 === MessageStore.messageList().length); + this.reloadMessageList(!MessageStore.messageList().length); this.quotaDebounce(); } } @@ -427,7 +427,7 @@ class AppUser extends AbstractApp { * @param {boolean=} bCopy = false */ moveMessagesToFolder(sFromFolderFullNameRaw, aUidForMove, sToFolderFullNameRaw, bCopy) { - if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && isArray(aUidForMove) && 0 < aUidForMove.length) { + if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && isArray(aUidForMove) && aUidForMove.length) { const oFromFolder = getFolderFromCacheList(sFromFolderFullNameRaw), oToFolder = getFolderFromCacheList(sToFolderFullNameRaw); @@ -823,7 +823,7 @@ class AppUser extends AbstractApp { rootUids = messages.map(oMessage => oMessage && oMessage.uid ? oMessage.uid : null) .filter((value, index, self) => !!value && self.indexOf(value) == index); - if ('' !== sFolderFullNameRaw && 0 < rootUids.length) { + if ('' !== sFolderFullNameRaw && rootUids.length) { switch (iSetAction) { case MessageSetAction.SetSeen: rootUids.forEach(sSubUid => { @@ -1001,7 +1001,7 @@ class AppUser extends AbstractApp { this.loginAndLogoutReload( false, true, - Settings.settingsGet('ParentEmail') && 0 < Settings.settingsGet('ParentEmail').length + 0 < (Settings.settingsGet('ParentEmail')||{length:0}).length ); }); } diff --git a/dev/Common/Cache.js b/dev/Common/Cache.js index a9b6e7256..6702b6d4e 100644 --- a/dev/Common/Cache.js +++ b/dev/Common/Cache.js @@ -209,7 +209,7 @@ export function initMessageFlagsFromCache(message) { const uid = message.uid, flags = getMessageFlagsFromCache(message.folderFullNameRaw, uid); - if (flags && 0 < flags.length) { + if (flags && flags.length) { message.flagged(!!flags[1]); if (!message.isSimpleMessage) { @@ -221,11 +221,11 @@ export function initMessageFlagsFromCache(message) { } } - if (0 < message.threads().length) { + if (message.threads().length) { const unseenSubUid = message.threads().find(sSubUid => { if (uid !== sSubUid) { const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid); - return subFlags && 0 < subFlags.length && !!subFlags[0]; + return subFlags && subFlags.length && !!subFlags[0]; } return false; }); @@ -233,7 +233,7 @@ export function initMessageFlagsFromCache(message) { const flaggedSubUid = message.threads().find(sSubUid => { if (uid !== sSubUid) { const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid); - return subFlags && 0 < subFlags.length && !!subFlags[1]; + return subFlags && subFlags.length && !!subFlags[1]; } return false; }); @@ -266,7 +266,7 @@ export function storeMessageFlagsToCache(message) { * @param {Array} flags */ export function storeMessageFlagsToCacheByFolderAndUid(folder, uid, flags) { - if (isArray(flags) && 0 < flags.length) { + if (isArray(flags) && flags.length) { setMessageFlagsToCache(folder, uid, flags); } } @@ -280,7 +280,7 @@ export function storeMessageFlagsToCacheBySetAction(folder, uid, setAction) { let unread = 0; const flags = getMessageFlagsFromCache(folder, uid); - if (isArray(flags) && 0 < flags.length) { + if (isArray(flags) && flags.length) { if (flags[0]) { unread = 1; } diff --git a/dev/Common/Selector.js b/dev/Common/Selector.js index c972f5142..9c8828493 100644 --- a/dev/Common/Selector.js +++ b/dev/Common/Selector.js @@ -59,7 +59,7 @@ class Selector { this.itemSelectedThrottle = _.debounce(this.itemSelected.bind(this), 300); this.listChecked.subscribe((items) => { - if (0 < items.length) { + if (items.length) { if (null === this.selectedItem()) { if (this.selectedItem.valueHasMutated) { this.selectedItem.valueHasMutated(); @@ -177,7 +177,7 @@ class Selector { if (!isChecked && !isSelected && this.autoSelect()) { if (this.focusedItem()) { this.selectedItem(this.focusedItem()); - } else if (0 < aItems.length) { + } else if (aItems.length) { if (null !== isNextFocused) { getNext = false; isNextFocused = aCache.find(sUid => { @@ -201,7 +201,7 @@ class Selector { if ( (0 !== this.iSelectNextHelper || 0 !== this.iFocusedNextHelper) && - 0 < aItems.length && + aItems.length && !this.focusedItem() ) { temp = null; diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index c2d74b982..da8b41e19 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -101,7 +101,7 @@ export function boolToAjax(value) { * @returns {boolean} */ export function isNonEmptyArray(values) { - return isArray(values) && 0 < values.length; + return isArray(values) && values.length; } /** @@ -141,17 +141,13 @@ export function encodeURI(url) { * @returns {Object} */ export function simpleQueryParser(queryString) { - let index = 0, - len = 0, - temp = null; - const queries = queryString.split('&'), params = {}; - for (len = queries.length; index < len; index++) { - temp = queries[index].split('='); + queries.forEach(temp => { + temp = temp.split('='); params[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]); - } + }); return params; } @@ -707,7 +703,7 @@ export function htmlToPlain(html) { const convertDivs = (...args) => { if (args && 1 < args.length) { let divText = trim(args[1]); - if (0 < divText.length) { + if (divText.length) { divText = divText.replace(/]*>([\s\S\r\n]*)<\/div>/gim, convertDivs); divText = '\n' + trim(divText) + '\n'; } @@ -805,15 +801,12 @@ export function plainToHtml(plain, findEmailAndLinksInText = false) { bDo = true, bStart = true, aNextText = [], - sLine = '', - iIndex = 0, aText = plain.split('\n'); do { bDo = false; aNextText = []; - for (iIndex = 0; iIndex < aText.length; iIndex++) { - sLine = aText[iIndex]; + aText.forEach(sLine => { bStart = '>' === sLine.substr(0, 1); if (bStart && !bIn) { bDo = true; @@ -833,7 +826,7 @@ export function plainToHtml(plain, findEmailAndLinksInText = false) { } else { aNextText.push(sLine); } - } + }); if (bIn) { bIn = false; @@ -888,10 +881,7 @@ export function folderListOptionsBuilder( let /** * @type {?FolderModel} */ - oItem = null, bSep = false, - iIndex = 0, - iLen = 0, aResult = []; const sDeepPrefix = '\u00A0\u00A0\u00A0'; @@ -911,21 +901,20 @@ export function folderListOptionsBuilder( aHeaderLines = []; } - for (iIndex = 0, iLen = aHeaderLines.length; iIndex < iLen; iIndex++) { + aHeaderLines.forEach(line => { aResult.push({ - id: aHeaderLines[iIndex][0], - name: aHeaderLines[iIndex][1], + id: line[0], + name: line[1], system: false, seporator: false, disabled: false }); - } + }); bSep = true; - for (iIndex = 0, iLen = aSystem.length; iIndex < iLen; iIndex++) { - oItem = aSystem[iIndex]; + aSystem.forEach(oItem => { if (fVisibleCallback ? fVisibleCallback(oItem) : true) { - if (bSep && 0 < aResult.length) { + if (bSep && aResult.length) { aResult.push({ id: '---', name: '---', @@ -947,11 +936,10 @@ export function folderListOptionsBuilder( (fDisableCallback ? fDisableCallback(oItem) : false) }); } - } + }); bSep = true; - for (iIndex = 0, iLen = aList.length; iIndex < iLen; iIndex++) { - oItem = aList[iIndex]; + aList.forEach(oItem => { // if (oItem.subScribed() || !oItem.existen || bBuildUnvisible) if ( (oItem.subScribed() || !oItem.existen || bBuildUnvisible) && @@ -959,7 +947,7 @@ export function folderListOptionsBuilder( ) { if (fVisibleCallback ? fVisibleCallback(oItem) : true) { if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubScribedSubfolders()) { - if (bSep && 0 < aResult.length) { + if (bSep && aResult.length) { aResult.push({ id: '---', name: '---', @@ -986,7 +974,7 @@ export function folderListOptionsBuilder( } } - if (oItem.subScribed() && 0 < oItem.subFolders().length) { + if (oItem.subScribed() && oItem.subFolders().length) { aResult = aResult.concat( folderListOptionsBuilder( [], @@ -1002,7 +990,7 @@ export function folderListOptionsBuilder( ) ); } - } + }); return aResult; } @@ -1304,7 +1292,7 @@ export function mimeContentType(fileName) { } ext = getFileExtension(fileName); - if (ext && 0 < ext.length && !isUnd(Mime[ext])) { + if (ext && ext.length && !isUnd(Mime[ext])) { result = Mime[ext]; } diff --git a/dev/External/ko.js b/dev/External/ko.js index b40133f8b..bafadcb55 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -951,7 +951,7 @@ ko.extenders.limitedList = (target, limitedList) => { const currentValue = ko.unwrap(target), list = ko.unwrap(limitedList); - if (Array.isArray(list) && 0 < list.length) { + if (Array.isArray(list) && list.length) { if (list.includes(newValue)) { target(newValue); } else if (list.includes(currentValue, list)) { diff --git a/dev/Helper/Message.js b/dev/Helper/Message.js index 0c1f6dead..d6269493f 100644 --- a/dev/Helper/Message.js +++ b/dev/Helper/Message.js @@ -8,14 +8,9 @@ import { EmailModel } from 'Model/Email'; * @returns {string} */ export function emailArrayToString(emails, friendlyView = false, wrapWithLink = false) { - let index = 0, - len = 0; - const result = []; if (isNonEmptyArray(emails)) { - for (len = emails.length; index < len; index++) { - result.push(emails[index].toLine(friendlyView, wrapWithLink)); - } + emails.forEach(email => result.push(email.toLine(friendlyView, wrapWithLink))); } return result.join(', '); @@ -26,16 +21,13 @@ export function emailArrayToString(emails, friendlyView = false, wrapWithLink = * @returns {string} */ export function emailArrayToStringClear(emails) { - let index = 0, - len = 0; - const result = []; if (isNonEmptyArray(emails)) { - for (len = emails.length; index < len; index++) { - if (emails[index] && emails[index].email && '' !== emails[index].name) { - result.push(emails[index].email); + emails.forEach(email => { + if (email && email.email && '' !== email.name) { + result.push(email.email); } - } + }); } return result.join(', '); @@ -46,18 +38,14 @@ export function emailArrayToStringClear(emails) { * @returns {Array.} */ export function emailArrayFromJson(json) { - let index = 0, - len = 0, - email = null; - const result = []; if (isNonEmptyArray(json)) { - for (index = 0, len = json.length; index < len; index++) { - email = EmailModel.newInstanceFromJson(json[index]); + json.forEach(email => { + email = EmailModel.newInstanceFromJson(email); if (email) { result.push(email); } - } + }); } return result; @@ -69,15 +57,12 @@ export function emailArrayFromJson(json) { * @param {Array} localEmails */ export function replyHelper(inputEmails, unic, localEmails) { - if (inputEmails && 0 < inputEmails.length) { - let index = 0; - const len = inputEmails.length; - - for (; index < len; index++) { - if (isUnd(unic[inputEmails[index].email])) { - unic[inputEmails[index].email] = true; - localEmails.push(inputEmails[index]); + if (inputEmails) { + inputEmails.forEach(email => { + if (isUnd(unic[email.email])) { + unic[email.email] = true; + localEmails.push(email); } - } + }); } } diff --git a/dev/Model/Filter.js b/dev/Model/Filter.js index 253228d64..0c483e3da 100644 --- a/dev/Model/Filter.js +++ b/dev/Model/Filter.js @@ -144,7 +144,7 @@ class FilterModel extends AbstractModel { return false; } - if (0 < this.conditions().length) { + if (this.conditions().length) { if (this.conditions().find(cond => cond && !cond.verify())) { return false; } diff --git a/dev/Model/Folder.js b/dev/Model/Folder.js index 33b63634f..b7b40e423 100644 --- a/dev/Model/Folder.js +++ b/dev/Model/Folder.js @@ -137,7 +137,7 @@ class FolderModel extends AbstractModel { this.canBeDeleted = ko.computed(() => { const bSystem = this.isSystemFolder(); - return !bSystem && 0 === this.subFolders().length && inboxFolderName !== this.fullNameRaw; + return !bSystem && !this.subFolders().length && inboxFolderName !== this.fullNameRaw; }); this.canBeSubScribed = ko.computed( diff --git a/dev/Model/Message.js b/dev/Model/Message.js index 72215cdb5..403346fe9 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -354,7 +354,6 @@ class MessageModel extends AbstractModel { if (attachment) { if ( '' !== attachment.cidWithOutTags && - 0 < this.foundedCIDs.length && this.foundedCIDs.includes(attachment.cidWithOutTags) ) { attachment.isLinked = true; @@ -372,14 +371,14 @@ class MessageModel extends AbstractModel { * @returns {boolean} */ hasUnsubsribeLinks() { - return this.unsubsribeLinks && 0 < this.unsubsribeLinks.length; + return this.unsubsribeLinks && this.unsubsribeLinks.length; } /** * @returns {string} */ getFirstUnsubsribeLink() { - return this.unsubsribeLinks && 0 < this.unsubsribeLinks.length ? this.unsubsribeLinks[0] || '' : ''; + return this.unsubsribeLinks && this.unsubsribeLinks.length ? this.unsubsribeLinks[0] || '' : ''; } /** @@ -573,11 +572,11 @@ class MessageModel extends AbstractModel { unic = isUnd(excludeEmails) ? {} : excludeEmails; replyHelper(this.replyTo, unic, result); - if (0 === result.length) { + if (!result.length) { replyHelper(this.from, unic, result); } - if (0 === result.length && !last) { + if (!result.length && !last) { return this.replyEmails({}, true); } @@ -596,14 +595,14 @@ class MessageModel extends AbstractModel { unic = isUnd(excludeEmails) ? {} : excludeEmails; replyHelper(this.replyTo, unic, toResult); - if (0 === toResult.length) { + if (!toResult.length) { replyHelper(this.from, unic, toResult); } replyHelper(this.to, unic, toResult); replyHelper(this.cc, unic, ccResult); - if (0 === toResult.length && !last) { + if (!toResult.length && !last) { data = this.replyAllEmails({}, true); return [data[0], ccResult]; } @@ -623,7 +622,7 @@ class MessageModel extends AbstractModel { */ attachmentsToStringLine() { const attachLines = this.attachments().map(item => item.fileName + ' (' + item.friendlySize + ')'); - return attachLines && 0 < attachLines.length ? attachLines.join(', ') : ''; + return attachLines && attachLines.length ? attachLines.join(', ') : ''; } /** diff --git a/dev/Remote/User/Ajax.js b/dev/Remote/User/Ajax.js index 7233f65ba..816af3fbf 100644 --- a/dev/Remote/User/Ajax.js +++ b/dev/Remote/User/Ajax.js @@ -449,14 +449,14 @@ class RemoteUserAjax extends AbstractAjaxRemote { let request = true; const uids = []; - if (isArray(list) && 0 < list.length) { + if (isArray(list) && list.length) { request = false; list.forEach(messageListItem => { if (!getMessageFlagsFromCache(messageListItem.folderFullNameRaw, messageListItem.uid)) { uids.push(messageListItem.uid); } - if (0 < messageListItem.threads().length) { + if (messageListItem.threads().length) { messageListItem.threads().forEach(uid => { if (!getMessageFlagsFromCache(messageListItem.folderFullNameRaw, uid)) { uids.push(uid); @@ -465,7 +465,7 @@ class RemoteUserAjax extends AbstractAjaxRemote { } }); - if (0 < uids.length) { + if (uids.length) { request = true; } } diff --git a/dev/Settings/Admin/Contacts.js b/dev/Settings/Admin/Contacts.js index 339ff5a82..8cb42cf55 100644 --- a/dev/Settings/Admin/Contacts.js +++ b/dev/Settings/Admin/Contacts.js @@ -67,7 +67,7 @@ class ContactsAdminSettings { if (value !== this.contactsType()) { if (supportedTypes.includes(value)) { this.contactsType(value); - } else if (0 < supportedTypes.length) { + } else if (supportedTypes.length) { this.contactsType(''); } } else { diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index 26d2b1d80..4429fd435 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -72,7 +72,7 @@ class FolderUserStore { trashFolder = this.trashFolder(), archiveFolder = this.archiveFolder(); - if (isArray(folders) && 0 < folders.length) { + if (isArray(folders) && folders.length) { if ('' !== sentFolder && UNUSED_OPTION_VALUE !== sentFolder) { list.push(sentFolder); } @@ -174,7 +174,7 @@ class FolderUserStore { timeouts.push([folder.interval, folder.fullNameRaw]); } - if (folder && 0 < folder.subFolders().length) { + if (folder && folder.subFolders().length) { fSearchFunction(folder.subFolders()); } }); diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 13525b846..bef605d7c 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -249,7 +249,7 @@ class MessageUserStore { initUidNextAndNewMessages(folder, uidNext, newMessages) { if (getFolderInboxName() === folder && isNormal(uidNext) && '' !== uidNext) { - if (isArray(newMessages) && 0 < newMessages.length) { + if (isArray(newMessages) && newMessages.length) { newMessages.forEach(item => { addNewMessageCache(folder, item.Uid); }); @@ -343,7 +343,7 @@ class MessageUserStore { toFolder.actionBlink(true); } - if (0 < messages.length) { + if (messages.length) { if (copy) { messages.forEach(item => { item.checked(false); @@ -381,7 +381,7 @@ class MessageUserStore { if ( messageList && - 0 < messageList.length && + messageList.length && !!messageList.find(item => !!(item && item.deleted() && item.uid === this.messageListThreadUid())) ) { const message = messageList.find(item => item && !item.deleted()); @@ -436,15 +436,10 @@ class MessageUserStore { initBlockquoteSwitcher(messageTextBody) { if (messageTextBody) { const $oList = $('blockquote:not(.rl-bq-switcher)', messageTextBody).filter(function() { - return ( - 0 === - $(this) - .parent() - .closest('blockquote', messageTextBody).length - ); // eslint-disable-line no-invalid-this + return !$(this).parent().closest('blockquote', messageTextBody).length; }); - if ($oList && 0 < $oList.length) { + if ($oList && $oList.length) { $oList.each(function() { const $this = $(this); // eslint-disable-line no-invalid-this diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 5b98feade..d7012f167 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -63,7 +63,7 @@ class PgpUserStore { }).flat().filter(value => !!value) : []; - if (0 === result.length && isNonEmptyArray(recipients)) { + if (!result.length && isNonEmptyArray(recipients)) { result = recipients.map(sEmail => { const keys = sEmail ? this.findAllPrivateKeysByEmailNotNative(sEmail) : null; return keys @@ -143,7 +143,7 @@ class PgpUserStore { decryptMessage(message, recipients, fCallback) { if (message && message.getEncryptionKeyIds) { const privateKeys = this.findPrivateKeysByEncryptionKeyIds(message.getEncryptionKeyIds(), recipients, true); - if (privateKeys && 0 < privateKeys.length) { + if (privateKeys && privateKeys.length) { showScreenPopup(require('View/Popup/MessageOpenPgp'), [ (decryptedKey) => { if (decryptedKey) { @@ -186,9 +186,9 @@ class PgpUserStore { verifyMessage(message, fCallback) { if (message && message.getSigningKeyIds) { const signingKeyIds = message.getSigningKeyIds(); - if (signingKeyIds && 0 < signingKeyIds.length) { + if (signingKeyIds && signingKeyIds.length) { const publicKeys = this.findPublicKeysBySigningKeyIds(signingKeyIds); - if (publicKeys && 0 < publicKeys.length) { + if (publicKeys && publicKeys.length) { try { const result = message.verify(publicKeys), valid = (_.isArray(result) ? result : []).find(item => item && item.valid && item.keyid); diff --git a/dev/Stores/User/Template.js b/dev/Stores/User/Template.js index 307741ce0..2522a2f67 100644 --- a/dev/Stores/User/Template.js +++ b/dev/Stores/User/Template.js @@ -23,7 +23,7 @@ class TemplateUserStore { // { // this.templatesNames.skipFirst = false; // } - // else if (aList && 1 < aList.length) + // else if (aList && aList.length) // { // Remote.templatesSortOrder(null, aList); // } diff --git a/dev/View/Popup/AdvancedSearch.js b/dev/View/Popup/AdvancedSearch.js index f161c0b49..788a5e9f8 100644 --- a/dev/View/Popup/AdvancedSearch.js +++ b/dev/View/Popup/AdvancedSearch.js @@ -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(',')); } diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 0a23fd56d..02c7f2217 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -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 ? '
' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') + + (sCc.length ? '
' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') + '
' + 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()) ); diff --git a/dev/View/Popup/ComposeOpenPgp.js b/dev/View/Popup/ComposeOpenPgp.js index 58f0eb4a0..91b9d6a93 100644 --- a/dev/View/Popup/ComposeOpenPgp.js +++ b/dev/View/Popup/ComposeOpenPgp.js @@ -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); } } diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index b32608f80..0f39dd410 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -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(); diff --git a/dev/View/Popup/Identity.js b/dev/View/Popup/Identity.js index 61748f1d7..fe22d5b46 100644 --- a/dev/View/Popup/Identity.js +++ b/dev/View/Popup/Identity.js @@ -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); } }); diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index 9c980349d..3d113842f 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -163,9 +163,8 @@ class MessageListMailBoxUserView extends AbstractViewNext { }); this.isIncompleteChecked = ko.computed(() => { - const m = MessageStore.messageList().length, - c = MessageStore.messageListChecked().length; - return 0 < m && 0 < c && m > c; + const c = MessageStore.messageListChecked().length; + return c && MessageStore.messageList().length > c; }); this.hasMessages = ko.computed(() => 0 < this.messageList().length); @@ -209,13 +208,11 @@ class MessageListMailBoxUserView extends AbstractViewNext { ); this.mobileCheckedStateShow = ko.computed(() => { - const checked = 0 < this.messageListChecked().length; - return this.mobile ? checked : true; + return this.mobile ? 0 < this.messageListChecked().length : true; }); this.mobileCheckedStateHide = ko.computed(() => { - const checked = 0 < this.messageListChecked().length; - return this.mobile ? !checked : true; + return this.mobile ? !this.messageListChecked().length : true; }); this.messageListFocused = ko.computed(() => Focused.MessageList === AppStore.focusedState()); @@ -399,7 +396,7 @@ class MessageListMailBoxUserView extends AbstractViewNext { } goToUpUpOrDownDown(up) { - if (0 < this.messageListChecked().length) { + if (this.messageListChecked().length) { return false; } @@ -652,7 +649,7 @@ class MessageListMailBoxUserView extends AbstractViewNext { const checked = this.messageListCheckedOrSelected(); if (currentMessage) { const checkedUids = checked.map(message => message.uid); - if (0 < checkedUids.length && checkedUids.includes(currentMessage.uid)) { + if (checkedUids.includes(currentMessage.uid)) { this.setAction( currentMessage.folderFullNameRaw, currentMessage.flagged() ? MessageSetAction.UnsetFlag : MessageSetAction.SetFlag, @@ -670,7 +667,7 @@ class MessageListMailBoxUserView extends AbstractViewNext { flagMessagesFast(bFlag) { const checked = this.messageListCheckedOrSelected(); - if (0 < checked.length) { + if (checked.length) { if (isUnd(bFlag)) { const flagged = checked.filter(message => message.flagged()); this.setAction( @@ -690,12 +687,12 @@ class MessageListMailBoxUserView extends AbstractViewNext { seenMessagesFast(seen) { const checked = this.messageListCheckedOrSelected(); - if (0 < checked.length) { + if (checked.length) { if (isUnd(seen)) { const unseen = checked.filter(message => message.unseen()); this.setAction( checked[0].folderFullNameRaw, - 0 < unseen.length ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen, + unseen.length ? MessageSetAction.SetSeen : MessageSetAction.UnsetSeen, checked ); } else { @@ -734,7 +731,7 @@ class MessageListMailBoxUserView extends AbstractViewNext { '' === this.messageListSearchDesc() && '' === this.messageListError() && '' === this.messageListEndThreadUid() && - 0 < this.messageList().length && + this.messageList().length && (this.isSpamFolder() || this.isTrashFolder()) ); } @@ -811,7 +808,7 @@ class MessageListMailBoxUserView extends AbstractViewNext { // delete key('delete, shift+delete, shift+3', KeyState.MessageList, (event, handler) => { if (event) { - if (0 < MessageStore.messageListCheckedOrSelected().length) { + if (MessageStore.messageListCheckedOrSelected().length) { if (handler && 'shift+delete' === handler.shortcut) { this.deleteWithoutMoveCommand(); } else { diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 2861aeef2..4379ee5a3 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -130,7 +130,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext { }; this.allowAttachmnetControls = ko.computed( - () => 0 < this.attachmentsActions().length && Settings.capa(Capa.AttachmentsActions) + () => this.attachmentsActions().length && Settings.capa(Capa.AttachmentsActions) ); this.downloadAsZipAllowed = ko.computed( @@ -496,7 +496,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext { return null; }).filter(value => !!value); - if (0 < dynamicEls.length) { + if (dynamicEls.length) { div.on('onBeforeOpen.lg', () => { useKeyboardShortcuts(false); removeInFocus(true); @@ -888,7 +888,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext { downloadAsZip() { const hashes = this.getAttachmentsHashes(); - if (0 < hashes.length) { + if (hashes.length) { Promises.attachmentsActions('Zip', hashes, this.downloadAsZipLoading) .then((result) => { if (result && result.Result && result.Result.Files && result.Result.Files[0] && result.Result.Files[0].Hash) {