Skip to content
Permalink
Browse files

Bug 1135649 - [Messages] Can't autocomplete email recipients r=azasypkin

  • Loading branch information...
julienw authored and rvandermeulen committed Feb 26, 2015
1 parent df92a3c commit 90dd2398e08793d8f24a3173be8bc24feabec192
Showing with 49 additions and 18 deletions.
  1. +13 −0 apps/sms/js/desktop-only/navigator_moz_contacts.js
  2. +19 −12 apps/sms/js/thread_ui.js
  3. +17 −6 apps/sms/test/unit/thread_ui_test.js
@@ -311,6 +311,19 @@
givenName: 'Ada',
tel: {
value: '104'
},
email: {
value: 'ada@lovelace.com'
}
})
);

ContactsDB.push(
new Contact({
familyName: 'Tesla',
givenName: 'Nikola',
email: {
value: 'nikola@tesla.com'
}
})
);
@@ -2522,41 +2522,48 @@ var ThreadUI = {
},

validateContact: function thui_validateContact(source, fValue, contacts) {
// fValue is currently unused here, but must be in the parameter
// list in order for exactContact and searchContact to both use
// validateContact as a handler.
//
var isInvalid = true;
var index = this.recipients.length - 1;
var last = this.recipientsList.lastElementChild;
var typed = last && last.textContent.trim();
var isContact = false;
var record, length, number, contact, prop, propValue;
var record, length, number, contact;

if (index < 0) {
index = 0;
}
prop = Settings.supportEmailRecipient &&
Utils.isEmailAddress(fValue) ? 'email' : 'tel';

var props = ['tel'];
if (Settings.supportEmailRecipient) {
props.push('email');
}

// If there is greater than zero matches,
// process the first found contact into
// an accepted Recipient.
if (contacts && contacts.length) {
isInvalid = false;
record = contacts[0];
length = record[prop].length;
var values = props.reduce((values, prop) => {
var propValue = record[prop];
if (propValue && propValue.length) {
return values.concat(propValue);
}

return values;
}, []);
length = values.length;

// Received an exact match with a single tel record
// Received an exact match with a single tel or email record
if (source.isLookupable && !source.isQuestionable && length === 1) {
if (Utils.probablyMatches(record[prop][0].value, fValue)) {
if (Utils.probablyMatches(values[0].value, fValue)) {
isContact = true;
number = record[prop][0].value;
number = values[0].value;
}
} else {
// Received an exact match that may have multiple tel records
for (var i = 0; i < length; i++) {
propValue = record[prop][i].value;
var propValue = values[i].value;
if (this.recipients.numbers.indexOf(propValue) === -1) {
number = propValue;
break;
@@ -1287,16 +1287,20 @@ suite('thread_ui.js >', function() {
test('[Email]input value has matching record ', function() {

MockSettings.supportEmailRecipient = true;
// TODO we need to filter properly inside contact search
// results (bug 1084184)
contacts[0].tel = [];
ThreadUI.validateContact(fixtureEmail, 'a@b.com', contacts);

sinon.assert.calledOnce(ThreadUI.recipients.remove);
sinon.assert.calledWith(ThreadUI.recipients.remove, 0);

assert.equal(
ThreadUI.recipients.add.firstCall.args[0].source, 'contacts'
);
assert.equal(
ThreadUI.recipients.add.firstCall.args[0].number, 'a@b.com'
sinon.assert.calledWithMatch(
ThreadUI.recipients.add,
{
source: 'contacts',
number: 'a@b.com'
}
);
});

@@ -1441,6 +1445,11 @@ suite('thread_ui.js >', function() {
contacts[0].email = [{value: 'a@b'}];
contacts[1].email = [{value: 'a@c'}];

// in bug 1084184 we should be able to filter the contacts using the
// fValue.
contacts[0].tel = [];
contacts[1].tel = [];

// An actual accepted recipient from contacts
ThreadUI.recipients.add({
name: 'Janet Jones',
@@ -1479,8 +1488,10 @@ suite('thread_ui.js >', function() {
'single, same tel record (invalid) ', function() {

MockSettings.supportEmailRecipient = true;
// Get rid of the second tel record to create a "duplicate"
// Make sure we have only one email
contacts[0].email.length = 1;
// in bug 1084184 we'll be able to filter using the fValue parameter.
contacts[0].tel = [];

// An actual accepted recipient from contacts
fixtureEmail.source = 'contacts';

0 comments on commit 90dd239

Please sign in to comment.
You can’t perform that action at this time.