@@ -32,63 +32,85 @@ module.exports = React.createClass({
3232 } ,
3333
3434 getInitialState : function ( ) {
35- // var areNotifsMuted = false;
36- // var cli = MatrixClientPeg.get();
37- // if (!cli.isGuest()) {
38- // var roomPushRule = cli.getRoomPushRule("global", this.props.room.roomId);
39- // if (roomPushRule) {
40- // if (0 <= roomPushRule.actions.indexOf("dont_notify")) {
41- // areNotifsMuted = true;
42- // }
43- // }
44- // }
45- //
46- // return {
47- // areNotifsMuted: areNotifsMuted,
48- // };
49- return null ;
35+ return {
36+ isFavourite : this . props . room . tags . hasOwnProperty ( "m.favourite" ) ,
37+ isLowPriority : this . props . room . tags . hasOwnProperty ( "m.lowpriority" ) ,
38+ } ;
5039 } ,
5140
52- // _save: function( isMuted ) {
53- // var self = this;
54- // const roomId = this.props.room.roomId;
55- // var cli = MatrixClientPeg.get();
56- //
57- // if (!cli.isGuest()) {
58- // cli.setRoomMutePushRule(
59- // "global", roomId, isMuted
60- // ).then(function() {
61- // self.setState({areNotifsMuted: isMuted});
62- //
63- // // delay slightly so that the user can see their state change
64- // // before closing the menu
65- // q.delay(500).then(function() {
66- // // tell everyone that wants to know of the change in
67- // // notification state
68- // dis.dispatch({
69- // action: 'notification_change',
70- // roomId: self.props.room.roomId,
71- // isMuted: isMuted,
72- // });
73- //
74- // // Close the context menu
75- // if (self.props.onFinished) {
76- // self.props.onFinished();
77- // };
78- // });
79- // }).fail(function(error) {
80- // // TODO: some form of error notification to the user
81- // // to inform them that their state change failed.
82- // });
83- // }
84- // },
41+ _toggleTag : function ( tagNameOn , tagNameOff ) {
42+ console . log ( "DEBUG: _toggleTag" ) ;
43+ console . log ( "tagNameOn: " + tagNameOn + " tagNameOff: " + tagNameOff ) ;
44+ var self = this ;
45+ const roomId = this . props . room . roomId ;
46+ var cli = MatrixClientPeg . get ( ) ;
47+ if ( ! cli . isGuest ( ) ) {
48+ q . delay ( 500 ) . then ( function ( ) {
49+ if ( tagNameOff !== null && tagNameOff !== undefined ) {
50+ cli . deleteRoomTag ( roomId , tagNameOff ) . finally ( function ( ) {
51+ // Close the context menu
52+ if ( self . props . onFinished ) {
53+ self . props . onFinished ( ) ;
54+ } ;
55+ } ) . fail ( function ( err ) {
56+ var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
57+ Modal . createDialog ( ErrorDialog , {
58+ title : "Failed to remove tag " + tagNameOff + " from room" ,
59+ description : err . toString ( )
60+ } ) ;
61+ } ) ;
62+ }
63+
64+ if ( tagNameOn !== null && tagNameOn !== undefined ) {
65+ cli . setRoomTag ( roomId , tagNameOn , { } ) . finally ( function ( ) {
66+ // Close the context menu
67+ if ( self . props . onFinished ) {
68+ self . props . onFinished ( ) ;
69+ } ;
70+ } ) . fail ( function ( err ) {
71+ var ErrorDialog = sdk . getComponent ( "dialogs.ErrorDialog" ) ;
72+ Modal . createDialog ( ErrorDialog , {
73+ title : "Failed to add tag " + tagNameOn + " to room" ,
74+ description : err . toString ( )
75+ } ) ;
76+ } ) ;
77+ }
78+ } ) ;
79+ }
80+ } ,
8581
8682 _onClickFavourite : function ( ) {
8783 // Tag room as 'Favourite'
84+ if ( ! this . state . isFavourite && this . state . isLowPriority ) {
85+ this . setState ( {
86+ isFavourite : true ,
87+ isLowPriority : false ,
88+ } ) ;
89+ this . _toggleTag ( "m.favourite" , "m.lowpriority" ) ;
90+ } else if ( this . state . isFavourite ) {
91+ this . setState ( { isFavourite : false } ) ;
92+ this . _toggleTag ( null , "m.favourite" ) ;
93+ } else if ( ! this . state . isFavourite ) {
94+ this . setState ( { isFavourite : true } ) ;
95+ this . _toggleTag ( "m.favourite" ) ;
96+ }
8897 } ,
8998
9099 _onClickLowPriority : function ( ) {
91100 // Tag room as 'Low Priority'
101+ if ( ! this . state . isLowPriority && this . state . isFavourite ) {
102+ this . setState ( {
103+ isFavourite : false ,
104+ isLowPriority : true ,
105+ } ) ;
106+ this . _toggleTag ( "m.lowpriority" , "m.favourite" ) ;
107+ } else if ( this . state . isLowPriority ) {
108+ this . setState ( { isLowPriority : false } ) ;
109+ this . _toggleTag ( null , "m.lowpriority" ) ;
110+ } else if ( ! this . state . isLowPriority ) {
111+ this . setState ( { isLowPriority : true } ) ;
112+ this . _toggleTag ( "m.lowpriority" ) ;
113+ }
92114 } ,
93115
94116 _onClickLeave : function ( ) {
@@ -100,13 +122,13 @@ module.exports = React.createClass({
100122
101123 var favouriteClasses = classNames ( {
102124 'mx_RoomTagContextMenu_field' : true ,
103- 'mx_RoomTagContextMenu_fieldSet' : false ,
125+ 'mx_RoomTagContextMenu_fieldSet' : this . state . isFavourite ,
104126 'mx_RoomTagContextMenu_fieldDisabled' : false ,
105127 } ) ;
106128
107129 var lowPriorityClasses = classNames ( {
108130 'mx_RoomTagContextMenu_field' : true ,
109- 'mx_RoomTagContextMenu_fieldSet' : false ,
131+ 'mx_RoomTagContextMenu_fieldSet' : this . state . isLowPriority ,
110132 'mx_RoomTagContextMenu_fieldDisabled' : false ,
111133 } ) ;
112134
@@ -119,16 +141,16 @@ module.exports = React.createClass({
119141 return (
120142 < div >
121143 < div className = { favouriteClasses } onClick = { this . _onClickFavourite } >
122- < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-fave.svg" width = "13 " height = "13 " />
144+ < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-fave.svg" width = "15 " height = "15 " />
123145 Favourite
124146 </ div >
125147 < div className = { lowPriorityClasses } onClick = { this . _onClickLowPriority } >
126- < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-fave .svg" width = "13 " height = "13 " />
148+ < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-low .svg" width = "15 " height = "15 " />
127149 Low Priority
128150 </ div >
129151 < hr className = "mx_RoomTagContextMenu_separator" />
130152 < div className = { leaveClasses } onClick = { this . _onClickLeave } >
131- < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-fave .svg" width = "13 " height = "13 " />
153+ < img className = "mx_RoomTagContextMenu_icon" src = "img/icon-context-delete .svg" width = "15 " height = "15 " />
132154 Leave
133155 </ div >
134156 </ div >
0 commit comments