With the Chat
module created, we can turn back to the controller, where we want to render the chat for the chosen room. Let's create a helper function for this:
Controller.prototype.showChat = function () { App.layout.controls.show(new App.Chat.CreateMessageView()); App.layout.conversation.show(new App.Chat.CollectionView({ collection: new App.Chat.Collection([], { room: App.room.get('name') }) })); };
In the controls
region, we put Chat.CreateMessageView
. Then, in the conversation
region, we render a Chat.CollectionView
instance. Now, in our Controller.prototype.room
method, we can call this showChat
method:
Controller.prototype.room = function (room) { this.showUsersAndRooms(); App.room = this.rooms.getRoom(room); if (!App.name) { this.showLogin().on('user-added', this.showChat.bind(this)); } else { this.showChat(); } };
Now, this route is complete. Once we have a name, we'll show the chat messages.