From 6ccb9bc057e33b3940e9cff1c77a2c787b011a25 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Wed, 25 Mar 2015 17:08:19 +0000 Subject: [PATCH] Bug 1114563 - Show the room name before the user enters the room. r=mikedeboer --- .../loop/content/shared/js/activeRoomStore.js | 35 +++++----- .../loop/test/shared/activeRoomStore_test.js | 67 +++++++++---------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/browser/components/loop/content/shared/js/activeRoomStore.js b/browser/components/loop/content/shared/js/activeRoomStore.js index 57c6b66a9d5..4d266537f75 100644 --- a/browser/components/loop/content/shared/js/activeRoomStore.js +++ b/browser/components/loop/content/shared/js/activeRoomStore.js @@ -182,10 +182,10 @@ loop.store.ActiveRoomStore = (function() { }, /** - * Execute fetchServerData event action from the dispatcher. Although - * this is to fetch the server data - for rooms on the standalone client, - * we don't actually need to get any data. Therefore we just save the - * data that is given to us for when the user chooses to join the room. + * Execute fetchServerData event action from the dispatcher. For rooms + * we need to get the room context information from the server. We don't + * need other data until the user decides to join the room. + * This action is only used for the standalone UI. * * @param {sharedActions.FetchServerData} actionData */ @@ -206,6 +206,18 @@ loop.store.ActiveRoomStore = (function() { this._handleRoomUpdate.bind(this)); this._mozLoop.rooms.on("delete:" + actionData.roomToken, this._handleRoomDelete.bind(this)); + + this._mozLoop.rooms.get(this._storeState.roomToken, + function(err, result) { + if (err) { + // XXX Bug 1110937 will want to handle the error results here + // e.g. room expired/invalid. + console.error("Failed to get room data:", err); + return; + } + + this.dispatcher.dispatch(new sharedActions.UpdateRoomInfo(result)); + }.bind(this)); }, /** @@ -341,21 +353,6 @@ loop.store.ActiveRoomStore = (function() { this._mozLoop.addConversationContext(this._storeState.windowId, actionData.sessionId, ""); - - // If we haven't got a room name yet, go and get one. We typically - // need to do this in the case of the standalone window. - // XXX When bug 1103331 lands this can be moved to earlier. - if (!this._storeState.roomName) { - this._mozLoop.rooms.get(this._storeState.roomToken, - function(err, result) { - if (err) { - console.error("Failed to get room data:", err); - return; - } - - this.dispatcher.dispatch(new sharedActions.UpdateRoomInfo(result)); - }.bind(this)); - } }, /** diff --git a/browser/components/loop/test/shared/activeRoomStore_test.js b/browser/components/loop/test/shared/activeRoomStore_test.js index 8616da90ac4..eafeffe9577 100644 --- a/browser/components/loop/test/shared/activeRoomStore_test.js +++ b/browser/components/loop/test/shared/activeRoomStore_test.js @@ -320,23 +320,48 @@ describe("loop.store.ActiveRoomStore", function () { }); describe("#fetchServerData", function() { - it("should save the token", function() { - store.fetchServerData(new sharedActions.FetchServerData({ + var fetchServerAction; + + beforeEach(function() { + fetchServerAction = new sharedActions.FetchServerData({ windowType: "room", token: "fakeToken" - })); + }); + }); + + it("should save the token", function() { + store.fetchServerData(fetchServerAction); expect(store.getStoreState().roomToken).eql("fakeToken"); }); it("should set the state to `READY`", function() { - store.fetchServerData(new sharedActions.FetchServerData({ - windowType: "room", - token: "fakeToken" - })); + store.fetchServerData(fetchServerAction); expect(store.getStoreState().roomState).eql(ROOM_STATES.READY); }); + + it("should call mozLoop.rooms.get to get the room data", function() { + store.fetchServerData(fetchServerAction); + + sinon.assert.calledOnce(fakeMozLoop.rooms.get); + }); + + it("should dispatch UpdateRoomInfo if mozLoop.rooms.get is successful", function() { + var roomDetails = { + roomName: "fakeName", + roomUrl: "http://invalid", + roomOwner: "gavin" + }; + + fakeMozLoop.rooms.get.callsArgWith(1, null, roomDetails); + + store.fetchServerData(fetchServerAction); + + sinon.assert.calledOnce(dispatcher.dispatch); + sinon.assert.calledWithExactly(dispatcher.dispatch, + new sharedActions.UpdateRoomInfo(roomDetails)); + }); }); describe("#feedbackComplete", function() { @@ -578,34 +603,6 @@ describe("loop.store.ActiveRoomStore", function () { "42", "15263748", ""); }); - it("should call mozLoop.rooms.get to get the room data if the roomName" + - "is not known", function() { - store.setStoreState({roomName: undefined}); - - store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData)); - - sinon.assert.calledOnce(fakeMozLoop.rooms.get); - }); - - it("should dispatch UpdateRoomInfo if mozLoop.rooms.get is successful", - function() { - var roomDetails = { - roomName: "fakeName", - roomUrl: "http://invalid", - roomOwner: "gavin" - }; - - fakeMozLoop.rooms.get.callsArgWith(1, null, roomDetails); - - store.setStoreState({roomName: undefined}); - - store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData)); - - sinon.assert.calledOnce(dispatcher.dispatch); - sinon.assert.calledWithExactly(dispatcher.dispatch, - new sharedActions.UpdateRoomInfo(roomDetails)); - }); - it("should call mozLoop.rooms.refreshMembership before the expiresTime", function() { store.joinedRoom(new sharedActions.JoinedRoom(fakeJoinedData));