Revamp array filtering

Replaced fakeMd5 with new Jua.randomId
Cleanup more code
This commit is contained in:
djmaze 2020-10-02 23:54:15 +02:00
parent 9992b20163
commit c3a2da65df
23 changed files with 130 additions and 289 deletions

View file

@ -10,7 +10,7 @@ class AccountUserStore {
this.accounts = ko.observableArray([]);
this.accounts.loading = ko.observable(false).extend({ throttle: 100 });
this.getEmailAddresses = () => this.accounts().map(item => item ? item.email : null).filter(value => !!value);
this.getEmailAddresses = () => this.accounts().map(item => item ? item.email : null).filter(v => v);
this.accountsUnreadCount = ko.computed(() => 0);
// this.accountsUnreadCount = ko.computed(() => {

View file

@ -85,7 +85,7 @@ class FolderUserStore {
});
this.folderListSystem = ko.computed(() =>
this.folderListSystemNames().map(name => getFolderFromCacheList(name)).filter(value => !!value)
this.folderListSystemNames().map(name => getFolderFromCacheList(name)).filter(v => v)
);
this.folderMenuForMove = ko.computed(() =>

View file

@ -5,8 +5,7 @@ import { Layout, Focused, MessageSetAction, StorageResultType, Notification } fr
import {
pInt,
pString,
plainToHtml,
findEmailAndLinks
plainToHtml
} from 'Common/Utils';
import {
@ -44,6 +43,14 @@ const
const result = hcont.clientHeight;
hcont.innerHTML = '';
return result;
},
/*eslint-disable max-len*/
url = /(^|[\s\n]|\/?>)(https:\/\/[-A-Z0-9+\u0026\u2019#/%?=()~_|!:,.;]*[-A-Z0-9+\u0026#/%=~()_|])/gi,
email = /(^|[\s\n]|\/?>)((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x21\x23-\x5b\x5d-\x7f]|\\[\x21\x23-\x5b\x5d-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x21-\x5a\x53-\x7f]|\\[\x21\x23-\x5b\x5d-\x7f])+)\]))/gi,
findEmailAndLinks = html => {
return html
.replace(url, '$1<a href="$2" target="_blank">$2</a>')
.replace(email, '$1<a href="mailto:$2">$2</a>');
};
let iMessageBodyCacheCount = 0;
@ -142,7 +149,7 @@ class MessageUserStore {
if (checked.length) {
return selectedMessage
? checked.concat([selectedMessage]).filter((value, index, self) => self.indexOf(value) == index)
? checked.concat([selectedMessage]).unique()
: checked;
}
@ -155,7 +162,7 @@ class MessageUserStore {
if (message) {
result.push(message.uid);
if (1 < message.threadsLen()) {
result = result.concat(message.threads()).filter((value, index, self) => self.indexOf(value) == index);
result = result.concat(message.threads()).unique();
}
}
});

View file

@ -53,7 +53,7 @@ function domControlEncryptedClickHelper(store, dom, armoredMessage, recipients)
} else if (validPrivateKey) {
const keyIds = Array.isNotEmpty(signingKeyIds) ? signingKeyIds : null,
additional = keyIds
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(value => !!value).join(', ')
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ')
: '';
controlsHelper(
@ -109,7 +109,7 @@ function domControlSignedClickHelper(store, dom, armoredMessage) {
} else {
const keyIds = Array.isNotEmpty(signingKeyIds) ? signingKeyIds : null,
additional = keyIds
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(value => !!value).join(', ')
? keyIds.map(item => (item && item.toHex ? item.toHex() : null)).filter(v => v).join(', ')
: '';
controlsHelper(
@ -138,8 +138,8 @@ class PgpUserStore {
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
this.openpgpkeysPublic = ko.computed(() => this.openpgpkeys().filter(item => !!(item && !item.isPrivate)));
this.openpgpkeysPrivate = ko.computed(() => this.openpgpkeys().filter(item => !!(item && item.isPrivate)));
this.openpgpkeysPublic = ko.computed(() => this.openpgpkeys().filter(item => item && !item.isPrivate));
this.openpgpkeysPrivate = ko.computed(() => this.openpgpkeys().filter(item => item && item.isPrivate));
}
/**
@ -165,14 +165,14 @@ class PgpUserStore {
return this.openpgpkeysPublic().map(item => {
const key = item && item.emails.includes(email) ? item : null;
return key ? key.getNativeKeys() : [null];
}).flat().filter(value => !!value);
}).flat().filter(v => v);
}
findPublicKeysBySigningKeyIds(signingKeyIds) {
return signingKeyIds.map(id => {
const key = id && id.toHex ? this.findPublicKeyByHex(id.toHex()) : null;
return key ? key.getNativeKeys() : [null];
}).flat().filter(value => !!value);
}).flat().filter(v => v);
}
findPrivateKeysByEncryptionKeyIds(encryptionKeyIds, recipients, returnWrapKeys) {
@ -180,7 +180,7 @@ class PgpUserStore {
? encryptionKeyIds.map(id => {
const key = id && id.toHex ? this.findPrivateKeyByHex(id.toHex()) : null;
return key ? (returnWrapKeys ? [key] : key.getNativeKeys()) : [null];
}).flat().filter(value => !!value)
}).flat().filter(v => v)
: [];
if (!result.length && Array.isNotEmpty(recipients)) {
@ -191,7 +191,7 @@ class PgpUserStore {
? keys
: keys.map(key => key.getNativeKeys()).flat()
: [null];
}).flat().filter((key, index, self) => key => !!key.id && self.indexOf(key) == index);
}).flat().validUnique(key => key.id);
}
return result;

View file

@ -15,7 +15,7 @@ class TemplateUserStore {
subscribers() {
this.templates.subscribe((list) => {
this.templatesNames(list.map(item => (item ? item.name : null)).filter(value => !!value));
this.templatesNames(list.map(item => (item ? item.name : null)).filter(v => v));
});
// this.templatesNames.subscribe((aList) => {