@@ -126,38 +126,48 @@ module.exports = React.createClass({
126
126
} ) ;
127
127
} ,
128
128
129
- showRoom : function ( room , ev ) {
129
+ onRoomClicked : function ( room , ev ) {
130
130
if ( ev . shiftKey ) {
131
131
ev . preventDefault ( ) ;
132
132
this . removeFromDirectory ( room ) ;
133
- return ;
133
+ } else {
134
+ this . showRoom ( room ) ;
134
135
}
136
+ } ,
135
137
138
+ showRoomAlias : function ( alias ) {
139
+ this . showRoom ( null , alias ) ;
140
+ } ,
141
+
142
+ showRoom : function ( room , room_alias ) {
136
143
var oob_data = { } ;
137
- if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
138
- if ( ! room . world_readable && ! room . guest_can_join ) {
139
- var NeedToRegisterDialog = sdk . getComponent ( "dialogs.NeedToRegisterDialog" ) ;
140
- Modal . createDialog ( NeedToRegisterDialog , {
141
- title : "Failed to join the room" ,
142
- description : "This room is inaccessible to guests. You may be able to join if you register."
143
- } ) ;
144
- return ;
144
+ var payload = { action : 'view_room' } ;
145
+ if ( room ) {
146
+ // Don't let the user view a room they won't be able to either
147
+ // peek or join: fail earlier so they don't have to click back
148
+ // to the directory.
149
+ if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
150
+ if ( ! room . world_readable && ! room . guest_can_join ) {
151
+ var NeedToRegisterDialog = sdk . getComponent ( "dialogs.NeedToRegisterDialog" ) ;
152
+ Modal . createDialog ( NeedToRegisterDialog , {
153
+ title : "Failed to join the room" ,
154
+ description : "This room is inaccessible to guests. You may be able to join if you register."
155
+ } ) ;
156
+ return ;
157
+ }
145
158
}
146
- }
147
-
148
- var room_alias = get_display_alias_for_room ( room ) ;
149
159
150
- oob_data = {
151
- avatarUrl : room . avatar_url ,
152
- // XXX: This logic is duplicated from the JS SDK which
153
- // would normally decide what the name is.
154
- name : room . name || room_alias || "Unnamed room" ,
155
- } ;
160
+ if ( ! room_alias ) {
161
+ room_alias = get_display_alias_for_room ( room ) ;
162
+ }
156
163
157
- var payload = {
158
- oob_data : oob_data ,
159
- action : 'view_room' ,
160
- } ;
164
+ payload . oob_data = {
165
+ avatarUrl : room . avatar_url ,
166
+ // XXX: This logic is duplicated from the JS SDK which
167
+ // would normally decide what the name is.
168
+ name : room . name || room_alias || "Unnamed room" ,
169
+ } ;
170
+ }
161
171
// It's not really possible to join Matrix rooms by ID because the HS has no way to know
162
172
// which servers to start querying. However, there's no other way to join rooms in
163
173
// this list without aliases at present, so if roomAlias isn't set here we have no
@@ -213,7 +223,7 @@ module.exports = React.createClass({
213
223
214
224
rows . unshift (
215
225
< tr key = { rooms [ i ] . room_id }
216
- onClick = { self . showRoom . bind ( null , rooms [ i ] ) }
226
+ onClick = { self . onRoomClicked . bind ( self , rooms [ i ] ) }
217
227
// cancel onMouseDown otherwise shift-clicking highlights text
218
228
onMouseDown = { ( ev ) => { ev . preventDefault ( ) ; } }
219
229
>
@@ -245,7 +255,7 @@ module.exports = React.createClass({
245
255
this . forceUpdate ( ) ;
246
256
this . setState ( { roomAlias : this . refs . roomAlias . value } )
247
257
if ( ev . key == "Enter" ) {
248
- this . showRoom ( null , this . refs . roomAlias . value ) ;
258
+ this . showRoomAlias ( this . refs . roomAlias . value ) ;
249
259
}
250
260
} ,
251
261
0 commit comments