js: simplify getDefaultKey

--

* src/Keyring.js: In case no default Key is set in configuration,
  only Keys reported as having a secret part should be considered
  for default Keys, avoiding some extra requests.
This commit is contained in:
Maximilian Krambach 2018-08-16 11:29:10 +02:00
parent 622db0d1de
commit aeb065acc9

View File

@ -192,17 +192,13 @@ export class GPGME_Keyring {
reject(error); reject(error);
}); });
} else { } else {
// TODO: this is overly 'expensive' in communication let msg = createMessage('keylist');
// and probably performance, too msg.setParameter('secret', true);
me.getKeys(null,true).then(function(keys){ msg.post().then(function(result){
for (let i=0; i < keys.length; i++){ if (result.keys.length === 0){
if (keys[i].get('hasSecret') === true){ reject(gpgme_error('KEY_NO_DEFAULT'));
resolve(keys[i]); } else {
break; resolve(result.keys[0]);
}
if (i === keys.length -1){
reject(gpgme_error('KEY_NO_DEFAULT'));
}
} }
}, function(error){ }, function(error){
reject(error); reject(error);