Bug 1193765 - Share Link doesn't work from the user unavailable screen of direct calls. r=dmose, a=ritu
authorMark Banner <standard8@mozilla.com>
Thu, 13 Aug 2015 09:09:21 +0100
changeset 288769 1d655c0c621c2e1983034ddfcc2ff1801d1fbae3
parent 288768 76f8cfa41d910eddda686f07aaac7221dbc5c15a
child 288770 83d2d1a34a2f495af3f47cf03efa3d77b589681e
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmose, ritu
bugs1193765
milestone42.0a2
Bug 1193765 - Share Link doesn't work from the user unavailable screen of direct calls. r=dmose, a=ritu
browser/components/loop/content/shared/js/conversationStore.js
browser/components/loop/modules/LoopRooms.jsm
browser/components/loop/test/shared/conversationStore_test.js
browser/components/loop/test/xpcshell/test_looprooms.js
--- a/browser/components/loop/content/shared/js/conversationStore.js
+++ b/browser/components/loop/content/shared/js/conversationStore.js
@@ -416,17 +416,19 @@ loop.store = loop.store || {};
     },
 
     /**
      * Fetches a new room URL intended to be sent over email when a contact
      * can't be reached.
      */
     fetchRoomEmailLink: function(actionData) {
       this.mozLoop.rooms.create({
-        roomName: actionData.roomName,
+        decryptedContext: {
+          roomName: actionData.roomName
+        },
         roomOwner: actionData.roomOwner,
         maxSize: loop.store.MAX_ROOM_CREATION_SIZE,
         expiresIn: loop.store.DEFAULT_EXPIRES_IN
       }, function(err, createdRoomData) {
         var buckets = this.mozLoop.ROOM_CREATE;
         if (err) {
           this.trigger("error:emailLink");
           this.mozLoop.telemetryAddValue("LOOP_ROOM_CREATE", buckets.CREATE_FAIL);
--- a/browser/components/loop/modules/LoopRooms.jsm
+++ b/browser/components/loop/modules/LoopRooms.jsm
@@ -297,16 +297,31 @@ let LoopRoomsInternal = {
   promiseDecryptRoomKey: Task.async(function* (encryptedKey) {
     let profileKey = yield MozLoopService.promiseProfileEncryptionKey();
 
     let decryptedRoomKey = yield loopCrypto.decryptBytes(profileKey, encryptedKey);
     return decryptedRoomKey;
   }),
 
   /**
+   * Updates a roomUrl to add a new key onto the end of the url.
+   *
+   * @param  {String} roomUrl The existing url that may or may not have a key
+   *                          on the end.
+   * @param  {String} roomKey The new key to put on the url.
+   * @return {String}         The revised url.
+   */
+  refreshRoomUrlWithNewKey: function(roomUrl, roomKey) {
+    // Strip any existing key from the url.
+    roomUrl = roomUrl.split("#")[0];
+    // Now add the key to the url.
+    return roomUrl + "#" + roomKey;
+  },
+
+  /**
    * Encrypts room data in a format appropriate to sending to the loop
    * server.
    *
    * @param  {Object} roomData The room data to encrypt.
    * @return {Promise} A promise that is resolved with an object containing
    *                   two objects:
    *                   - encrypted: The encrypted data to send. This excludes
    *                                any decrypted data.
@@ -399,20 +414,17 @@ let LoopRoomsInternal = {
       catch (error) {
         MozLoopService.log.error("Failed to save room key:", error);
       }
     }
 
     roomData.roomKey = key;
     roomData.decryptedContext = JSON.parse(decryptedData);
 
-    // Strip any existing key from the url.
-    roomData.roomUrl = roomData.roomUrl.split("#")[0];
-    // Now add the key to the url.
-    roomData.roomUrl = roomData.roomUrl + "#" + roomData.roomKey;
+    roomData.roomUrl = this.refreshRoomUrlWithNewKey(roomData.roomUrl, roomData.roomKey);
 
     return roomData;
   }),
 
   /**
    * Saves room information and notifies updates to any listeners.
    *
    * @param {Object}  roomData The new room data to save.
@@ -605,16 +617,18 @@ let LoopRoomsInternal = {
       room = all;
       // ...but only send the encrypted data.
       let response = yield MozLoopService.hawkRequest(this.sessionType, "/rooms",
         "POST", encrypted);
 
       extend(room, JSON.parse(response.body));
       // Do not keep this value - it is a request to the server.
       delete room.expiresIn;
+      // Make sure the url has the key on it.
+      room.roomUrl = this.refreshRoomUrlWithNewKey(room.roomUrl, room.roomKey);
       this.rooms.set(room.roomToken, room);
 
       if (this.sessionType == LOOP_SESSION_TYPE.GUEST) {
         this.setGuestCreatedRoom(true);
       }
 
       // Now we've got the room token, we can save the key to disk.
       yield this.roomsCache.setKey(this.sessionType, room.roomToken, room.roomKey);
--- a/browser/components/loop/test/shared/conversationStore_test.js
+++ b/browser/components/loop/test/shared/conversationStore_test.js
@@ -1044,18 +1044,19 @@ describe("loop.store.ConversationStore",
     it("should request a new call url to the server", function() {
       store.fetchRoomEmailLink(new sharedActions.FetchRoomEmailLink({
         roomOwner: "bob@invalid.tld",
         roomName: "FakeRoomName"
       }));
 
       sinon.assert.calledOnce(fakeMozLoop.rooms.create);
       sinon.assert.calledWithMatch(fakeMozLoop.rooms.create, {
-        roomOwner: "bob@invalid.tld",
-        roomName: "FakeRoomName"
+        decryptedContext: {
+          roomName: "FakeRoomName"
+        }
       });
     });
 
     it("should update the emailLink attribute when the new room url is received",
       function() {
         fakeMozLoop.rooms.create = function(roomData, cb) {
           cb(null, {roomUrl: "http://fake.invalid/"});
         };
--- a/browser/components/loop/test/xpcshell/test_looprooms.js
+++ b/browser/components/loop/test/xpcshell/test_looprooms.js
@@ -399,16 +399,23 @@ add_task(function* test_errorStates() {
 
 // Test if creating a new room works as expected.
 add_task(function* test_createRoom() {
   var expectedRoom = extend({}, kCreateRoomProps);
   expectedRoom.roomToken = kCreateRoomData.roomToken;
 
   gExpectedAdds.push(expectedRoom);
   let room = yield LoopRooms.promise("create", kCreateRoomProps);
+
+  // We can't check the value of the key, but check we've got a # which indicates
+  // there should be one.
+  Assert.ok(room.roomUrl.contains("#"), "Created room url should have a key");
+  var key = room.roomUrl.split("#")[1];
+  Assert.ok(key.length, "Created room url should have non-zero length key");
+
   compareRooms(room, expectedRoom);
 });
 
 // Test if opening a new room window works correctly.
 add_task(function* test_openRoom() {
   let openedUrl;
   Chat.open = function(contentWindow, origin, title, url) {
     openedUrl = url;