mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 10:22:18 -05:00
Review
This commit is contained in:
parent
6a8c24d813
commit
b01aa6716c
@ -95,7 +95,7 @@ var ReadCtrl = function($scope, $location, $q, email, invitation, outbox, pgp, k
|
|||||||
return keychain.getReceiverPublicKey(user.address);
|
return keychain.getReceiverPublicKey(user.address);
|
||||||
|
|
||||||
}).then(function(pubkey) {
|
}).then(function(pubkey) {
|
||||||
if (pubkey.publicKey) {
|
if (pubkey && pubkey.publicKey) {
|
||||||
user.secure = true;
|
user.secure = true;
|
||||||
} else {
|
} else {
|
||||||
user.secure = false;
|
user.secure = false;
|
||||||
|
@ -64,40 +64,30 @@ Keychain.prototype.verifyPublicKey = function(uuid) {
|
|||||||
* @return [PublicKeyCollection] The requiested public keys
|
* @return [PublicKeyCollection] The requiested public keys
|
||||||
*/
|
*/
|
||||||
Keychain.prototype.getPublicKeys = function(ids) {
|
Keychain.prototype.getPublicKeys = function(ids) {
|
||||||
var self = this;
|
var self = this,
|
||||||
return new Promise(function(resolve, reject) {
|
jobs = [],
|
||||||
var after, already, pubkeys = [];
|
pubkeys = [];
|
||||||
|
|
||||||
// return empty array if key ids are emtpy
|
ids.forEach(function(i) {
|
||||||
if (ids.length < 1) {
|
|
||||||
resolve(pubkeys);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
after = _.after(ids.length, function() {
|
|
||||||
resolve(pubkeys);
|
|
||||||
});
|
|
||||||
|
|
||||||
_.each(ids, function(i) {
|
|
||||||
// lookup locally and in storage
|
// lookup locally and in storage
|
||||||
self.lookupPublicKey(i._id).then(function(pubkey) {
|
var promise = self.lookupPublicKey(i._id).then(function(pubkey) {
|
||||||
if (!pubkey) {
|
if (!pubkey) {
|
||||||
reject(new Error('Error looking up public key!'));
|
throw new Error('Error looking up public key!');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if public key with that id has already been fetched
|
// check if public key with that id has already been fetched
|
||||||
already = null;
|
var already = _.findWhere(pubkeys, {
|
||||||
already = _.findWhere(pubkeys, {
|
|
||||||
_id: i._id
|
_id: i._id
|
||||||
});
|
});
|
||||||
if (!already) {
|
if (!already) {
|
||||||
pubkeys.push(pubkey);
|
pubkeys.push(pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
after(); // asynchronously iterate through objects
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
});
|
||||||
|
jobs.push(promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(jobs).then(function() {
|
||||||
|
return pubkeys;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user