@@ -52,6 +52,18 @@ module.exports = React.createClass({
52
52
} ,
53
53
54
54
componentDidMount : function ( ) {
55
+ this . getPublicRooms ( ) ;
56
+ } ,
57
+
58
+ componentWillUnmount : function ( ) {
59
+ // dis.dispatch({
60
+ // action: 'ui_opacity',
61
+ // sideOpacity: 1.0,
62
+ // middleOpacity: 1.0,
63
+ // });
64
+ } ,
65
+
66
+ getPublicRooms : function ( ) {
55
67
var self = this ;
56
68
MatrixClientPeg . get ( ) . publicRooms ( function ( err , data ) {
57
69
if ( err ) {
@@ -68,54 +80,80 @@ module.exports = React.createClass({
68
80
publicRooms : data . chunk ,
69
81
loading : false ,
70
82
} ) ;
71
- self . forceUpdate ( ) ;
72
83
}
73
84
} ) ;
74
85
} ,
75
86
76
- componentWillUnmount : function ( ) {
77
- // dis.dispatch({
78
- // action: 'ui_opacity',
79
- // sideOpacity: 1.0,
80
- // middleOpacity: 1.0,
81
- // });
82
- } ,
87
+ /**
88
+ * A limited interface for removing rooms from the directory.
89
+ * Will set the room to not be publicly visible and delete the
90
+ * default alias. In the long term, it would be better to allow
91
+ * HS admins to do this through the RoomSettings interface, but
92
+ * this needs SPEC-417.
93
+ */
94
+ removeFromDirectory : function ( room ) {
95
+ var alias = get_display_alias_for_room ( room ) ;
96
+ var name = room . name || alias || "Unnamed room" ;
83
97
84
- showRoom : function ( roomId , roomAlias ) {
85
- // extract the metadata from the publicRooms structure to pass
86
- // as out-of-band data to view_room, because we get information
87
- // here that we can't get other than by joining the room in some
88
- // cases.
89
- var room ;
90
- if ( roomId ) {
91
- for ( var i = 0 ; i < this . state . publicRooms . length ; ++ i ) {
92
- if ( this . state . publicRooms [ i ] . room_id == roomId ) {
93
- room = this . state . publicRooms [ i ] ;
94
- break ;
95
- }
98
+ var QuestionDialog = sdk . getComponent ( "dialogs.QuestionDialog" ) ;
99
+ var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
100
+
101
+ Modal . createDialog ( QuestionDialog , {
102
+ title : "Remove from Directory" ,
103
+ description : `Delete the room alias '${ alias } ' and remove '${ name } ' from the directory?` ,
104
+ onFinished : ( should_delete ) => {
105
+ if ( ! should_delete ) return ;
106
+
107
+ var Loader = sdk . getComponent ( "elements.Spinner" ) ;
108
+ var modal = Modal . createDialog ( Loader ) ;
109
+ var step = `remove '${ name } ' from the directory.` ;
110
+
111
+ MatrixClientPeg . get ( ) . setRoomDirectoryVisibility ( room . room_id , 'private' ) . then ( ( ) => {
112
+ step = 'delete the alias.' ;
113
+ return MatrixClientPeg . get ( ) . deleteAlias ( alias ) ;
114
+ } ) . done ( ( ) => {
115
+ modal . close ( ) ;
116
+ this . getPublicRooms ( ) ;
117
+ } , function ( err ) {
118
+ modal . close ( ) ;
119
+ this . getPublicRooms ( ) ;
120
+ Modal . createDialog ( ErrorDialog , {
121
+ title : "Failed to " + step ,
122
+ description : err . toString ( )
123
+ } ) ;
124
+ } ) ;
96
125
}
126
+ } ) ;
127
+ } ,
128
+
129
+ showRoom : function ( room , ev ) {
130
+ if ( ev . shiftKey ) {
131
+ ev . preventDefault ( ) ;
132
+ this . removeFromDirectory ( room ) ;
133
+ return ;
97
134
}
135
+
98
136
var oob_data = { } ;
99
- if ( room ) {
100
- if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
101
- if ( ! room . world_readable && ! room . guest_can_join ) {
102
- var NeedToRegisterDialog = sdk . getComponent ( "dialogs.NeedToRegisterDialog" ) ;
103
- Modal . createDialog ( NeedToRegisterDialog , {
104
- title : "Failed to join the room" ,
105
- description : "This room is inaccessible to guests. You may be able to join if you register."
106
- } ) ;
107
- return ;
108
- }
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 ;
109
145
}
110
-
111
- oob_data = {
112
- avatarUrl : room . avatar_url ,
113
- // XXX: This logic is duplicated from the JS SDK which
114
- // would normally decide what the name is.
115
- name : room . name || room . canonical_alias || ( room . aliases ? room . aliases [ 0 ] : "Unnamed room" ) ,
116
- } ;
117
146
}
118
147
148
+ var room_alias = get_display_alias_for_room ( room ) ;
149
+
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
+ } ;
156
+
119
157
var payload = {
120
158
oob_data : oob_data ,
121
159
action : 'view_room' ,
@@ -124,10 +162,10 @@ module.exports = React.createClass({
124
162
// which servers to start querying. However, there's no other way to join rooms in
125
163
// this list without aliases at present, so if roomAlias isn't set here we have no
126
164
// choice but to supply the ID.
127
- if ( roomAlias ) {
128
- payload . room_alias = roomAlias ;
165
+ if ( room_alias ) {
166
+ payload . room_alias = room_alias ;
129
167
} else {
130
- payload . room_id = roomId ;
168
+ payload . room_id = room . room_id ;
131
169
}
132
170
dis . dispatch ( payload ) ;
133
171
} ,
@@ -150,8 +188,7 @@ module.exports = React.createClass({
150
188
var self = this ;
151
189
var guestRead , guestJoin , perms ;
152
190
for ( var i = 0 ; i < rooms . length ; i ++ ) {
153
- var alias = rooms [ i ] . canonical_alias || ( rooms [ i ] . aliases ? rooms [ i ] . aliases [ 0 ] : "" ) ;
154
- var name = rooms [ i ] . name || alias || "Unnamed room" ;
191
+ var name = rooms [ i ] . name || get_display_alias_for_room ( rooms [ i ] ) || "Unnamed room" ;
155
192
guestRead = null ;
156
193
guestJoin = null ;
157
194
@@ -175,7 +212,11 @@ module.exports = React.createClass({
175
212
topic = linkifyString ( sanitizeHtml ( topic ) ) ;
176
213
177
214
rows . unshift (
178
- < tr key = { rooms [ i ] . room_id } onClick = { self . showRoom . bind ( null , rooms [ i ] . room_id , alias ) } >
215
+ < tr key = { rooms [ i ] . room_id }
216
+ onClick = { self . showRoom . bind ( null , rooms [ i ] ) }
217
+ // cancel onMouseDown otherwise shift-clicking highlights text
218
+ onMouseDown = { ( ev ) => { ev . preventDefault ( ) ; } }
219
+ >
179
220
< td className = "mx_RoomDirectory_roomAvatar" >
180
221
< BaseAvatar width = { 24 } height = { 24 } resizeMethod = 'crop'
181
222
name = { name } idName = { name }
@@ -189,7 +230,7 @@ module.exports = React.createClass({
189
230
< div className = "mx_RoomDirectory_topic"
190
231
onClick = { function ( e ) { e . stopPropagation ( ) } }
191
232
dangerouslySetInnerHTML = { { __html : topic } } />
192
- < div className = "mx_RoomDirectory_alias" > { alias } </ div >
233
+ < div className = "mx_RoomDirectory_alias" > { get_display_alias_for_room ( rooms [ i ] ) } </ div >
193
234
</ td >
194
235
< td className = "mx_RoomDirectory_roomMemberCount" >
195
236
{ rooms [ i ] . num_joined_members }
@@ -237,3 +278,9 @@ module.exports = React.createClass({
237
278
) ;
238
279
}
239
280
} ) ;
281
+
282
+ // Similar to matrix-react-sdk's MatrixTools.getDisplayAliasForRoom
283
+ // but works with the objects we get from the public room list
284
+ function get_display_alias_for_room ( room ) {
285
+ return room . canonical_alias || ( room . aliases ? room . aliases [ 0 ] : "" ) ;
286
+ }
0 commit comments