Skip to content

Commit f143315

Browse files
authored
Merge pull request element-hq#5142 from turt2live/travis/pinned_messages
Message/event pinning
2 parents 6f81960 + 6926c96 commit f143315

7 files changed

Lines changed: 174 additions & 5 deletions

File tree

‎src/components/views/context_menus/MessageContextMenu.js‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,40 @@ module.exports = React.createClass({
4343
getInitialState: function() {
4444
return {
4545
canRedact: false,
46+
canPin: false,
4647
};
4748
},
4849

4950
componentWillMount: function() {
50-
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkCanRedact);
51-
this._checkCanRedact();
51+
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkPermissions);
52+
this._checkPermissions();
5253
},
5354

5455
componentWillUnmount: function() {
5556
const cli = MatrixClientPeg.get();
5657
if (cli) {
57-
cli.removeListener('RoomMember.powerLevel', this._checkCanRedact);
58+
cli.removeListener('RoomMember.powerLevel', this._checkPermissions);
5859
}
5960
},
6061

61-
_checkCanRedact: function() {
62+
_checkPermissions: function() {
6263
const cli = MatrixClientPeg.get();
6364
const room = cli.getRoom(this.props.mxEvent.getRoomId());
65+
6466
const canRedact = room.currentState.maySendRedactionForEvent(this.props.mxEvent, cli.credentials.userId);
65-
this.setState({canRedact});
67+
let canPin = room.currentState.mayClientSendStateEvent('m.room.pinned_events', cli);
68+
69+
// HACK: Intentionally say we can't pin if the user doesn't want to use the functionality
70+
if (!UserSettingsStore.isFeatureEnabled("feature_pinning")) canPin = false;
71+
72+
this.setState({canRedact, canPin});
73+
},
74+
75+
_isPinned: function() {
76+
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
77+
const pinnedEvent = room.currentState.getStateEvents('m.room.pinned_events', '');
78+
if (!pinnedEvent) return false;
79+
return pinnedEvent.getContent().pinned.includes(this.props.mxEvent.getId());
6680
},
6781

6882
onResendClick: function() {
@@ -122,6 +136,28 @@ module.exports = React.createClass({
122136
this.closeMenu();
123137
},
124138

139+
onPinClick: function() {
140+
MatrixClientPeg.get().getStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', '')
141+
.catch(e => {
142+
// Intercept the Event Not Found error and fall through the promise chain with no event.
143+
if (e.errcode === "M_NOT_FOUND") return null;
144+
throw e;
145+
})
146+
.then(event => {
147+
const eventIds = (event ? event.pinned : []) || [];
148+
if (!eventIds.includes(this.props.mxEvent.getId())) {
149+
// Not pinned - add
150+
eventIds.push(this.props.mxEvent.getId());
151+
} else {
152+
// Pinned - remove
153+
eventIds.splice(eventIds.indexOf(this.props.mxEvent.getId()), 1);
154+
}
155+
156+
MatrixClientPeg.get().sendStateEvent(this.props.mxEvent.getRoomId(), 'm.room.pinned_events', {pinned: eventIds}, '');
157+
});
158+
this.closeMenu();
159+
},
160+
125161
closeMenu: function() {
126162
if (this.props.onFinished) this.props.onFinished();
127163
},
@@ -147,6 +183,7 @@ module.exports = React.createClass({
147183
let redactButton;
148184
let cancelButton;
149185
let forwardButton;
186+
let pinButton;
150187
let viewSourceButton;
151188
let viewClearSourceButton;
152189
let unhidePreviewButton;
@@ -186,6 +223,14 @@ module.exports = React.createClass({
186223
{ _t('Forward Message') }
187224
</div>
188225
);
226+
227+
if (this.state.canPin) {
228+
pinButton = (
229+
<div className="mx_MessageContextMenu_field" onClick={this.onPinClick}>
230+
{this._isPinned() ? _t('Unpin Message') : _t('Pin Message')}
231+
</div>
232+
);
233+
}
189234
}
190235
}
191236

@@ -246,6 +291,7 @@ module.exports = React.createClass({
246291
{redactButton}
247292
{cancelButton}
248293
{forwardButton}
294+
{pinButton}
249295
{viewSourceButton}
250296
{viewClearSourceButton}
251297
{unhidePreviewButton}

‎src/i18n/strings/en_EN.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@
200200
"You have successfully set a password!": "You have successfully set a password!",
201201
"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.",
202202
"Continue": "Continue",
203+
"Pin Message": "Pin Message",
204+
"Unpin Message": "Unpin Message",
205+
"Jump to message": "Jump to message",
206+
"No pinned messages.": "No pinned messages.",
207+
"Loading...": "Loading...",
203208
"Please set a password!": "Please set a password!",
204209
"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.",
205210
"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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@
185185
"You have successfully set a password and an email address!": "You have successfully set a password and an email address!",
186186
"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.",
187187
"Warning": "Warning",
188+
"Pin Message": "Pin Message",
189+
"Unpin Message": "Unpin Message",
190+
"Jump to message": "Jump to message",
191+
"No pinned messages.": "No pinned messages.",
192+
"Loading...": "Loading...",
188193
"Checking for an update...": "Checking for an update...",
189194
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
190195
"No update available.": "No update available.",

‎src/skins/vector/css/_components.scss‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
@import "./matrix-react-sdk/views/voip/_CallView.scss";
6969
@import "./matrix-react-sdk/views/voip/_IncomingCallbox.scss";
7070
@import "./matrix-react-sdk/views/voip/_VideoView.scss";
71+
@import "./matrix-react-sdk/views/rooms/_PinnedEventsPanel.scss";
72+
@import "./matrix-react-sdk/views/rooms/_PinnedEventTile.scss";
7173
@import "./vector-web/_fonts.scss";
7274
@import "./vector-web/structures/_CompatibilityPage.scss";
7375
@import "./vector-web/structures/_HomePage.scss";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2017 Travis Ralston
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_PinnedEventTile {
18+
min-height: 40px;
19+
margin-bottom: 5px;
20+
width: 100%;
21+
border-radius: 5px; // for the hover
22+
}
23+
24+
.mx_PinnedEventTile:hover {
25+
background-color: $event-selected-color;
26+
}
27+
28+
.mx_PinnedEventTile .mx_PinnedEventTile_sender {
29+
color: #868686;
30+
font-size: 0.8em;
31+
vertical-align: top;
32+
display: block;
33+
padding-bottom: 3px;
34+
}
35+
36+
.mx_PinnedEventTile .mx_EventTile_content {
37+
margin-left: 50px;
38+
position: relative;
39+
top: 0;
40+
left: 0;
41+
}
42+
43+
.mx_PinnedEventTile .mx_BaseAvatar {
44+
float: left;
45+
margin-right: 10px;
46+
}
47+
48+
.mx_PinnedEventTile:hover .mx_PinnedEventTile_actions {
49+
display: block;
50+
}
51+
52+
.mx_PinnedEventTile_actions {
53+
float: right;
54+
margin-right: 10px;
55+
display: none;
56+
}
57+
58+
.mx_PinnedEventTile_unpinButton {
59+
display: inline-block;
60+
cursor: pointer;
61+
margin-left: 10px;
62+
}
63+
64+
.mx_PinnedEventTile_gotoButton {
65+
display: inline-block;
66+
font-size: 0.8em;
67+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2017 Travis Ralston
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_PinnedEventsPanel {
18+
border-top: 1px solid $primary-hairline-color;
19+
}
20+
21+
.mx_PinnedEventsPanel_body {
22+
max-height: 300px;
23+
overflow-y: auto;
24+
padding-bottom: 15px;
25+
}
26+
27+
.mx_PinnedEventsPanel_header {
28+
margin: 0;
29+
padding-top: 8px;
30+
padding-bottom: 15px;
31+
}
32+
33+
.mx_PinnedEventsPanel_cancel {
34+
margin: 12px;
35+
float: right;
36+
display: inline-block;
37+
}

‎src/skins/vector/img/icons-pin.svg‎

Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)