support cancelling previews

This commit is contained in:
Matthew Hodgson 2016-04-03 02:50:36 +01:00
parent f9c914c40e
commit e61c99f7f3
2 changed files with 20 additions and 3 deletions

View File

@ -91,7 +91,7 @@ module.exports = React.createClass({
var widget;
if (this.state.link) {
var LinkPreviewWidget = sdk.getComponent('rooms.LinkPreviewWidget');
widget = <LinkPreviewWidget link={ this.state.link } ts={ this.props.mxEvent.getTs() } onWidgetLoad={ this.props.onWidgetLoad }/>;
widget = <LinkPreviewWidget link={ this.state.link } mxEvent={ this.props.mxEvent } onWidgetLoad={ this.props.onWidgetLoad }/>;
}
switch (content.msgtype) {

View File

@ -31,7 +31,7 @@ module.exports = React.createClass({
propTypes: {
link: React.PropTypes.string.isRequired,
ts: React.PropTypes.number,
mxEvent: React.PropTypes.object.isRequired,
onWidgetLoad: React.PropTypes.func,
},
@ -42,7 +42,13 @@ module.exports = React.createClass({
},
componentWillMount: function() {
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.ts).then((res)=>{
if (global.localStorage) {
if (global.localStorage.getItem("hide_preview_" + this.props.mxEvent.getId()) === "1") {
return;
}
}
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.mxEvent.getTs()).then((res)=>{
this.setState({ preview: res });
this.props.onWidgetLoad();
}, (error)=>{
@ -60,6 +66,15 @@ module.exports = React.createClass({
linkifyElement(this.refs.description, linkifyMatrix.options);
},
onCancelClick: function(event) {
this.setState({ preview: null });
// FIXME: persist this somewhere smarter than local storage
// FIXME: add to event contextual menu ability to unhide hidden previews
if (global.localStorage) {
global.localStorage.setItem("hide_preview_" + this.props.mxEvent.getId(), "1");
}
},
render: function() {
var p = this.state.preview;
if (!p) return <div/>;
@ -93,6 +108,8 @@ module.exports = React.createClass({
{ p["og:description"] }
</div>
</div>
<img className="mx_LinkPreviewWidget_cancel" src="img/cancel.svg" width="18" height="18"
onClick={ this.onCancelClick }/>
</div>
);
}