Skip to content

Commit 774c3db

Browse files
committed
Pin/unpin message option in a message's context menu
Signed-off-by: Travis Ralston <travpc@gmail.com>
1 parent f35289a commit 774c3db

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/components/views/context_menus/MessageContextMenu.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ module.exports = React.createClass({
6565
this.setState({canRedact});
6666
},
6767

68+
_isPinned: function() {
69+
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
70+
const pinnedEvent = room.currentState.getStateEvents('m.room.pinned_events', '');
71+
if (!pinnedEvent) return false;
72+
return pinnedEvent.getContent().pinned.includes(this.props.mxEvent.getId());
73+
},
74+
6875
onResendClick: function() {
6976
Resend.resend(this.props.mxEvent);
7077
this.closeMenu();
@@ -122,6 +129,22 @@ module.exports = React.createClass({
122129
this.closeMenu();
123130
},
124131

132+
onPinClick: function() {
133+
MatrixClientPeg.get().getStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', '').then(event => {
134+
const eventIds = (event ? event.pinned : []) || [];
135+
if (!eventIds.includes(this.props.mxEvent.getId())) {
136+
// Not pinned - add
137+
eventIds.push(this.props.mxEvent.getId());
138+
} else {
139+
// Pinned - remove
140+
eventIds.splice(eventIds.indexOf(this.props.mxEvent.getId()), 1);
141+
}
142+
143+
MatrixClientPeg.get().sendStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', {pinned: eventIds}, '');
144+
});
145+
this.closeMenu();
146+
},
147+
125148
closeMenu: function() {
126149
if (this.props.onFinished) this.props.onFinished();
127150
},
@@ -147,6 +170,7 @@ module.exports = React.createClass({
147170
let redactButton;
148171
let cancelButton;
149172
let forwardButton;
173+
let pinButton;
150174
let viewSourceButton;
151175
let viewClearSourceButton;
152176
let unhidePreviewButton;
@@ -186,6 +210,11 @@ module.exports = React.createClass({
186210
{ _t('Forward Message') }
187211
</div>
188212
);
213+
pinButton = (
214+
<div className="mx_MessageContextMenu_field" onClick={this.onPinClick}>
215+
{ this._isPinned() ? _t('Unpin Message') : _t('Pin Message') }
216+
</div>
217+
);
189218
}
190219
}
191220

@@ -246,6 +275,7 @@ module.exports = React.createClass({
246275
{redactButton}
247276
{cancelButton}
248277
{forwardButton}
278+
{pinButton}
249279
{viewSourceButton}
250280
{viewClearSourceButton}
251281
{unhidePreviewButton}

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@
213213
"You have successfully set a password!": "You have successfully set a password!",
214214
"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.",
215215
"Continue": "Continue",
216+
"Pin Message": "Pin Message",
217+
"Unpin Message": "Unpin Message",
216218
"Please set a password!": "Please set a password!",
217219
"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.",
218220
"You have successfully set a password and an email address!": "You have successfully set a password and an email address!",

src/i18n/strings/en_US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@
199199
"You have successfully set a password and an email address!": "You have successfully set a password and an email address!",
200200
"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.",
201201
"Warning": "Warning",
202+
"Pin Message": "Pin Message",
203+
"Unpin Message": "Unpin Message",
202204
"Checking for an update...": "Checking for an update...",
203205
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
204206
"No update available.": "No update available.",

0 commit comments

Comments
 (0)