diff options
Diffstat (limited to 'webapp/components/post_view/components/post_body_additional_content.jsx')
-rw-r--r-- | webapp/components/post_view/components/post_body_additional_content.jsx | 64 |
1 files changed, 22 insertions, 42 deletions
diff --git a/webapp/components/post_view/components/post_body_additional_content.jsx b/webapp/components/post_view/components/post_body_additional_content.jsx index e6c1f3b06..cad618de0 100644 --- a/webapp/components/post_view/components/post_body_additional_content.jsx +++ b/webapp/components/post_view/components/post_body_additional_content.jsx @@ -2,12 +2,11 @@ // See License.txt for license information. import PostAttachmentList from './post_attachment_list.jsx'; -import PostAttachmentOEmbed from './post_attachment_oembed.jsx'; +import PostAttachmentOpenGraph from './post_attachment_opengraph.jsx'; import PostImage from './post_image.jsx'; import YoutubeVideo from 'components/youtube_video.jsx'; import Constants from 'utils/constants.jsx'; -import OEmbedProviders from './providers.json'; import * as Utils from 'utils/utils.jsx'; import React from 'react'; @@ -17,7 +16,6 @@ export default class PostBodyAdditionalContent extends React.Component { super(props); this.getSlackAttachment = this.getSlackAttachment.bind(this); - this.getOEmbedProvider = this.getOEmbedProvider.bind(this); this.generateToggleableEmbed = this.generateToggleableEmbed.bind(this); this.generateStaticEmbed = this.generateStaticEmbed.bind(this); this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this); @@ -72,18 +70,6 @@ export default class PostBodyAdditionalContent extends React.Component { ); } - getOEmbedProvider(link) { - for (let i = 0; i < OEmbedProviders.length; i++) { - for (let j = 0; j < OEmbedProviders[i].patterns.length; j++) { - if (link.match(OEmbedProviders[i].patterns[j])) { - return OEmbedProviders[i]; - } - } - } - - return null; - } - isLinkImage(link) { const regex = /.+\/(.+\.(?:jpg|gif|bmp|png|jpeg))(?:\?.*)?$/i; const match = link.match(regex); @@ -152,38 +138,20 @@ export default class PostBodyAdditionalContent extends React.Component { } const link = Utils.extractFirstLink(this.props.post.message); - if (!link) { - return null; - } - - if (Utils.isFeatureEnabled(Constants.PRE_RELEASE_FEATURES.EMBED_PREVIEW)) { - const provider = this.getOEmbedProvider(link); - - if (provider) { - return ( - <PostAttachmentOEmbed - provider={provider} - link={link} - /> - ); - } + if (link && Utils.isFeatureEnabled(Constants.PRE_RELEASE_FEATURES.EMBED_PREVIEW)) { + return ( + <PostAttachmentOpenGraph + link={link} + childComponentDidUpdateFunction={this.props.childComponentDidUpdateFunction} + previewCollapsed={this.props.previewCollapsed} + /> + ); } return null; } render() { - const staticEmbed = this.generateStaticEmbed(); - - if (staticEmbed) { - return ( - <div> - {this.props.message} - {staticEmbed} - </div> - ); - } - if (this.isLinkToggleable() && !this.state.linkLoadError) { const messageWithToggle = []; @@ -224,6 +192,17 @@ export default class PostBodyAdditionalContent extends React.Component { ); } + const staticEmbed = this.generateStaticEmbed(); + + if (staticEmbed) { + return ( + <div> + {this.props.message} + {staticEmbed} + </div> + ); + } + return this.props.message; } } @@ -235,5 +214,6 @@ PostBodyAdditionalContent.propTypes = { post: React.PropTypes.object.isRequired, message: React.PropTypes.element.isRequired, compactDisplay: React.PropTypes.bool, - previewCollapsed: React.PropTypes.string + previewCollapsed: React.PropTypes.string, + childComponentDidUpdateFunction: React.PropTypes.func }; |