summaryrefslogtreecommitdiffstats
path: root/web/react/components/post_attachment_oembed.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2015-11-11 13:56:13 -0500
committerJoram Wilander <jwawilander@gmail.com>2015-11-11 13:56:13 -0500
commitf8f0814a3796ffd80615c7722e096bef9ef17e73 (patch)
tree2d11bbe6aced74fab6b5fe03fd1a248762c71be4 /web/react/components/post_attachment_oembed.jsx
parent89200132663c79c9d071af1e612afef1bb3d94e6 (diff)
parenta1d40102a2f857c5dc79ed2c0066e1967e8505b8 (diff)
downloadchat-f8f0814a3796ffd80615c7722e096bef9ef17e73.tar.gz
chat-f8f0814a3796ffd80615c7722e096bef9ef17e73.tar.bz2
chat-f8f0814a3796ffd80615c7722e096bef9ef17e73.zip
Merge pull request #1352 from florianorben/PLT-1049
PLT-1049: Vine URLs should not generate preview links
Diffstat (limited to 'web/react/components/post_attachment_oembed.jsx')
-rw-r--r--web/react/components/post_attachment_oembed.jsx83
1 files changed, 83 insertions, 0 deletions
diff --git a/web/react/components/post_attachment_oembed.jsx b/web/react/components/post_attachment_oembed.jsx
new file mode 100644
index 000000000..f544dbc88
--- /dev/null
+++ b/web/react/components/post_attachment_oembed.jsx
@@ -0,0 +1,83 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+export default class PostAttachmentOEmbed extends React.Component {
+ constructor(props) {
+ super(props);
+ this.fetchData = this.fetchData.bind(this);
+
+ this.isLoading = false;
+ }
+
+ componentWillMount() {
+ this.setState({data: {}});
+ }
+
+ componentWillReceiveProps(nextProps) {
+ this.fetchData(nextProps.link);
+ }
+
+ fetchData(link) {
+ if (!this.isLoading) {
+ this.isLoading = true;
+ return $.ajax({
+ url: 'https://noembed.com/embed?nowrap=on&url=' + encodeURIComponent(link),
+ dataType: 'jsonp',
+ success: (result) => {
+ this.isLoading = false;
+ if (result.error) {
+ this.setState({data: {}});
+ } else {
+ this.setState({data: result});
+ }
+ },
+ error: () => {
+ this.setState({data: {}});
+ }
+ });
+ }
+ }
+
+ render() {
+ if ($.isEmptyObject(this.state.data)) {
+ return <div></div>;
+ }
+
+ return (
+ <div
+ className='attachment attachment--oembed'
+ ref='attachment'
+ >
+ <div className='attachment__content'>
+ <div
+ className={'clearfix attachment__container'}
+ >
+ <h1
+ className='attachment__title'
+ >
+ <a
+ className='attachment__title-link'
+ href={this.state.data.url}
+ target='_blank'
+ >
+ {this.state.data.title}
+ </a>
+ </h1>
+ <div>
+ <div className={'attachment__body attachment__body--no_thumb'}>
+ <div
+ dangerouslySetInnerHTML={{__html: this.state.data.html}}
+ >
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ }
+}
+
+PostAttachmentOEmbed.propTypes = {
+ link: React.PropTypes.string.isRequired
+};