66 "scripts/chat/common/channel/channel_controller" ,
77 "scripts/chat/common/input/input_controller" ,
88 "scripts/chat/room/room_controller" ,
9- "scripts/entities/relation/room_relation " ,
9+ "scripts/entities/model/room_model " ,
1010 "scripts/region_manager" ,
1111] ,
1212function (
@@ -17,13 +17,13 @@ function (
1717 ChannelController ,
1818 InputController ,
1919 RoomController ,
20- RoomRelationalModel ,
20+ RoomModel ,
2121 regionManager
2222) {
2323
2424 var ChatRouter = Backbone . Marionette . AppRouter . extend ( {
2525 appRoutes : {
26- "room/:room" : "showChat "
26+ "room/:room" : "showChatRoom "
2727 }
2828 } ) ;
2929
@@ -39,26 +39,33 @@ function (
3939
4040 var roomControllers = { } ;
4141
42- var API = {
43- createChatRoom : function ( room ) {
42+ var createChatRoom = function ( room ) {
4443
45- /* called to create a room
46- */
44+ /* called to create a room
45+ */
4746
48- var roomRelationalModel = communicator . reqres . request ( 'entities:room:add' , room ) ;
47+ var roomModel = communicator . reqres . request ( 'entities:room:add' , room ) ;
4948
50- roomControllers [ room ] = new RoomController ( {
51- region : chatLayout . roomRegion ,
52- roomModel : roomRelationalModel ,
53- } ) ;
49+ roomControllers [ room ] = new RoomController ( {
50+ region : chatLayout . roomRegion ,
51+ roomModel : roomModel ,
52+ } ) ;
5453
55- } ,
54+ communicator . vent . trigger ( "chat:create:room" , room ) ;
55+
56+ } ;
57+
58+ var API = {
5659 showChatRoom : function ( room ) {
5760
5861 /* called to show a specific room
5962 * i.e. to switch between rooms
6063 */
6164
65+ if ( ! roomControllers . hasOwnProperty ( room ) ) {
66+ createChatRoom ( room ) ;
67+ }
68+
6269 roomControllers [ room ] . showRoom ( ) ;
6370
6471 } ,
@@ -86,8 +93,6 @@ function (
8693 communicator . vent . on ( "login:submit" , function ( room ) {
8794 communicator . command . execute ( "ws:connect" ) ;
8895 communicator . vent . on ( "ws:connect" , function ( ) {
89- API . createChatRoom ( room ) ;
90- communicator . vent . trigger ( "chat:create:room" , room ) ;
9196 API . showChat ( ) ;
9297 communicator . vent . trigger ( "chat:show:room" , room ) ;
9398 } ) ;
0 commit comments