Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Thu, 16 Oct 2014 18:58:59 +0100
changeset 210777 2e896ba5d24fea6c6d4662315f5a3082153c8701
parent 210776 80f3f56a6091df282995f2870c5380e7b5c50d26
child 210778 8a4b1c63f43326fd0c423b7b9bc0812076e990bc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmikedeboer
bugs1081154
milestone36.0a1
Bug 1081154 - Loop direct calls should attempt to call phone numbers as well as email addresses. r=mikedeboer
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.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"