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

Commit

Permalink
Merge pull request #27326 from lodr/bug-997547-text-to-email-from-con…
Browse files Browse the repository at this point in the history
…tacts

Bug 997547 - [MMS]Text to email from Contact details
r=:julienw
  • Loading branch information
delapuente committed Jan 19, 2015
2 parents e6a5e65 + 095a9ce commit eda2429
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
3 changes: 3 additions & 0 deletions apps/communications/contacts/elements/details.html
Expand Up @@ -84,6 +84,9 @@ <h2 data-l10n-id="#type_l10n_id#">#type#</h2>
<b aria-label="Email" data-l10n-id="composeEmail">#value#</b>
</button>
</div>
<div class="item-media pull-right">
<button id="send-sms-to-email-button-#i#" class="activity send-sms icon icon-message" data-l10n-id="send-sms-button" aria-label="SMS"></button>
</div>
</div>
</li>

Expand Down
Expand Up @@ -35,6 +35,11 @@ <h2 data-l10n-id="#type_l10n_id#">#type#</h2>
<b>#value#</b>
</button>
</div>
<div class="item-media pull-right">
<button id="send-sms-to-email-button-#i#"
class="activity send-sms icon icon-message"
data-l10n-id="send-sms-button" aria-label="SMS"></button>
</div>
</div>
</li>
</section>
Expand Down
14 changes: 7 additions & 7 deletions apps/sms/js/activity_handler.js
Expand Up @@ -77,31 +77,31 @@ var ActivityHandler = {
},

/**
* Finds a contact from a number.
* Finds a contact from a number or email address.
* Returns a promise that resolve with a contact
* or is rejected if not found
* @returns Promise that resolve to a
* {number: String, name: String, source: 'contacts'}
*/
_findContactByNumber: function findContactByNumber(number) {
_findContactByTarget: function findContactByTarget(target) {
var deferred = Utils.Promise.defer();
Contacts.findByPhoneNumber(number, (results) => {
Contacts.findByAddress(target, (results) => {
var record, name, contact;

// Bug 867948: results null is a legitimate case
if (results && results.length) {
record = results[0];
name = record.name.length && record.name[0];
contact = {
number: number,
number: target,
name: name,
source: 'contacts'
};

deferred.resolve(contact);
return;
}
deferred.reject(new Error('No contact found with number: ' + number));
deferred.reject(new Error('No contact found with target: ' + target));
return;

});
Expand All @@ -120,7 +120,7 @@ var ActivityHandler = {

var viewInfo = {
body: activity.source.data.body,
number: activity.source.data.number,
number: activity.source.data.target || activity.source.data.number,
contact: null,
threadId: null
};
Expand All @@ -132,7 +132,7 @@ var ActivityHandler = {
viewInfo.threadId = threadId;
},
function onReject() {
return ActivityHandler._findContactByNumber(viewInfo.number)
return ActivityHandler._findContactByTarget(viewInfo.number)
.then( (contact) => viewInfo.contact = contact);
}
)
Expand Down
29 changes: 28 additions & 1 deletion apps/sms/test/unit/activity_handler_test.js
Expand Up @@ -746,6 +746,17 @@ suite('ActivityHandler', function() {
postResult: sinon.stub()
};

var newActivity_email = {
source: {
name: 'new',
data: {
target: 'abc@exmple.com',
body: 'foo'
}
},
postResult: sinon.stub()
};

var newActivity_empty = {
source: {
name: 'new',
Expand Down Expand Up @@ -899,13 +910,29 @@ suite('ActivityHandler', function() {
}).then(done,done);
});

test('new message with email', function(done) {
MockNavigatormozSetMessageHandler.mTrigger('activity', newActivity_email);
threadDeferred.reject(new Error('No thread for this test'));

sinon.assert.called(ActivityHandler._onNewActivity);
ActivityHandler._onNewActivity.firstCall.returnValue.then(function() {
assert.isTrue(ActivityHandler.isInActivity());
sinon.assert.calledWithMatch(Navigation.toPanel, 'composer', {
activity: {
number: newActivity_email.source.data.target,
body: newActivity_email.source.data.body
}
});
}).then(done,done);
});

test('when no existing thread, but a contact: new message with contact',
function(done) {
MockNavigatormozSetMessageHandler.mTrigger('activity', newActivity);
threadDeferred.reject(new Error('No thread for this test'));

Contacts.findByPhoneNumber.restore();
this.sinon.stub(Contacts, 'findByPhoneNumber')
this.sinon.stub(Contacts, 'findByAddress')
.callsArgWith(1, [{ name: ['foo'] }]);

sinon.assert.called(ActivityHandler._onNewActivity);
Expand Down
12 changes: 9 additions & 3 deletions shared/js/contacts/contacts_buttons.js
Expand Up @@ -88,8 +88,8 @@ var ContactsButtons = {
},

_onSendSmsClicked: function onSendSmsClicked(evt) {
var tel = evt.target.dataset.tel;
SmsIntegration.sendSms(tel);
var target = evt.target.dataset.target;
SmsIntegration.sendSms(target);
},

_onEmailOrPickClick: function onEmailOrPickClick(evt) {
Expand Down Expand Up @@ -128,7 +128,7 @@ var ContactsButtons = {

// Add event listeners to the phone template components
var sendSmsButton = template.querySelector('#send-sms-button-' + tel);
sendSmsButton.dataset.tel = telField.value;
sendSmsButton.dataset.target = telField.value;
sendSmsButton.addEventListener('click',
this._onSendSmsClicked.bind(this));

Expand Down Expand Up @@ -164,6 +164,12 @@ var ContactsButtons = {
document.querySelector('#email-details-template-\\#i\\#');
var template = utils.templates.render(emailsTemplate, emailField);

var sendSmsButton = template.querySelector('#send-sms-to-email-button-' +
email);
sendSmsButton.dataset.target = emailField.value;
sendSmsButton.addEventListener('click',
this._onSendSmsClicked.bind(this));

// Add event listeners to the phone template components
var emailButton = template.querySelector('#email-or-pick-' + email);
emailButton.dataset.email = emailField.value;
Expand Down
2 changes: 1 addition & 1 deletion shared/js/contacts/sms_integration.js
Expand Up @@ -10,7 +10,7 @@ var SmsIntegration = {
name: 'new',
data: {
type: 'websms/sms',
number: number
target: number
}
});
} catch (e) {
Expand Down

0 comments on commit eda2429

Please sign in to comment.