Skip to content

Commit 5a97786

Browse files
committed
Initial pass of the tag menu, still lots of tweaking and bugfixing to do, but most of the mechanics are there now
1 parent 72ba708 commit 5a97786

8 files changed

Lines changed: 154 additions & 64 deletions

File tree

‎src/components/views/context_menus/NotificationStateContextMenu.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = React.createClass({
5757
// Wrapping this in a q promise, as setRoomMutePushRule can return
5858
// a promise or a value
5959
q(cli.setRoomMutePushRule("global", roomId, areNotifsMuted))
60-
.then(function(s) {
60+
.then(function() {
6161
self.setState({areNotifsMuted: areNotifsMuted});
6262

6363
// delay slightly so that the user can see their state change

‎src/components/views/context_menus/RoomTagContextMenu.js‎

Lines changed: 75 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

‎src/skins/vector/css/vector-web/views/context_menus/RoomTagContextMenu.css‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ limitations under the License.
1515
*/
1616

1717
.mx_RoomTagContextMenu_field {
18-
padding-top: 4px;
18+
padding-top: 8px;
1919
padding-right: 20px;
20-
padding-bottom: 10px;
20+
padding-bottom: 8px;
2121
cursor: pointer;
2222
white-space: nowrap;
2323
display: flex;
2424
align-items: center;
2525
}
2626

27+
.mx_RoomTagContextMenu_field:first-child {
28+
padding-top: 4px;
29+
}
30+
31+
.mx_RoomTagContextMenu_field:last-child {
32+
padding-bottom: 4px;
33+
}
34+
2735
.mx_RoomTagContextMenu_field.mx_RoomTagContextMenu_fieldSet {
2836
font-weight: bold;
2937
}
Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

‎src/skins/vector/img/icon-context-fave.svg‎

Lines changed: 7 additions & 8 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)