Pin/unpin message option in a message's context menu

Signed-off-by: Travis Ralston <travpc@gmail.com>
pull/5142/head
Travis Ralston 2017-09-28 09:42:33 -06:00
parent f35289a664
commit 774c3dbd38
3 changed files with 34 additions and 0 deletions

View File

@ -65,6 +65,13 @@ module.exports = React.createClass({
this.setState({canRedact}); 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() { onResendClick: function() {
Resend.resend(this.props.mxEvent); Resend.resend(this.props.mxEvent);
this.closeMenu(); this.closeMenu();
@ -122,6 +129,22 @@ module.exports = React.createClass({
this.closeMenu(); 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() { closeMenu: function() {
if (this.props.onFinished) this.props.onFinished(); if (this.props.onFinished) this.props.onFinished();
}, },
@ -147,6 +170,7 @@ module.exports = React.createClass({
let redactButton; let redactButton;
let cancelButton; let cancelButton;
let forwardButton; let forwardButton;
let pinButton;
let viewSourceButton; let viewSourceButton;
let viewClearSourceButton; let viewClearSourceButton;
let unhidePreviewButton; let unhidePreviewButton;
@ -186,6 +210,11 @@ module.exports = React.createClass({
{ _t('Forward Message') } { _t('Forward Message') }
</div> </div>
); );
pinButton = (
<div className="mx_MessageContextMenu_field" onClick={this.onPinClick}>
{ this._isPinned() ? _t('Unpin Message') : _t('Pin Message') }
</div>
);
} }
} }
@ -246,6 +275,7 @@ module.exports = React.createClass({
{redactButton} {redactButton}
{cancelButton} {cancelButton}
{forwardButton} {forwardButton}
{pinButton}
{viewSourceButton} {viewSourceButton}
{viewClearSourceButton} {viewClearSourceButton}
{unhidePreviewButton} {unhidePreviewButton}

View File

@ -213,6 +213,8 @@
"You have successfully set a password!": "You have successfully set a password!", "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.", "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", "Continue": "Continue",
"Pin Message": "Pin Message",
"Unpin Message": "Unpin Message",
"Please set a password!": "Please set a password!", "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.", "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!", "You have successfully set a password and an email address!": "You have successfully set a password and an email address!",

View File

@ -199,6 +199,8 @@
"You have successfully set a password and an email address!": "You have successfully set a password and an email address!", "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.", "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", "Warning": "Warning",
"Pin Message": "Pin Message",
"Unpin Message": "Unpin Message",
"Checking for an update...": "Checking for an update...", "Checking for an update...": "Checking for an update...",
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).", "Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
"No update available.": "No update available.", "No update available.": "No update available.",