Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MMS]Auto suggestion for email address r=Steve #20879

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,4 +1,4 @@
/*global Template, Utils */
/*global Template, Utils, Settings */

'use strict';

@@ -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;
}

@@ -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 email
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.
@@ -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]);
@@ -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 = {
@@ -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;
@@ -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);
@@ -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;
@@ -1,4 +1,4 @@
/*global GestureDetector, Dialog, Navigation */
/*global Utils, GestureDetector, Dialog, Navigation, Settings */

(function(exports) {
'use strict';
@@ -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>
@@ -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;
}

@@ -20,6 +20,9 @@ var Settings = {

_serviceIds: null,

// we need to remove this when email functionality is ready.
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
@@ -2571,32 +2571,34 @@ var ThreadUI = global.ThreadUI = {
var last = this.recipientsList.lastElementChild;
var typed = last && last.textContent.trim();
var isContact = false;
var record, tel, length, number, contact;
var record, length, number, contact, prop, propValue;

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;
propValue = record[prop][i].value;
if (this.recipients.numbers.indexOf(propValue) === -1) {
number = propValue;
break;
}
}
@@ -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)
@@ -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);
@@ -588,6 +595,11 @@
numberHTML: ''
};

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

return data;
},

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

/*
TODO: Email Address check.
*/
isEmailAddress: function(email) {

This comment has been minimized.

Copy link
@steveck-chung

steveck-chung Jun 24, 2014

Contributor

Please add `isEmailAddress: Utils.isEmailAddress`` in mock_utils.js to pass the unit test.

This comment has been minimized.

Copy link
@na-matsumoto

na-matsumoto Jun 26, 2014

Author Contributor

Sorry, I add.

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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.