@@ -20,6 +20,7 @@ limitations under the License.
2020import Promise from 'bluebird' ;
2121import React from 'react' ;
2222import classNames from 'classnames' ;
23+ import PropTypes from 'prop-types' ;
2324import sdk from 'matrix-react-sdk' ;
2425import { _t , _td } from 'matrix-react-sdk/lib/languageHandler' ;
2526import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg' ;
@@ -28,14 +29,15 @@ import DMRoomMap from 'matrix-react-sdk/lib/utils/DMRoomMap';
2829import * as Rooms from 'matrix-react-sdk/lib/Rooms' ;
2930import * as RoomNotifs from 'matrix-react-sdk/lib/RoomNotifs' ;
3031import Modal from 'matrix-react-sdk/lib/Modal' ;
32+ import RoomListActions from 'matrix-react-sdk/lib/actions/RoomListActions' ;
3133
3234module . exports = React . createClass ( {
3335 displayName : 'RoomTileContextMenu' ,
3436
3537 propTypes : {
36- room : React . PropTypes . object . isRequired ,
38+ room : PropTypes . object . isRequired ,
3739 /* callback called when the menu is dismissed */
38- onFinished : React . PropTypes . func ,
40+ onFinished : PropTypes . func ,
3941 } ,
4042
4143 getInitialState ( ) {
@@ -45,7 +47,7 @@ module.exports = React.createClass({
4547 isFavourite : this . props . room . tags . hasOwnProperty ( "m.favourite" ) ,
4648 isLowPriority : this . props . room . tags . hasOwnProperty ( "m.lowpriority" ) ,
4749 isDirectMessage : Boolean ( dmRoomMap . getUserIdForRoomId ( this . props . room . roomId ) ) ,
48- }
50+ } ;
4951 } ,
5052
5153 componentWillMount : function ( ) {
@@ -132,22 +134,22 @@ module.exports = React.createClass({
132134 } ,
133135
134136 _onClickDM : function ( ) {
137+ if ( MatrixClientPeg . get ( ) . isGuest ( ) ) return ;
138+
135139 const newIsDirectMessage = ! this . state . isDirectMessage ;
136140 this . setState ( {
137141 isDirectMessage : newIsDirectMessage ,
138142 } ) ;
139143
140- if ( MatrixClientPeg . get ( ) . isGuest ( ) ) return ;
141-
142144 Rooms . guessAndSetDMRoom (
143- this . props . room , newIsDirectMessage
145+ this . props . room , newIsDirectMessage ,
144146 ) . delay ( 500 ) . finally ( ( ) => {
145147 // Close the context menu
146148 if ( this . props . onFinished ) {
147149 this . props . onFinished ( ) ;
148- } ;
150+ }
149151 } , ( err ) => {
150- var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
152+ const ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
151153 Modal . createTrackedDialog ( 'Failed to set Direct Message status of room' , '' , ErrorDialog , {
152154 title : _t ( 'Failed to set Direct Message status of room' ) ,
153155 description : ( ( err && err . message ) ? err . message : _t ( 'Operation failed' ) ) ,
@@ -165,7 +167,7 @@ module.exports = React.createClass({
165167 // Close the context menu
166168 if ( this . props . onFinished ) {
167169 this . props . onFinished ( ) ;
168- } ;
170+ }
169171 } ,
170172
171173 _onClickReject : function ( ) {
@@ -177,16 +179,16 @@ module.exports = React.createClass({
177179 // Close the context menu
178180 if ( this . props . onFinished ) {
179181 this . props . onFinished ( ) ;
180- } ;
182+ }
181183 } ,
182184
183185 _onClickForget : function ( ) {
184186 // FIXME: duplicated with RoomSettings (and dead code in RoomView)
185187 MatrixClientPeg . get ( ) . forget ( this . props . room . roomId ) . done ( function ( ) {
186188 dis . dispatch ( { action : 'view_next_room' } ) ;
187189 } , function ( err ) {
188- var errCode = err . errcode || _td ( "unknown error code" ) ;
189- var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
190+ const errCode = err . errcode || _td ( "unknown error code" ) ;
191+ const ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
190192 Modal . createTrackedDialog ( 'Failed to forget room' , '' , ErrorDialog , {
191193 title : _t ( 'Failed to forget room %(errCode)s' , { errCode : errCode } ) ,
192194 description : ( ( err && err . message ) ? err . message : _t ( 'Operation failed' ) ) ,
@@ -196,28 +198,27 @@ module.exports = React.createClass({
196198 // Close the context menu
197199 if ( this . props . onFinished ) {
198200 this . props . onFinished ( ) ;
199- } ;
201+ }
200202 } ,
201203
202204 _saveNotifState : function ( newState ) {
205+ if ( MatrixClientPeg . get ( ) . isGuest ( ) ) return ;
206+
203207 const oldState = this . state . roomNotifState ;
204208 const roomId = this . props . room . roomId ;
205- var cli = MatrixClientPeg . get ( ) ;
206-
207- if ( cli . isGuest ( ) ) return ;
208209
209210 this . setState ( {
210211 roomNotifState : newState ,
211212 } ) ;
212- RoomNotifs . setRoomNotifsState ( this . props . room . roomId , newState ) . done ( ( ) => {
213+ RoomNotifs . setRoomNotifsState ( roomId , newState ) . done ( ( ) => {
213214 // delay slightly so that the user can see their state change
214215 // before closing the menu
215216 return Promise . delay ( 500 ) . then ( ( ) => {
216217 if ( this . _unmounted ) return ;
217218 // Close the context menu
218219 if ( this . props . onFinished ) {
219220 this . props . onFinished ( ) ;
220- } ;
221+ }
221222 } ) ;
222223 } , ( error ) => {
223224 // TODO: some form of error notification to the user
@@ -247,22 +248,22 @@ module.exports = React.createClass({
247248 } ,
248249
249250 _renderNotifMenu : function ( ) {
250- var alertMeClasses = classNames ( {
251+ const alertMeClasses = classNames ( {
251252 'mx_RoomTileContextMenu_notif_field' : true ,
252253 'mx_RoomTileContextMenu_notif_fieldSet' : this . state . roomNotifState == RoomNotifs . ALL_MESSAGES_LOUD ,
253254 } ) ;
254255
255- var allNotifsClasses = classNames ( {
256+ const allNotifsClasses = classNames ( {
256257 'mx_RoomTileContextMenu_notif_field' : true ,
257258 'mx_RoomTileContextMenu_notif_fieldSet' : this . state . roomNotifState == RoomNotifs . ALL_MESSAGES ,
258259 } ) ;
259260
260- var mentionsClasses = classNames ( {
261+ const mentionsClasses = classNames ( {
261262 'mx_RoomTileContextMenu_notif_field' : true ,
262263 'mx_RoomTileContextMenu_notif_fieldSet' : this . state . roomNotifState == RoomNotifs . MENTIONS_ONLY ,
263264 } ) ;
264265
265- var muteNotifsClasses = classNames ( {
266+ const muteNotifsClasses = classNames ( {
266267 'mx_RoomTileContextMenu_notif_field' : true ,
267268 'mx_RoomTileContextMenu_notif_fieldSet' : this . state . roomNotifState == RoomNotifs . MUTE ,
268269 } ) ;
@@ -272,22 +273,22 @@ module.exports = React.createClass({
272273 < div className = "mx_RoomTileContextMenu_notif_picker" >
273274 < img src = "img/notif-slider.svg" width = "20" height = "107" />
274275 </ div >
275- < div className = { alertMeClasses } onClick = { this . _onClickAlertMe } >
276+ < div className = { alertMeClasses } onClick = { this . _onClickAlertMe } >
276277 < img className = "mx_RoomTileContextMenu_notif_activeIcon" src = "img/notif-active.svg" width = "12" height = "12" />
277278 < img className = "mx_RoomTileContextMenu_notif_icon mx_filterFlipColor" src = "img/icon-context-mute-off-copy.svg" width = "16" height = "12" />
278279 { _t ( 'All messages (noisy)' ) }
279280 </ div >
280- < div className = { allNotifsClasses } onClick = { this . _onClickAllNotifs } >
281+ < div className = { allNotifsClasses } onClick = { this . _onClickAllNotifs } >
281282 < img className = "mx_RoomTileContextMenu_notif_activeIcon" src = "img/notif-active.svg" width = "12" height = "12" />
282283 < img className = "mx_RoomTileContextMenu_notif_icon mx_filterFlipColor" src = "img/icon-context-mute-off.svg" width = "16" height = "12" />
283284 { _t ( 'All messages' ) }
284285 </ div >
285- < div className = { mentionsClasses } onClick = { this . _onClickMentions } >
286+ < div className = { mentionsClasses } onClick = { this . _onClickMentions } >
286287 < img className = "mx_RoomTileContextMenu_notif_activeIcon" src = "img/notif-active.svg" width = "12" height = "12" />
287288 < img className = "mx_RoomTileContextMenu_notif_icon mx_filterFlipColor" src = "img/icon-context-mute-mentions.svg" width = "16" height = "12" />
288289 { _t ( 'Mentions only' ) }
289290 </ div >
290- < div className = { muteNotifsClasses } onClick = { this . _onClickMute } >
291+ < div className = { muteNotifsClasses } onClick = { this . _onClickMute } >
291292 < img className = "mx_RoomTileContextMenu_notif_activeIcon" src = "img/notif-active.svg" width = "12" height = "12" />
292293 < img className = "mx_RoomTileContextMenu_notif_icon mx_filterFlipColor" src = "img/icon-context-mute.svg" width = "16" height = "12" />
293294 { _t ( 'Mute' ) }
@@ -322,7 +323,7 @@ module.exports = React.createClass({
322323
323324 return (
324325 < div >
325- < div className = "mx_RoomTileContextMenu_leave" onClick = { leaveClickHandler } >
326+ < div className = "mx_RoomTileContextMenu_leave" onClick = { leaveClickHandler } >
326327 < img className = "mx_RoomTileContextMenu_tag_icon" src = "img/icon_context_delete.svg" width = "15" height = "15" />
327328 { leaveText }
328329 </ div >
@@ -351,17 +352,17 @@ module.exports = React.createClass({
351352
352353 return (
353354 < div >
354- < div className = { favouriteClasses } onClick = { this . _onClickFavourite } >
355+ < div className = { favouriteClasses } onClick = { this . _onClickFavourite } >
355356 < img className = "mx_RoomTileContextMenu_tag_icon" src = "img/icon_context_fave.svg" width = "15" height = "15" />
356357 < img className = "mx_RoomTileContextMenu_tag_icon_set" src = "img/icon_context_fave_on.svg" width = "15" height = "15" />
357358 { _t ( 'Favourite' ) }
358359 </ div >
359- < div className = { lowPriorityClasses } onClick = { this . _onClickLowPriority } >
360+ < div className = { lowPriorityClasses } onClick = { this . _onClickLowPriority } >
360361 < img className = "mx_RoomTileContextMenu_tag_icon" src = "img/icon_context_low.svg" width = "15" height = "15" />
361362 < img className = "mx_RoomTileContextMenu_tag_icon_set" src = "img/icon_context_low_on.svg" width = "15" height = "15" />
362363 { _t ( 'Low Priority' ) }
363364 </ div >
364- < div className = { dmClasses } onClick = { this . _onClickDM } >
365+ < div className = { dmClasses } onClick = { this . _onClickDM } >
365366 < img className = "mx_RoomTileContextMenu_tag_icon" src = "img/icon_context_person.svg" width = "15" height = "15" />
366367 < img className = "mx_RoomTileContextMenu_tag_icon_set" src = "img/icon_context_person_on.svg" width = "15" height = "15" />
367368 { _t ( 'Direct Chat' ) }
@@ -372,7 +373,7 @@ module.exports = React.createClass({
372373
373374 render : function ( ) {
374375 const myMember = this . props . room . getMember (
375- MatrixClientPeg . get ( ) . credentials . userId
376+ MatrixClientPeg . get ( ) . credentials . userId ,
376377 ) ;
377378
378379 // Can't set notif level or tags on non-join rooms
@@ -389,5 +390,5 @@ module.exports = React.createClass({
389390 { this . _renderRoomTagMenu ( ) }
390391 </ div >
391392 ) ;
392- }
393+ } ,
393394} ) ;
0 commit comments