From a1f8116e3bd5ac0bf916bf61e913f0adadbe7353 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 7 Sep 2016 17:47:47 +0100 Subject: [PATCH 1/2] Support toggling DM status of rooms on context menu --- .../views/context_menus/RoomTagContextMenu.js | 60 +++++++++++-- src/skins/vector/img/icon_context_person.svg | 85 +++++++++++++++++++ .../vector/img/icon_context_person_on.svg | 85 +++++++++++++++++++ src/skins/vector/img/icons-people.svg | 9 -- 4 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 src/skins/vector/img/icon_context_person.svg create mode 100644 src/skins/vector/img/icon_context_person_on.svg delete mode 100644 src/skins/vector/img/icons-people.svg diff --git a/src/components/views/context_menus/RoomTagContextMenu.js b/src/components/views/context_menus/RoomTagContextMenu.js index 3637a3a5..f0dc5f07 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,41 @@ 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; + } + + 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 +185,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 +235,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 00000000..fff019d3 --- /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 00000000..36294433 --- /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 d6867a3f..00000000 --- a/src/skins/vector/img/icons-people.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - From 74aef1fdadac41a1e1d65f39f5d40be1f499ba96 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 8 Sep 2016 13:58:53 +0100 Subject: [PATCH 2/2] Comment delay --- src/components/views/context_menus/RoomTagContextMenu.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/views/context_menus/RoomTagContextMenu.js b/src/components/views/context_menus/RoomTagContextMenu.js index f0dc5f07..43fd7a55 100644 --- a/src/components/views/context_menus/RoomTagContextMenu.js +++ b/src/components/views/context_menus/RoomTagContextMenu.js @@ -136,6 +136,8 @@ module.exports = React.createClass({ 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