Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer a=lmandel
authorMark Banner <standard8@mozilla.com>
Thu, 16 Oct 2014 18:58:59 +0100
changeset 225734 191b3ce44bea
parent 225733 f705ffd06218
child 225735 3fc523fcc7da
push id3995
push userrjesup@wgate.com
push date2014-10-20 00:58 +0000
treeherdermozilla-beta@8c42ccaf8aa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, lmandel
bugs1081154
milestone34.0
Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer a=lmandel
browser/components/loop/content/shared/js/conversationStore.js
browser/components/loop/test/shared/conversationStore_test.js
--- a/browser/components/loop/content/shared/js/conversationStore.js
+++ b/browser/components/loop/content/shared/js/conversationStore.js
@@ -322,20 +322,35 @@ loop.store = (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.ConversationStore", funct
         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"