From a600aaea87da158c2b44ec15251b359368cda953 Mon Sep 17 00:00:00 2001
From: Tankred Hase
Date: Mon, 15 Sep 2014 19:06:31 +0200
Subject: [PATCH] Bind email addresses in pgp keychain to autocomplete
---
src/js/controller/write.js | 45 ++++++++++++++++++++++++++++----------
src/tpl/write.html | 6 ++---
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/src/js/controller/write.js b/src/js/controller/write.js
index 66e39f7..b9b4e9e 100644
--- a/src/js/controller/write.js
+++ b/src/js/controller/write.js
@@ -63,6 +63,7 @@ define(function(require) {
$scope.body = '';
$scope.ciphertextPreview = '';
$scope.attachments = [];
+ $scope.addressBookCache = undefined;
}
function reportBug() {
@@ -214,7 +215,7 @@ define(function(require) {
* Verify email address and fetch its public key
*/
$scope.verify = function(recipient) {
- if(!recipient) {
+ if (!recipient) {
return;
}
@@ -231,7 +232,7 @@ define(function(require) {
}
// keychainDao is undefined in local dev environment
- if(keychainDao) {
+ if (keychainDao) {
// check if to address is contained in known public keys
// when we write an email, we always need to work with the latest keys available
keychainDao.refreshKeyForUserId(recipient.address, function(err, key) {
@@ -403,22 +404,42 @@ define(function(require) {
$scope.tagStyle = function(recipient) {
var classes = ['label'];
- if(recipient.secure === false) {
+ if (recipient.secure === false) {
classes.push('label-primary');
}
return classes;
};
- $scope.lookupAddressBook = function(/*query*/) {
+ $scope.lookupAddressBook = function(query) {
var deferred = $q.defer();
- deferred.resolve([
- { address: 'john@doe.com' },
- { address: 'jane@doe.com' },
- { address: 'john.doe@example.com' },
- { address: 'jane.doe@example.com' },
- { address: 'max.mustermann@example.com' },
- ]);
+ if (!$scope.addressBookCache) {
+ // populate address book cache
+ keychainDao.listLocalPublicKeys(function(err, keys) {
+ if (err) {
+ $scope.onError(err);
+ return;
+ }
+
+ $scope.addressBookCache = keys.map(function(key) {
+ return {
+ address: key.userId
+ };
+ });
+ filter();
+ });
+
+ } else {
+ filter();
+ }
+
+ // query address book cache
+ function filter() {
+ var addresses = $scope.addressBookCache.filter(function(i) {
+ return i.address.indexOf(query) !== -1;
+ });
+ deferred.resolve(addresses);
+ }
return deferred.promise;
};
@@ -500,7 +521,7 @@ define(function(require) {
link: function(scope, element, attrs) {
var model = $parse(attrs.focusInput);
scope.$watch(model, function(value) {
- if(value === true) {
+ if (value === true) {
$timeout(function() {
element.find('input').first().focus();
}, 100);
diff --git a/src/tpl/write.html b/src/tpl/write.html
index 3ac3fd2..747870e 100644
--- a/src/tpl/write.html
+++ b/src/tpl/write.html
@@ -17,7 +17,7 @@
tag-style="tagStyle" display-property="address" on-tag-added="verify($tag)"
allowed-tags-pattern='^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'
placeholder="add recipient">
-
+
-
+
-
+