mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Deduplicate and sort OpenPGP.js key stores #89
This commit is contained in:
parent
d832117ae4
commit
89b6e84fea
1 changed files with 16 additions and 7 deletions
|
|
@ -117,12 +117,16 @@ export const OpenPGPUserStore = new class {
|
||||||
|
|
||||||
loadKeyrings() {
|
loadKeyrings() {
|
||||||
if (window.openpgp) {
|
if (window.openpgp) {
|
||||||
|
const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}),
|
||||||
|
dedup = keys => (keys || [])
|
||||||
|
.filter((v, i, a) => a.findIndex(entry => entry.fingerprint == v.fingerprint) === i)
|
||||||
|
.sort((a, b) => collator.compare(a.emails[0], b.emails[0]));
|
||||||
loadOpenPgpKeys(publicKeysItem).then(keys => {
|
loadOpenPgpKeys(publicKeysItem).then(keys => {
|
||||||
this.publicKeys(keys || []);
|
this.publicKeys(dedup(keys));
|
||||||
console.log('openpgp.js public keys loaded');
|
console.log('openpgp.js public keys loaded');
|
||||||
});
|
});
|
||||||
loadOpenPgpKeys(privateKeysItem).then(keys => {
|
loadOpenPgpKeys(privateKeysItem).then(keys => {
|
||||||
this.privateKeys(keys || [])
|
this.privateKeys(dedup(keys));
|
||||||
console.log('openpgp.js private keys loaded');
|
console.log('openpgp.js private keys loaded');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -138,12 +142,17 @@ export const OpenPGPUserStore = new class {
|
||||||
importKey(armoredKey) {
|
importKey(armoredKey) {
|
||||||
window.openpgp && openpgp.readKey({armoredKey:armoredKey}).then(key => {
|
window.openpgp && openpgp.readKey({armoredKey:armoredKey}).then(key => {
|
||||||
if (!key.err) {
|
if (!key.err) {
|
||||||
if (key.isPrivate()) {
|
key = new OpenPgpKeyModel(armoredKey, key);
|
||||||
this.privateKeys.push(new OpenPgpKeyModel(armoredKey, key));
|
if (key.key.isPrivate()) {
|
||||||
storeOpenPgpKeys(this.privateKeys, privateKeysItem);
|
if (!this.privateKeys.find(entry => entry.fingerprint == key.fingerprint)) {
|
||||||
|
this.privateKeys.push(key);
|
||||||
|
storeOpenPgpKeys(this.privateKeys, privateKeysItem);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.publicKeys.push(new OpenPgpKeyModel(armoredKey, key));
|
if (!this.publicKeys.find(entry => entry.fingerprint == key.fingerprint)) {
|
||||||
storeOpenPgpKeys(this.publicKeys, publicKeysItem);
|
this.publicKeys.push(key);
|
||||||
|
storeOpenPgpKeys(this.publicKeys, publicKeysItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue