diff --git a/src/components/views/context_menus/RoomTagContextMenu.js b/src/components/views/context_menus/RoomTagContextMenu.js index 3637a3a5ee..43fd7a553a 100644 --- a/src/components/views/context_menus/RoomTagContextMenu.js +++ b/src/components/views/context_menus/RoomTagContextMenu.js @@ -21,6 +21,8 @@ var React = require('react'); var classNames = require('classnames'); var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); var dis = require('matrix-react-sdk/lib/dispatcher'); +var DMRoomMap = require('matrix-react-sdk/lib/utils/DMRoomMap'); +var Rooms = require('matrix-react-sdk/lib/Rooms'); module.exports = React.createClass({ displayName: 'RoomTagContextMenu', @@ -32,9 +34,11 @@ module.exports = React.createClass({ }, getInitialState: function() { + const dmRoomMap = new DMRoomMap(MatrixClientPeg.get()); return { isFavourite: this.props.room.tags.hasOwnProperty("m.favourite"), isLowPriority: this.props.room.tags.hasOwnProperty("m.lowpriority"), + isDirectMessage: Boolean(dmRoomMap.getUserIdForRoomId(this.props.room.roomId)), }; }, @@ -113,6 +117,43 @@ module.exports = React.createClass({ } }, + _onClickDM: function() { + const newIsDirectMessage = !this.state.isDirectMessage; + this.setState({ + isDirectMessage: newIsDirectMessage, + }); + + if (MatrixClientPeg.get().isGuest()) return; + + let newTarget; + if (newIsDirectMessage) { + const guessedTarget = Rooms.guessDMRoomTarget( + this.props.room, + this.props.room.getMember(MatrixClientPeg.get().credentials.userId), + ); + newTarget = guessedTarget.userId; + } else { + newTarget = null; + } + + // give some time for the user to see the icon change first, since + // this will hide the context menu once it completes + q.delay(500).done(() => { + return Rooms.setDMRoom(this.props.room.roomId, newTarget).finally(() => { + // Close the context menu + if (this.props.onFinished) { + this.props.onFinished(); + }; + }, (err) => { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Failed to set Direct Message status of room", + description: err.toString() + }); + }); + }); + }, + _onClickLeave: function() { // Leave room dis.dispatch({ @@ -146,27 +187,33 @@ module.exports = React.createClass({ }, render: function() { - var myUserId = MatrixClientPeg.get().credentials.userId; - var myMember = this.props.room.getMember(myUserId); + const myUserId = MatrixClientPeg.get().credentials.userId; + const myMember = this.props.room.getMember(myUserId); - var favouriteClasses = classNames({ + const favouriteClasses = classNames({ 'mx_RoomTagContextMenu_field': true, 'mx_RoomTagContextMenu_fieldSet': this.state.isFavourite, 'mx_RoomTagContextMenu_fieldDisabled': false, }); - var lowPriorityClasses = classNames({ + const lowPriorityClasses = classNames({ 'mx_RoomTagContextMenu_field': true, 'mx_RoomTagContextMenu_fieldSet': this.state.isLowPriority, 'mx_RoomTagContextMenu_fieldDisabled': false, }); - var leaveClasses = classNames({ + const leaveClasses = classNames({ 'mx_RoomTagContextMenu_field': true, 'mx_RoomTagContextMenu_fieldSet': false, 'mx_RoomTagContextMenu_fieldDisabled': false, }); + const dmClasses = classNames({ + 'mx_RoomTagContextMenu_field': true, + 'mx_RoomTagContextMenu_fieldSet': this.state.isDirectMessage, + 'mx_RoomTagContextMenu_fieldDisabled': false, + }); + if (myMember && myMember.membership === "leave") { return (
@@ -190,6 +237,11 @@ module.exports = React.createClass({ Low Priority
+
+ + + Direct Message +

diff --git a/src/skins/vector/img/icon_context_person.svg b/src/skins/vector/img/icon_context_person.svg new file mode 100644 index 0000000000..fff019d377 --- /dev/null +++ b/src/skins/vector/img/icon_context_person.svg @@ -0,0 +1,85 @@ + + + + + + image/svg+xml + + 81230A28-D944-4572-B5DB-C03CAA2B1FCA + + + + + + 81230A28-D944-4572-B5DB-C03CAA2B1FCA + Created with sketchtool. + + + + + + + + + + diff --git a/src/skins/vector/img/icon_context_person_on.svg b/src/skins/vector/img/icon_context_person_on.svg new file mode 100644 index 0000000000..362944332d --- /dev/null +++ b/src/skins/vector/img/icon_context_person_on.svg @@ -0,0 +1,85 @@ + + + + + + image/svg+xml + + 81230A28-D944-4572-B5DB-C03CAA2B1FCA + + + + + + 81230A28-D944-4572-B5DB-C03CAA2B1FCA + Created with sketchtool. + + + + + + + + + + diff --git a/src/skins/vector/img/icons-people.svg b/src/skins/vector/img/icons-people.svg deleted file mode 100644 index d6867a3f3a..0000000000 --- a/src/skins/vector/img/icons-people.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - -