Skip to content

Commit 8c619fe

Browse files
committed
Merge pull request element-hq#1343 from vector-im/matthew/preview_urls
URL previewing support
2 parents a1b78f9 + efd01d6 commit 8c619fe

3 files changed

Lines changed: 119 additions & 22 deletions

File tree

‎src/components/views/elements/ImageView.js‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,19 @@ module.exports = React.createClass({
2727
displayName: 'ImageView',
2828

2929
propTypes: {
30-
onFinished: React.PropTypes.func.isRequired,
31-
name: React.PropTypes.string
30+
src: React.PropTypes.string.isRequired, // the source of the image being displayed
31+
name: React.PropTypes.string, // the main title ('name') for the image
32+
link: React.PropTypes.string, // the link (if any) applied to the name of the image
33+
width: React.PropTypes.number, // width of the image src in pixels
34+
height: React.PropTypes.number, // height of the image src in pixels
35+
fileSize: React.PropTypes.number, // size of the image src in bytes
36+
onFinished: React.PropTypes.func.isRequired, // callback when the lightbox is dismissed
37+
38+
// the event (if any) that the Image is displaying. Used for event-specific stuff like
39+
// redactions, senders, timestamps etc. Other descriptors are taken from the explicit
40+
// properties above, which let us use lightboxes to display images which aren't associated
41+
// with events.
42+
mxEvent: React.PropTypes.object,
3243
},
3344

3445
// XXX: keyboard shortcuts for managing dialogs should be done by the modal
@@ -67,16 +78,10 @@ module.exports = React.createClass({
6778
},
6879

6980
getName: function () {
70-
var name;
71-
72-
if(this.props.name) {
73-
name = this.props.name;
74-
} else if(this.props.mxEvent) {
75-
name = this.props.mxEvent.getContent().body;
76-
} else {
77-
name = null;
81+
var name = this.props.name;
82+
if (name && this.props.link) {
83+
name = <a href={ this.props.link } target="_blank">{ name }</a>;
7884
}
79-
8085
return name;
8186
},
8287

@@ -117,14 +122,20 @@ module.exports = React.createClass({
117122
width: this.props.width,
118123
height: this.props.height,
119124
};
120-
res = ", " + style.width + "x" + style.height + "px";
125+
res = style.width + "x" + style.height + "px";
121126
}
122127

123128
var size;
124-
if (this.props.mxEvent &&
125-
this.props.mxEvent.getContent().info &&
126-
this.props.mxEvent.getContent().info.size) {
127-
size = filesize(this.props.mxEvent.getContent().info.size);
129+
if (this.props.fileSize) {
130+
size = filesize(this.props.fileSize);
131+
}
132+
133+
var size_res;
134+
if (size && res) {
135+
size_res = size + ", " + res;
136+
}
137+
else {
138+
size_res = size || res;
128139
}
129140

130141
var showEventMeta = !!this.props.mxEvent;
@@ -161,14 +172,9 @@ module.exports = React.createClass({
161172
<a className="mx_ImageView_link" href={ this.props.src } target="_blank">
162173
<div className="mx_ImageView_download">
163174
Download this file<br/>
164-
<span className="mx_ImageView_size">{ size } { res }</span>
175+
<span className="mx_ImageView_size">{ size_res }</span>
165176
</div>
166177
</a>
167-
<div className="mx_ImageView_button">
168-
<a className="mx_ImageView_link" href={ this.props.src } target="_blank">
169-
View full screen
170-
</a>
171-
</div>
172178
{ eventRedact }
173179
<div className="mx_ImageView_shim">
174180
</div>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ var Resend = require("matrix-react-sdk/lib/Resend");
2727
module.exports = React.createClass({
2828
displayName: 'MessageContextMenu',
2929

30+
propTypes: {
31+
/* the MatrixEvent associated with the context menu */
32+
mxEvent: React.PropTypes.object.isRequired,
33+
34+
/* an optional EventTileOps implementation that can be used to unhide preview widgets */
35+
eventTileOps: React.PropTypes.object,
36+
37+
/* callback called when the menu is dismissed */
38+
onFinished: React.PropTypes.func,
39+
},
40+
3041
onResendClick: function() {
3142
Resend.resend(this.props.mxEvent);
3243
if (this.props.onFinished) this.props.onFinished();
@@ -66,13 +77,21 @@ module.exports = React.createClass({
6677
if (this.props.onFinished) this.props.onFinished();
6778
},
6879

80+
onUnhidePreviewClick: function() {
81+
if (this.props.eventTileOps) {
82+
this.props.eventTileOps.unhideWidget();
83+
}
84+
if (this.props.onFinished) this.props.onFinished();
85+
},
86+
6987
render: function() {
7088
var eventStatus = this.props.mxEvent.status;
7189
var resendButton;
7290
var viewSourceButton;
7391
var redactButton;
7492
var cancelButton;
7593
var permalinkButton;
94+
var unhidePreviewButton;
7695

7796
if (eventStatus === 'not_sent') {
7897
resendButton = (
@@ -104,6 +123,16 @@ module.exports = React.createClass({
104123
</div>
105124
);
106125

126+
if (this.props.eventTileOps) {
127+
if (this.props.eventTileOps.isWidgetHidden()) {
128+
unhidePreviewButton = (
129+
<div className="mx_ContextualMenu_field" onClick={this.onUnhidePreviewClick}>
130+
Unhide Preview
131+
</div>
132+
)
133+
}
134+
}
135+
107136
// XXX: this should be https://matrix.to.
108137
// XXX: if we use room ID, we should also include a server where the event can be found (other than in the domain of the event ID)
109138
permalinkButton = (
@@ -119,6 +148,7 @@ module.exports = React.createClass({
119148
{redactButton}
120149
{cancelButton}
121150
{viewSourceButton}
151+
{unhidePreviewButton}
122152
{permalinkButton}
123153
</div>
124154
);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2015, 2016 OpenMarket Ltd
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_LinkPreviewWidget {
18+
margin-top: 15px;
19+
margin-right: 15px;
20+
margin-bottom: 15px;
21+
display: -webkit-flex;
22+
display: flex;
23+
border-left: 4px solid #ddd;
24+
color: #888;
25+
}
26+
27+
.mx_LinkPreviewWidget_image {
28+
-webkit-flex: 0 0 100px;
29+
flex: 0 0 100px;
30+
margin-left: 15px;
31+
text-align: center;
32+
}
33+
34+
.mx_LinkPreviewWidget_caption {
35+
margin-left: 15px;
36+
-webkit-flex: 1;
37+
flex: 1;
38+
}
39+
40+
.mx_LinkPreviewWidget_title {
41+
display: inline;
42+
font-weight: bold;
43+
}
44+
45+
.mx_LinkPreviewWidget_siteName {
46+
display: inline;
47+
}
48+
49+
.mx_LinkPreviewWidget_description {
50+
margin-top: 8px;
51+
white-space: normal;
52+
}
53+
54+
.mx_LinkPreviewWidget_cancel {
55+
visibility: hidden;
56+
cursor: pointer;
57+
}
58+
59+
.mx_LinkPreviewWidget:hover .mx_LinkPreviewWidget_cancel {
60+
visibility: visible;
61+
}

0 commit comments

Comments
 (0)