diff --git a/dev/App/User.js b/dev/App/User.js index aad9d98aa..48b0db5ea 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -1,6 +1,6 @@ import 'External/User/ko'; -import { pInt, pString } from 'Common/Utils'; +import { isArray, isNonEmptyArray, pInt, pString } from 'Common/Utils'; import { isPosNumeric, delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser'; import { @@ -275,7 +275,7 @@ class AppUser extends AbstractApp { moveOrDeleteResponseHelper(iError, oData) { if (!iError && FolderUserStore.currentFolder()) { - if (oData && Array.isArray(oData.Result) && 2 === oData.Result.length) { + if (oData && isArray(oData.Result) && 2 === oData.Result.length) { setFolderHash(oData.Result[0], oData.Result[1]); } else { setFolderHash(FolderUserStore.currentFolderFullNameRaw(), ''); @@ -367,7 +367,7 @@ class AppUser extends AbstractApp { * @param {boolean=} bCopy = false */ moveMessagesToFolder(sFromFolderFullNameRaw, aUidForMove, sToFolderFullNameRaw, bCopy) { - if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && Array.isArray(aUidForMove) && aUidForMove.length) { + if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && isArray(aUidForMove) && aUidForMove.length) { const oFromFolder = getFolderFromCacheList(sFromFolderFullNameRaw), oToFolder = getFolderFromCacheList(sToFolderFullNameRaw); @@ -479,7 +479,7 @@ class AppUser extends AbstractApp { sAccountEmail = AccountUserStore.email(); let parentEmail = SettingsGet('ParentEmail') || sAccountEmail; - if (Array.isArray(oData.Result.Accounts)) { + if (isArray(oData.Result.Accounts)) { AccountUserStore.accounts.forEach(oAccount => counts[oAccount.email] = oAccount.count() ); @@ -493,7 +493,7 @@ class AppUser extends AbstractApp { ); } - if (Array.isArray(oData.Result.Identities)) { + if (isArray(oData.Result.Identities)) { delegateRunOnDestroy(IdentityUserStore()); IdentityUserStore( @@ -522,7 +522,7 @@ class AppUser extends AbstractApp { Remote.templates((iError, data) => { TemplateUserStore.templates.loading(false); - if (!iError && data.Result && Array.isArray(data.Result.Templates)) { + if (!iError && data.Result && isArray(data.Result.Templates)) { delegateRunOnDestroy(TemplateUserStore.templates()); TemplateUserStore.templates( @@ -540,7 +540,7 @@ class AppUser extends AbstractApp { !iError && data && data.Result && - Array.isArray(data.Result) && + isArray(data.Result) && 1 < data.Result.length && isPosNumeric(data.Result[0], true) && isPosNumeric(data.Result[1], true) @@ -635,9 +635,9 @@ class AppUser extends AbstractApp { */ folderInformationMultiply(boot = false) { const folders = FolderUserStore.getNextFolderNames(); - if (Array.isNotEmpty(folders)) { + if (isNonEmptyArray(folders)) { Remote.folderInformationMultiply((iError, oData) => { - if (!iError && oData && oData.Result && oData.Result.List && Array.isNotEmpty(oData.Result.List)) { + if (!iError && oData && oData.Result && oData.Result.List && isNonEmptyArray(oData.Result.List)) { const utc = Date.now(); oData.Result.List.forEach(item => { const hash = getFolderHash(item.Folder), @@ -760,7 +760,7 @@ class AppUser extends AbstractApp { */ getAutocomplete(query, autocompleteCallback) { Remote.suggestions((iError, data) => { - if (!iError && data && Array.isArray(data.Result)) { + if (!iError && data && isArray(data.Result)) { autocompleteCallback( data.Result.map(item => (item && item[0] ? new EmailModel(item[0], item[1]) : null)).filter(v => v) ); @@ -776,7 +776,7 @@ class AppUser extends AbstractApp { */ setExpandedFolder(sFullNameHash, bExpanded) { let aExpandedList = Local.get(ClientSideKeyName.ExpandedFolders); - if (!Array.isArray(aExpandedList)) { + if (!isArray(aExpandedList)) { aExpandedList = []; } diff --git a/dev/Common/Cache.js b/dev/Common/Cache.js index 37017d64a..2a65a11cc 100644 --- a/dev/Common/Cache.js +++ b/dev/Common/Cache.js @@ -1,5 +1,5 @@ import { MessageSetAction } from 'Common/EnumsUser'; -import { pInt } from 'Common/Utils'; +import { isNonEmptyArray, pInt } from 'Common/Utils'; let FOLDERS_CACHE = {}, FOLDERS_NAME_CACHE = {}, @@ -255,7 +255,7 @@ export class MessageFlagsCache * @param {Array} flags */ static storeByFolderAndUid(folder, uid, flags) { - if (Array.isNotEmpty(flags)) { + if (isNonEmptyArray(flags)) { this.setFor(folder, uid, flags); } } @@ -269,7 +269,7 @@ export class MessageFlagsCache let unread = 0; const flags = this.getFor(folder, uid); - if (Array.isNotEmpty(flags)) { + if (isNonEmptyArray(flags)) { if (flags[0]) { unread = 1; } diff --git a/dev/Common/File.js b/dev/Common/File.js index 3b5701040..7469b8308 100644 --- a/dev/Common/File.js +++ b/dev/Common/File.js @@ -1,6 +1,8 @@ /* eslint key-spacing: 0 */ /* eslint quote-props: 0 */ +import { isNonEmptyArray } from 'Common/Utils'; + const cache = {}, app = 'application/', @@ -279,7 +281,7 @@ export const FileInfo = { * @returns {string} */ getCombinedIconClass: data => { - if (Array.isNotEmpty(data)) { + if (isNonEmptyArray(data)) { let icons = data .map(item => item ? FileInfo.getIconClass(FileInfo.getExtension(item[0]), item[1])[0] : '') .validUnique(); diff --git a/dev/Common/Selector.js b/dev/Common/Selector.js index c1bf55c7d..109b30135 100644 --- a/dev/Common/Selector.js +++ b/dev/Common/Selector.js @@ -1,4 +1,5 @@ import ko from 'ko'; +import { isArray } from 'Common/Utils'; export class Selector { /** @@ -79,7 +80,7 @@ export class Selector { this.list.subscribe( items => { - if (Array.isArray(items)) { + if (isArray(items)) { items.forEach(item => { if (item) { const uid = this.getItemUid(item); @@ -115,7 +116,7 @@ export class Selector { this.focusedItem(null); this.selectedItem(null); - if (Array.isArray(aItems)) { + if (isArray(aItems)) { len = aCheckedCache.length; aItems.forEach(item => { diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index 0d089cbfa..230be3ddd 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -3,7 +3,7 @@ import { doc, elementById } from 'Common/Globals'; export const isArray = Array.isArray, - isNonEmptyArray = Array.isNotEmpty; + isNonEmptyArray = array => isArray(array) && array.length; /** * @param {*} value @@ -116,7 +116,7 @@ export function changeTheme(value, themeTrigger = ()=>{}) { } rl.fetchJSON(url, init) .then(data => { - if (data && Array.isArray(data) && 2 === data.length) { + if (data && isArray(data) && 2 === data.length) { if (themeLink && !themeStyle) { themeStyle = doc.createElement('style'); themeStyle.id = 'app-theme-style'; @@ -139,7 +139,7 @@ export function changeTheme(value, themeTrigger = ()=>{}) { export function addObservablesTo(target, observables) { Object.entries(observables).forEach(([key, value]) => - target[key] = /*Array.isArray(value) ? ko.observableArray(value) :*/ ko.observable(value) ); + target[key] = /*isArray(value) ? ko.observableArray(value) :*/ ko.observable(value) ); } export function addComputablesTo(target, computables) { diff --git a/dev/Component/EmailAddresses.js b/dev/Component/EmailAddresses.js index ca9fbb7f4..ac7813361 100644 --- a/dev/Component/EmailAddresses.js +++ b/dev/Component/EmailAddresses.js @@ -1,4 +1,5 @@ import { doc, createElement } from 'Common/Globals'; +import { isArray } from 'Common/Utils'; import { EmailModel } from 'Model/Email'; const contentType = 'snappymail/emailaddress', @@ -204,7 +205,7 @@ export class EmailAddressesComponent { _setChosen(valArr) { var self = this; - if (!Array.isArray(valArr)){ + if (!isArray(valArr)){ return false; } diff --git a/dev/External/User/ko.js b/dev/External/User/ko.js index c3cbb4206..97b98bb8c 100644 --- a/dev/External/User/ko.js +++ b/dev/External/User/ko.js @@ -3,6 +3,7 @@ import ko from 'ko'; import { HtmlEditor } from 'Common/Html'; import { timeToNode } from 'Common/Momentor'; import { elementById } from 'Common/Globals'; +import { isArray } from 'Common/Utils'; import { EmailAddressesComponent } from 'Component/EmailAddresses'; import { ThemeStore } from 'Stores/Theme'; @@ -144,7 +145,7 @@ ko.bindingHandlers.dropmessages = { fnStop(e); if ('messages' === getDragAction(e) && ['move','copy'].includes(e.dataTransfer.effectAllowed)) { let data = dragData.data; - if (folder && data && data.folder && Array.isArray(data.uids)) { + if (folder && data && data.folder && isArray(data.uids)) { rl.app.moveMessagesToFolder(data.folder, data.uids, folder.fullNameRaw, data.copy && e.ctrlKey); } } diff --git a/dev/External/ko.js b/dev/External/ko.js index 8393b953d..9354e27a1 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -1,6 +1,7 @@ import { i18n, i18nToNodes, trigger } from 'Common/Translator'; import { doc, createElement } from 'Common/Globals'; import { SaveSettingsStep } from 'Common/Enums'; +import { isNonEmptyArray } from 'Common/Utils'; const isFunction = v => typeof v === 'function', @@ -146,7 +147,7 @@ ko.extenders.limitedList = (target, limitedList) => { const currentValue = ko.unwrap(target), list = ko.unwrap(limitedList); - if (Array.isNotEmpty(list)) { + if (isNonEmptyArray(list)) { if (list.includes(newValue)) { target(newValue); } else if (list.includes(currentValue, list)) { diff --git a/dev/Knoin/AbstractModel.js b/dev/Knoin/AbstractModel.js index dae0fc1bb..5738f4908 100644 --- a/dev/Knoin/AbstractModel.js +++ b/dev/Knoin/AbstractModel.js @@ -1,4 +1,4 @@ -import { addObservablesTo, addComputablesTo } from 'Common/Utils'; +import { isArray, addObservablesTo, addComputablesTo } from 'Common/Utils'; function dispose(disposable) { if (disposable && 'function' === typeof disposable.dispose) { @@ -16,7 +16,7 @@ function typeCast(curValue, newValue) { if (curValue.constructor.reviveFromJson) { return curValue.constructor.reviveFromJson(newValue); } - if (Array.isArray(curValue) && !Array.isArray(newValue)) + if (isArray(curValue) && !isArray(newValue)) return []; } return newValue; diff --git a/dev/Knoin/AbstractScreen.js b/dev/Knoin/AbstractScreen.js index dc07bff77..77a781447 100644 --- a/dev/Knoin/AbstractScreen.js +++ b/dev/Knoin/AbstractScreen.js @@ -1,8 +1,10 @@ +import { isArray, isNonEmptyArray } from 'Common/Utils'; + export class AbstractScreen { constructor(screenName, viewModels = []) { this.oCross = null; this.sScreenName = screenName; - this.aViewModels = Array.isArray(viewModels) ? viewModels : []; + this.aViewModels = isArray(viewModels) ? viewModels : []; } /** @@ -40,7 +42,7 @@ export class AbstractScreen { if (!this.__started) { this.__started = true; const routes = this.routes(); - if (Array.isNotEmpty(routes)) { + if (isNonEmptyArray(routes)) { let route = new Crossroads(), fMatcher = (this.onRoute || (()=>{})).bind(this); diff --git a/dev/Model/AbstractCollection.js b/dev/Model/AbstractCollection.js index c44425faa..9ec8c08bf 100644 --- a/dev/Model/AbstractCollection.js +++ b/dev/Model/AbstractCollection.js @@ -1,3 +1,4 @@ +import { isArray } from 'Common/Utils'; export class AbstractCollectionModel extends Array { @@ -27,7 +28,7 @@ export class AbstractCollectionModel extends Array // json[@Count] json = json['@Collection']; } - if (Array.isArray(json)) { + if (isArray(json)) { json.forEach(item => { item && itemCallback && (item = itemCallback(item, result)); item && result.push(item); diff --git a/dev/Model/Contact.js b/dev/Model/Contact.js index 978d5f931..5bbc0de51 100644 --- a/dev/Model/Contact.js +++ b/dev/Model/Contact.js @@ -1,5 +1,5 @@ +import { isNonEmptyArray } from 'Common/Utils'; import { ContactPropertyModel, ContactPropertyType } from 'Model/ContactProperty'; - import { AbstractModel } from 'Knoin/AbstractModel'; export class ContactModel extends AbstractModel { @@ -26,7 +26,7 @@ export class ContactModel extends AbstractModel { let name = '', email = ''; - if (Array.isNotEmpty(this.properties)) { + if (isNonEmptyArray(this.properties)) { this.properties.forEach(property => { if (property) { if (ContactPropertyType.FirstName === property.type()) { @@ -52,7 +52,7 @@ export class ContactModel extends AbstractModel { const contact = super.reviveFromJson(json); if (contact) { let list = []; - if (Array.isNotEmpty(json.properties)) { + if (isNonEmptyArray(json.properties)) { json.properties.forEach(property => { property = ContactPropertyModel.reviveFromJson(property); property && list.push(property); diff --git a/dev/Model/Filter.js b/dev/Model/Filter.js index 8ab6ca988..b53656c55 100644 --- a/dev/Model/Filter.js +++ b/dev/Model/Filter.js @@ -1,6 +1,6 @@ import ko from 'ko'; -import { pString } from 'Common/Utils'; +import { isNonEmptyArray, pString } from 'Common/Utils'; import { delegateRunOnDestroy } from 'Common/UtilsUser'; import { i18n } from 'Common/Translator'; import { getFolderFromCacheList } from 'Common/Cache'; @@ -230,7 +230,7 @@ export class FilterModel extends AbstractModel { filter.conditions([]); - if (Array.isNotEmpty(json.Conditions)) { + if (isNonEmptyArray(json.Conditions)) { filter.conditions( json.Conditions.map(aData => FilterConditionModel.reviveFromJson(aData)).filter(v => v) ); diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 8b7e1eced..9ccf90013 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -1,7 +1,7 @@ import { AbstractCollectionModel } from 'Model/AbstractCollection'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; -import { pInt } from 'Common/Utils'; +import { isArray, pInt } from 'Common/Utils'; import { ClientSideKeyName, FolderType } from 'Common/EnumsUser'; import * as Cache from 'Common/Cache'; import { Settings, SettingsGet } from 'Common/Globals'; @@ -75,7 +75,7 @@ export class FolderCollectionModel extends AbstractCollectionModel if (oCacheFolder) { oCacheFolder.collapsed(!expandedFolders - || !Array.isArray(expandedFolders) + || !isArray(expandedFolders) || !expandedFolders.includes(oCacheFolder.fullNameHash)); if (oFolder.Extended) { diff --git a/dev/Model/Message.js b/dev/Model/Message.js index 7ce42faf8..8a8d4e92a 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -4,7 +4,7 @@ import { MessagePriority } from 'Common/EnumsUser'; import { i18n } from 'Common/Translator'; import { encodeHtml } from 'Common/Html'; -import { isArray } from 'Common/Utils'; +import { isArray, isNonEmptyArray } from 'Common/Utils'; import { serverRequestRaw } from 'Common/Links'; @@ -223,7 +223,7 @@ export class MessageModel extends AbstractModel { */ fromDkimData() { let result = ['none', '']; - if (Array.isNotEmpty(this.from) && 1 === this.from.length && this.from[0] && this.from[0].dkimStatus) { + if (isNonEmptyArray(this.from) && 1 === this.from.length && this.from[0] && this.from[0].dkimStatus) { result = [this.from[0].dkimStatus, this.from[0].dkimValue || '']; } diff --git a/dev/Model/OpenPgpKey.js b/dev/Model/OpenPgpKey.js index 36bebd18e..1ae0a623f 100644 --- a/dev/Model/OpenPgpKey.js +++ b/dev/Model/OpenPgpKey.js @@ -1,7 +1,7 @@ import ko from 'ko'; +import { isNonEmptyArray } from 'Common/Utils'; import { AbstractModel } from 'Knoin/AbstractModel'; - import { PgpUserStore } from 'Stores/User/Pgp'; export class OpenPgpKeyModel extends AbstractModel { @@ -21,7 +21,7 @@ export class OpenPgpKeyModel extends AbstractModel { this.index = index; this.id = ID; - this.ids = Array.isNotEmpty(IDs) ? IDs : [ID]; + this.ids = isNonEmptyArray(IDs) ? IDs : [ID]; this.guid = guID; this.user = ''; this.users = userIDs; diff --git a/dev/Model/SieveScript.js b/dev/Model/SieveScript.js index 86b9a61ef..b37bee73f 100644 --- a/dev/Model/SieveScript.js +++ b/dev/Model/SieveScript.js @@ -2,7 +2,7 @@ import ko from 'ko'; import { AbstractModel } from 'Knoin/AbstractModel'; import { FilterModel } from 'Model/Filter'; -import { pString } from 'Common/Utils'; +import { isNonEmptyArray, pString } from 'Common/Utils'; const SIEVE_FILE_NAME = 'rainloop.user'; @@ -327,7 +327,7 @@ export class SieveScriptModel extends AbstractModel if (script) { if (script.allowFilters()) { script.filters( - Array.isNotEmpty(json.filters) + isNonEmptyArray(json.filters) ? json.filters.map(aData => FilterModel.reviveFromJson(aData)).filter(v => v) : sieveScriptToFilters(script.body()) ); diff --git a/dev/Remote/AbstractFetch.js b/dev/Remote/AbstractFetch.js index f6f4b99fd..0e39f2802 100644 --- a/dev/Remote/AbstractFetch.js +++ b/dev/Remote/AbstractFetch.js @@ -1,6 +1,6 @@ import { Notification } from 'Common/Enums'; import { Settings } from 'Common/Globals'; -import { pInt, pString } from 'Common/Utils'; +import { isArray, pInt, pString } from 'Common/Utils'; import { serverRequest } from 'Common/Links'; let iJsonErrorCount = 0, @@ -169,7 +169,7 @@ export class AbstractFetchRemote setTrigger(trigger, value) { if (trigger) { value = !!value; - (Array.isArray(trigger) ? trigger : [trigger]).forEach(fTrigger => { + (isArray(trigger) ? trigger : [trigger]).forEach(fTrigger => { fTrigger && fTrigger(value); }); } diff --git a/dev/Remote/User/Fetch.js b/dev/Remote/User/Fetch.js index ec210cafe..d50441084 100644 --- a/dev/Remote/User/Fetch.js +++ b/dev/Remote/User/Fetch.js @@ -1,4 +1,4 @@ -import { pString, pInt } from 'Common/Utils'; +import { isArray, isNonEmptyArray, pString, pInt } from 'Common/Utils'; import { getFolderHash, @@ -440,7 +440,7 @@ class RemoteUserFetch extends AbstractFetchRemote { let request = true; const uids = []; - if (Array.isNotEmpty(list)) { + if (isNonEmptyArray(list)) { request = false; list.forEach(messageListItem => { if (!MessageFlagsCache.getFor(messageListItem.folder, messageListItem.uid)) { @@ -464,7 +464,7 @@ class RemoteUserFetch extends AbstractFetchRemote { if (request) { this.defaultRequest(fCallback, 'FolderInformation', { Folder: folder, - FlagsUids: Array.isArray(uids) ? uids.join(',') : '', + FlagsUids: isArray(uids) ? uids.join(',') : '', UidNext: getFolderInboxName() === folder ? getFolderUidNext(folder) : '' }); } else if (SettingsUserStore.useThreads()) { diff --git a/dev/Settings/Admin/General.js b/dev/Settings/Admin/General.js index d3aeaec89..a7df51e76 100644 --- a/dev/Settings/Admin/General.js +++ b/dev/Settings/Admin/General.js @@ -1,6 +1,7 @@ import ko from 'ko'; import { + isArray, pInt, settingsSaveHelperSimpleFunction, changeTheme, @@ -27,7 +28,7 @@ export class GeneralAdminSettings { this.languages = LanguageStore.languages; const aLanguagesAdmin = Settings.app('languagesAdmin'); - this.languagesAdmin = ko.observableArray(Array.isArray(aLanguagesAdmin) ? aLanguagesAdmin : []); + this.languagesAdmin = ko.observableArray(isArray(aLanguagesAdmin) ? aLanguagesAdmin : []); this.languageAdmin = ko .observable(SettingsGet('LanguageAdmin')) .extend({ limitedList: this.languagesAdmin }); diff --git a/dev/Settings/User/General.js b/dev/Settings/User/General.js index 17d7536fb..0a669d928 100644 --- a/dev/Settings/User/General.js +++ b/dev/Settings/User/General.js @@ -4,7 +4,7 @@ import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts'; import { SaveSettingsStep } from 'Common/Enums'; import { EditorDefaultType, Layout } from 'Common/EnumsUser'; import { SettingsGet } from 'Common/Globals'; -import { settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; +import { isArray, settingsSaveHelperSimpleFunction, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import { i18n, trigger as translatorTrigger, reload as translatorReload, convertLangName } from 'Common/Translator'; import { showScreenPopup } from 'Knoin/Knoin'; @@ -57,7 +57,7 @@ export class GeneralUserSettings { this.identityMain = ko.computed(() => { const list = this.identities(); - return Array.isArray(list) ? list.find(item => item && !item.id()) : null; + return isArray(list) ? list.find(item => item && !item.id()) : null; }); this.identityMainDesc = ko.computed(() => { diff --git a/dev/Stores/Admin/Package.js b/dev/Stores/Admin/Package.js index 3df197f24..9bfbf6cd4 100644 --- a/dev/Stores/Admin/Package.js +++ b/dev/Stores/Admin/Package.js @@ -1,4 +1,5 @@ import ko from 'ko'; +import { isArray } from 'Common/Utils'; import Remote from 'Remote/Admin/Fetch'; export const PackageAdminStore = ko.observableArray(); @@ -23,7 +24,7 @@ PackageAdminStore.fetch = () => { } }); - if (Array.isArray(data.Result.List)) { + if (isArray(data.Result.List)) { list = data.Result.List.map(item => { if (item) { item.loading = ko.observable(loading[item.file] !== undefined); diff --git a/dev/Stores/Language.js b/dev/Stores/Language.js index af09e17d9..546785e18 100644 --- a/dev/Stores/Language.js +++ b/dev/Stores/Language.js @@ -1,5 +1,6 @@ import ko from 'ko'; import { Settings, SettingsGet } from 'Common/Globals'; +import { isArray } from 'Common/Utils'; export const LanguageStore = { languages: ko.observableArray(), @@ -7,7 +8,7 @@ export const LanguageStore = { populate: function() { const aLanguages = Settings.app('languages'); - this.languages(Array.isArray(aLanguages) ? aLanguages : []); + this.languages(isArray(aLanguages) ? aLanguages : []); this.language(SettingsGet('Language')); this.userLanguage(SettingsGet('UserLanguage')); } diff --git a/dev/Stores/Theme.js b/dev/Stores/Theme.js index e0d27e03f..3a11d63c9 100644 --- a/dev/Stores/Theme.js +++ b/dev/Stores/Theme.js @@ -1,5 +1,6 @@ import ko from 'ko'; import { $htmlCL, leftPanelDisabled, Settings, SettingsGet } from 'Common/Globals'; +import { isArray } from 'Common/Utils'; export const ThemeStore = { themes: ko.observableArray(), @@ -10,7 +11,7 @@ export const ThemeStore = { populate: function(){ const themes = Settings.app('themes'); - this.themes(Array.isArray(themes) ? themes : []); + this.themes(isArray(themes) ? themes : []); this.theme(SettingsGet('Theme')); if (!this.isMobile()) { this.userBackgroundName(SettingsGet('UserBackgroundName')); diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index 6de7a0e32..144f71d54 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -3,7 +3,7 @@ import ko from 'ko'; import { Scope, Notification } from 'Common/Enums'; import { MessageSetAction } from 'Common/EnumsUser'; import { doc, elementById } from 'Common/Globals'; -import { pInt, pString, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; +import { isNonEmptyArray, pInt, pString, addObservablesTo, addSubscribablesTo } from 'Common/Utils'; import { plainToHtml } from 'Common/UtilsUser'; import { @@ -237,7 +237,7 @@ export const MessageUserStore = new class { initUidNextAndNewMessages(folder, uidNext, newMessages) { if (getFolderInboxName() === folder && uidNext) { - if (Array.isNotEmpty(newMessages)) { + if (isNonEmptyArray(newMessages)) { newMessages.forEach(item => addNewMessageCache(folder, item.Uid)); NotificationUserStore.playSoundNotification(); diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index c64547754..281e3931d 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -1,7 +1,7 @@ import ko from 'ko'; import { i18n } from 'Common/Translator'; -import { pString } from 'Common/Utils'; +import { isArray, isNonEmptyArray, pString } from 'Common/Utils'; import { doc } from 'Common/Globals'; import { AccountUserStore } from 'Stores/User/Account'; @@ -54,7 +54,7 @@ function domControlEncryptedClickHelper(store, dom, armoredMessage, recipients) decryptedMessage.getText() ); } else if (validPrivateKey) { - const keyIds = Array.isNotEmpty(signingKeyIds) ? signingKeyIds : null, + const keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null, additional = keyIds ? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ') : ''; @@ -110,7 +110,7 @@ function domControlSignedClickHelper(store, dom, armoredMessage) { message.getText() ); } else { - const keyIds = Array.isNotEmpty(signingKeyIds) ? signingKeyIds : null, + const keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null, additional = keyIds ? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ') : ''; @@ -179,14 +179,14 @@ export const PgpUserStore = new class { } findPrivateKeysByEncryptionKeyIds(encryptionKeyIds, recipients, returnWrapKeys) { - let result = Array.isArray(encryptionKeyIds) + let result = isArray(encryptionKeyIds) ? encryptionKeyIds.map(id => { const key = id && id.toHex ? this.findPrivateKeyByHex(id.toHex()) : null; return key ? (returnWrapKeys ? [key] : key.getNativeKeys()) : [null]; }).flat().filter(v => v) : []; - if (!result.length && Array.isNotEmpty(recipients)) { + if (!result.length && isNonEmptyArray(recipients)) { result = recipients.map(sEmail => { const keys = sEmail ? this.findAllPrivateKeysByEmailNotNative(sEmail) : null; return keys @@ -314,7 +314,7 @@ export const PgpUserStore = new class { if (publicKeys && publicKeys.length) { try { const result = message.verify(publicKeys), - valid = (Array.isArray(result) ? result : []).find(item => item && item.valid && item.keyid); + valid = (isArray(result) ? result : []).find(item => item && item.valid && item.keyid); if (valid && valid.keyid && valid.keyid && valid.keyid.toHex) { fCallback(this.findPublicKeyByHex(valid.keyid.toHex())); diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 060f3ad23..7a6e95bc7 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -8,7 +8,7 @@ import { import { ComposeType } from 'Common/EnumsUser'; -import { pInt } from 'Common/Utils'; +import { isNonEmptyArray, pInt } from 'Common/Utils'; import { delegateRunOnDestroy, computedPaginatorHelper, showMessageComposer } from 'Common/UtilsUser'; import { Selector } from 'Common/Selector'; @@ -164,7 +164,7 @@ class ContactsPopupView extends AbstractViewPopup { bccEmails = null; const aC = this.contactsCheckedOrSelected(); - if (Array.isNotEmpty(aC)) { + if (isNonEmptyArray(aC)) { aE = aC.map(oItem => { if (oItem) { const data = oItem.getNameAndEmailHelper(), @@ -181,7 +181,7 @@ class ContactsPopupView extends AbstractViewPopup { aE = aE.filter(value => !!value); } - if (Array.isNotEmpty(aE)) { + if (isNonEmptyArray(aE)) { this.bBackToCompose = false; hideScreenPopup(ContactsPopupView); @@ -461,7 +461,7 @@ class ContactsPopupView extends AbstractViewPopup { list = []; if (!iError && data && data.Result && data.Result.List) { - if (Array.isNotEmpty(data.Result.List)) { + if (isNonEmptyArray(data.Result.List)) { data.Result.List.forEach(item => { item = ContactModel.reviveFromJson(item); item && list.push(item); diff --git a/dev/View/Popup/Plugin.js b/dev/View/Popup/Plugin.js index 52519f9aa..283b1a102 100644 --- a/dev/View/Popup/Plugin.js +++ b/dev/View/Popup/Plugin.js @@ -2,6 +2,7 @@ import ko from 'ko'; import { Scope, Notification } from 'Common/Enums'; import { getNotification, i18n } from 'Common/Translator'; +import { isNonEmptyArray } from 'Common/Utils'; import Remote from 'Remote/Admin/Fetch'; @@ -75,7 +76,7 @@ class PluginPopupView extends AbstractViewPopup { this.readme(oPlugin.Readme); const config = oPlugin.Config; - if (Array.isNotEmpty(config)) { + if (isNonEmptyArray(config)) { this.configures( config.map(item => ({ 'value': ko.observable(item[0]), diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 005464e1a..fb22ec0b5 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -16,7 +16,7 @@ import { import { doc, $htmlCL, leftPanelDisabled, keyScopeReal, moveAction, Settings } from 'Common/Globals'; -import { inFocus } from 'Common/Utils'; +import { isNonEmptyArray, inFocus } from 'Common/Utils'; import { mailToHelper, showMessageComposer } from 'Common/UtilsUser'; import { SMAudio } from 'Common/Audio'; @@ -80,7 +80,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight { this.allowMessageListActions = Settings.capa(Capa.MessageListActions); const attachmentsActions = Settings.app('attachmentsActions'); - this.attachmentsActions = ko.observableArray(Array.isNotEmpty(attachmentsActions) ? attachmentsActions : []); + this.attachmentsActions = ko.observableArray(isNonEmptyArray(attachmentsActions) ? attachmentsActions : []); this.message = MessageUserStore.message; this.hasCheckedMessages = MessageUserStore.hasCheckedMessages; @@ -177,7 +177,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight { viewFromDkimStatusTitle:() => { const status = this.viewFromDkimData(); - if (Array.isNotEmpty(status)) { + if (isNonEmptyArray(status)) { if (status[0]) { return status[1] || 'DKIM: ' + status[0]; } diff --git a/dev/prototype.js b/dev/prototype.js index 61b71b853..1ee2c9be6 100644 --- a/dev/prototype.js +++ b/dev/prototype.js @@ -1,6 +1,5 @@ (doc=>{ - Array.isNotEmpty = array => Array.isArray(array) && array.length; Array.prototype.unique = function() { return this.filter((v, i, a) => a.indexOf(v) === i); }; Array.prototype.validUnique = function(fn) { return this.filter((v, i, a) => (fn ? fn(v) : v) && a.indexOf(v) === i);