From 774c3dbd3851b4b2d8ea9acc35db000c624f01d6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 28 Sep 2017 09:42:33 -0600 Subject: [PATCH] Pin/unpin message option in a message's context menu Signed-off-by: Travis Ralston --- .../views/context_menus/MessageContextMenu.js | 30 +++++++++++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/i18n/strings/en_US.json | 2 ++ 3 files changed, 34 insertions(+) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index d6d9302fd..09503f99f 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -65,6 +65,13 @@ module.exports = React.createClass({ this.setState({canRedact}); }, + _isPinned: function() { + const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); + const pinnedEvent = room.currentState.getStateEvents('m.room.pinned_events', ''); + if (!pinnedEvent) return false; + return pinnedEvent.getContent().pinned.includes(this.props.mxEvent.getId()); + }, + onResendClick: function() { Resend.resend(this.props.mxEvent); this.closeMenu(); @@ -122,6 +129,22 @@ module.exports = React.createClass({ this.closeMenu(); }, + onPinClick: function() { + MatrixClientPeg.get().getStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', '').then(event => { + const eventIds = (event ? event.pinned : []) || []; + if (!eventIds.includes(this.props.mxEvent.getId())) { + // Not pinned - add + eventIds.push(this.props.mxEvent.getId()); + } else { + // Pinned - remove + eventIds.splice(eventIds.indexOf(this.props.mxEvent.getId()), 1); + } + + MatrixClientPeg.get().sendStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', {pinned: eventIds}, ''); + }); + this.closeMenu(); + }, + closeMenu: function() { if (this.props.onFinished) this.props.onFinished(); }, @@ -147,6 +170,7 @@ module.exports = React.createClass({ let redactButton; let cancelButton; let forwardButton; + let pinButton; let viewSourceButton; let viewClearSourceButton; let unhidePreviewButton; @@ -186,6 +210,11 @@ module.exports = React.createClass({ { _t('Forward Message') } ); + pinButton = ( +
+ { this._isPinned() ? _t('Unpin Message') : _t('Pin Message') } +
+ ); } } @@ -246,6 +275,7 @@ module.exports = React.createClass({ {redactButton} {cancelButton} {forwardButton} + {pinButton} {viewSourceButton} {viewClearSourceButton} {unhidePreviewButton} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 343377466..9b1780f78 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -213,6 +213,8 @@ "You have successfully set a password!": "You have successfully set a password!", "You can now return to your account after signing out, and sign in on other devices.": "You can now return to your account after signing out, and sign in on other devices.", "Continue": "Continue", + "Pin Message": "Pin Message", + "Unpin Message": "Unpin Message", "Please set a password!": "Please set a password!", "This will allow you to return to your account after signing out, and sign in on other devices.": "This will allow you to return to your account after signing out, and sign in on other devices.", "You have successfully set a password and an email address!": "You have successfully set a password and an email address!", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 4eded6160..1d2fc1c97 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -199,6 +199,8 @@ "You have successfully set a password and an email address!": "You have successfully set a password and an email address!", "Remember, you can always set an email address in user settings if you change your mind.": "Remember, you can always set an email address in user settings if you change your mind.", "Warning": "Warning", + "Pin Message": "Pin Message", + "Unpin Message": "Unpin Message", "Checking for an update...": "Checking for an update...", "Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).", "No update available.": "No update available.",