Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 974867 - [MMS]Auto suggestion for email address r=Julien #20680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions apps/sms/js/contact_renderer.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Template, Utils */
/*global Template, Utils, Settings */

'use strict';

Expand Down Expand Up @@ -172,7 +172,10 @@ ContactRenderer.prototype = {

// don't render if there is no phone number
// TODO: Add email checking support for MMS
if (!contact.tel || !contact.tel.length) {
var hasTel = contact.tel && contact.tel.length;
var hasEmail = contact.email && contact.email.length;

if (!hasTel && !(Settings.supportEmailRecipient && hasEmail)) {
return false;
}

Expand All @@ -190,16 +193,30 @@ ContactRenderer.prototype = {
number: escsubs.map(function(k) {
// Match any of the search terms with the number
return new RegExp(k, 'ig');
}),
email: escsubs.map(function(k) {
// Match any of the search terms with the number
return new RegExp('^' + k, 'gi');
})
};

var include = renderPhoto ? { photoURL: true } : null;
var tels = contact.tel;
var details = Utils.getContactDetails(tels[0].value, contact, include);
var addresses = [];

if (contact.tel && contact.tel.length) {
addresses = addresses.concat(contact.tel);
}
if (Settings.supportEmailRecipient &&
contact.email && contact.email.length) {
addresses = addresses.concat(contact.email);
}
var details = Utils.getContactDetails(
addresses[0].value, contact, include
);

var tempDiv = document.createElement('div');

tels.forEach(function(current) {
addresses.forEach(function(current) {
// Only render a contact's tel value entry for the _specified_
// input value when not rendering all values. If the tel
// record value _doesn't_ match, then continue.
Expand All @@ -219,7 +236,12 @@ ContactRenderer.prototype = {

var data = Utils.getDisplayObject(details.title, current);

['name', 'number'].forEach(function(key) {
var props = ['name', 'number'];
if (Settings.supportEmailRecipient) {
props.push('email');
}

props.forEach(function(key) {
var escapedData = Template.escape(data[key]);
if (shouldHighlight) {
escapedData = highlight(escapedData, regexps[key]);
Expand Down
11 changes: 9 additions & 2 deletions apps/sms/js/contacts.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
(function(exports) {
'use strict';
/*global fb */
/*global fb, Settings */
var unknownNumbers = [];

var filterFns = {
Expand Down Expand Up @@ -188,6 +188,9 @@
request.onsuccess = function onsuccess() {
var contacts = this.result.slice();
var fields = ['tel', 'givenName', 'familyName'];
if (Settings.supportEmailRecipient) {
fields.push('email');
}
var criteria = { fields: fields, terms: lower };
var results = [];
var contact;
Expand Down Expand Up @@ -228,8 +231,12 @@
},

findContactByString: function contacts_findBy(filterValue, callback) {
var props = ['tel', 'givenName', 'familyName'];
if (Settings.supportEmailRecipient) {
props.push('email');
}
return this.findBy({
filterBy: ['tel', 'givenName', 'familyName'],
filterBy: props,
filterOp: 'contains',
filterValue: filterValue
}, callback);
Expand Down
3 changes: 3 additions & 0 deletions apps/sms/js/desktop-only/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
// nested condition a way out of the second and third loop.
outer:
for (var field of filter.filterBy) {
if (!contact[field]) {
continue;
}
for (var value of contact[field]) {
if (typeof value !== 'string') {
value = value.value;
Expand Down
8 changes: 6 additions & 2 deletions apps/sms/js/recipients.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global GestureDetector, Dialog, Navigation */
/*global Utils, GestureDetector, Dialog, Navigation, Settings */

(function(exports) {
'use strict';
Expand Down Expand Up @@ -28,6 +28,8 @@
this.separator = opts.separator || '';
this.carrier = opts.carrier || '';
this.className = 'recipient';
this.isEmail = Settings.supportEmailRecipient &&
Utils.isEmailAddress(this.number);

// isLookupable
// the recipient was accepted by pressing <enter>
Expand All @@ -52,7 +54,9 @@
// is questionable and may be invalid.
number = this.number[0] === '+' ? this.number.slice(1) : this.number;

if (this.source === 'manual' && !rdigit.test(number)) {
if (this.isEmail) {
this.className += ' email';
} else if (this.source === 'manual' && !rdigit.test(number)) {
this.isQuestionable = true;
}

Expand Down
2 changes: 2 additions & 0 deletions apps/sms/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var Settings = {

_serviceIds: null,

supportEmailRecipient: false,

// We set the default maximum concatenated number of our SMS app to 10
// based on:
// https://bugzilla.mozilla.org/show_bug.cgi?id=813686#c0
Expand Down
15 changes: 8 additions & 7 deletions apps/sms/js/thread_ui.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2571,32 +2571,33 @@ var ThreadUI = global.ThreadUI = {
var last = this.recipientsList.lastElementChild;
var typed = last && last.textContent.trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see tests for the new code here.

var isContact = false;
var record, tel, length, number, contact;
var record, length, number, contact, prop;

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

// 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.tel.length;
length = record[prop].length;

// Received an exact match with a single tel record
if (source.isLookupable && !source.isQuestionable && length === 1) {
if (Utils.probablyMatches(record.tel[0].value, fValue)) {
if (Utils.probablyMatches(record[prop][0].value, fValue)) {
isContact = true;
number = record.tel[0].value;
number = record[prop][0].value;
}
} else {
// Received an exact match that may have multiple tel records
for (var i = 0; i < length; i++) {
tel = record.tel[i];
if (this.recipients.numbers.indexOf(tel.value) === -1) {
number = tel.value;
if (this.recipients.numbers.indexOf(record[prop][i].value) === -1) {
number = record[prop][i].value;
break;
}
}
Expand Down
21 changes: 19 additions & 2 deletions apps/sms/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

/* globals ContactPhotoHelper, Notification, Threads*/
/* globals ContactPhotoHelper, Notification, Threads, Settings */

(function(exports) {
'use strict';
var rdashes = /-(.)/g;
var rescape = /[.?*+^$[\]\\(){}|-]/g;
var rparams = /([^?=&]+)(?:=([^&]*))?/g;
var rnondialablechars = /[^,#+\*\d]/g;
var rmail = /[\w-]+@[\w\-]/;
var downsamplingRefSize = {
// Estimate average Thumbnail size:
// 120 X 60 (max pixel) X 3 (full color) / 20 (average jpeg compress ratio)
Expand Down Expand Up @@ -267,6 +268,12 @@
return false;
}

if (Settings.supportEmailRecipient &&
Utils.isEmailAddress(a) &&
Utils.isEmailAddress(b)) {
return a === b;
}

if (service && service.normalize) {
a = service.normalize(a);
b = service.normalize(b);
Expand Down Expand Up @@ -588,6 +595,11 @@
numberHTML: ''
};

if (Settings.supportEmailRecipient) {
data.email = number;
data.emailHTML = '';
}

return data;
},

Expand All @@ -604,7 +616,12 @@
};
});
},

/*
TODO: Email Address check.
*/
isEmailAddress: function(email) {
return rmail.test(email);
},
/*
Helper function for removing notifications. It will fetch the notification
using the current threadId or the parameter if provided, and close them
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions apps/sms/style/sms.css
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ Do not remove.
float: left;
}

.recipient[contenteditable].email {
padding-right: 3.8rem;
background: white url(images/icons/icon_sms_compose_email.png) calc(100% - 1.5rem) center no-repeat;
}

/* Disable padding and margin on empty contenteditable recipients when they do
* not have focus. This allows the Recipients List to intelligently collapse
* when the final row contains no "assimilated" (i.e. non-contenteditable)
Expand Down
Loading