Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer
--- a/browser/components/loop/content/shared/js/conversationStore.js
+++ b/browser/components/loop/content/shared/js/conversationStore.js
@@ -322,20 +322,35 @@ loop.store.ConversationStore = (function
},
/**
* Obtains the outgoing call data from the server and handles the
* result.
*/
_setupOutgoingCall: function() {
var contactAddresses = [];
+ var contact = this.get("contact");
- this.get("contact").email.forEach(function(address) {
- contactAddresses.push(address.value);
- });
+ function appendContactValues(property, strip) {
+ if (contact.hasOwnProperty(property)) {
+ contact[property].forEach(function(item) {
+ if (strip) {
+ contactAddresses.push(item.value
+ .replace(/^(\+)?(.*)$/g, function(m, prefix, number) {
+ return (prefix || "") + number.replace(/[\D]+/g, "");
+ }));
+ } else {
+ contactAddresses.push(item.value);
+ }
+ });
+ }
+ }
+
+ appendContactValues("email");
+ appendContactValues("tel", true);
this.client.setupOutgoingCall(contactAddresses,
this.get("callType"),
function(err, result) {
if (err) {
console.error("Failed to get outgoing call data", err);
this.dispatcher.dispatch(
new sharedActions.ConnectionFailure({reason: "setup"}));
--- a/browser/components/loop/test/shared/conversationStore_test.js
+++ b/browser/components/loop/test/shared/conversationStore_test.js
@@ -271,16 +271,89 @@ describe("loop.store.ConversationStore",
dispatcher.dispatch(
new sharedActions.GatherCallData(outgoingCallData));
sinon.assert.calledOnce(client.setupOutgoingCall);
sinon.assert.calledWith(client.setupOutgoingCall,
["fakeEmail"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
});
+ it("should include all email addresses in the call data", function() {
+ contact = {
+ name: [ "Mr Smith" ],
+ email: [{
+ type: "home",
+ value: "fakeEmail",
+ pref: true
+ },
+ {
+ type: "work",
+ value: "emailFake",
+ pref: false
+ }]
+ };
+
+ dispatcher.dispatch(
+ new sharedActions.GatherCallData(outgoingCallData));
+
+ sinon.assert.calledOnce(client.setupOutgoingCall);
+ sinon.assert.calledWith(client.setupOutgoingCall,
+ ["fakeEmail", "emailFake"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
+ });
+
+ it("should include trim phone numbers for the call data", function() {
+ contact = {
+ name: [ "Mr Smith" ],
+ tel: [{
+ type: "home",
+ value: "+44-5667+345 496(2335)45+ 456+",
+ pref: true
+ }]
+ };
+
+ dispatcher.dispatch(
+ new sharedActions.GatherCallData(outgoingCallData));
+
+ sinon.assert.calledOnce(client.setupOutgoingCall);
+ sinon.assert.calledWith(client.setupOutgoingCall,
+ ["+445667345496233545456"], sharedUtils.CALL_TYPES.AUDIO_VIDEO);
+ });
+
+ it("should include all email and telephone values in the call data", function() {
+ contact = {
+ name: [ "Mr Smith" ],
+ email: [{
+ type: "home",
+ value: "fakeEmail",
+ pref: true
+ }, {
+ type: "work",
+ value: "emailFake",
+ pref: false
+ }],
+ tel: [{
+ type: "work",
+ value: "01234567890",
+ pref: false
+ }, {
+ type: "home",
+ value: "09876543210",
+ pref: false
+ }]
+ };
+
+ dispatcher.dispatch(
+ new sharedActions.GatherCallData(outgoingCallData));
+
+ sinon.assert.calledOnce(client.setupOutgoingCall);
+ sinon.assert.calledWith(client.setupOutgoingCall,
+ ["fakeEmail", "emailFake", "01234567890", "09876543210"],
+ sharedUtils.CALL_TYPES.AUDIO_VIDEO);
+ });
+
describe("server response handling", function() {
beforeEach(function() {
sandbox.stub(dispatcher, "dispatch");
});
it("should dispatch a connect call action on success", function() {
var callData = {
apiKey: "fakeKey"