From 0f7a8f0fb52f4376a42391812a20e622e82fef4e Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 15 Jun 2016 08:01:52 -0400 Subject: [PATCH] Distinguish between static embeds and toggleable embeds (#3333) --- .../post_body_additional_content.jsx | 67 ++++++++++++------- webapp/utils/constants.jsx | 1 + 2 files changed, 45 insertions(+), 23 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 6757f3b2a5..d7cbe5d6cf 100644 --- a/webapp/components/post_view/components/post_body_additional_content.jsx +++ b/webapp/components/post_view/components/post_body_additional_content.jsx @@ -18,7 +18,8 @@ export default class PostBodyAdditionalContent extends React.Component { this.getSlackAttachment = this.getSlackAttachment.bind(this); this.getOEmbedProvider = this.getOEmbedProvider.bind(this); - this.generateEmbed = this.generateEmbed.bind(this); + this.generateToggleableEmbed = this.generateToggleableEmbed.bind(this); + this.generateStaticEmbed = this.generateStaticEmbed.bind(this); this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this); this.state = { @@ -69,29 +70,12 @@ export default class PostBodyAdditionalContent extends React.Component { return null; } - generateEmbed() { - if (this.props.post.type === 'slack_attachment') { - return this.getSlackAttachment(); - } - + generateToggleableEmbed() { 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 ( - - ); - } - } - if (YoutubeVideo.isYoutubeLink(link)) { return ( + ); + } + } + + return null; + } + + render() { + const staticEmbed = this.generateStaticEmbed(); + + if (staticEmbed) { + return ( +
+ {this.props.message} + {staticEmbed} +
+ ); + } + + const toggleableEmbed = this.generateToggleableEmbed(); + + if (toggleableEmbed) { let messageWithToggle = []; // if message has only one line and starts with a link place toggle in this only line @@ -148,7 +169,7 @@ export default class PostBodyAdditionalContent extends React.Component { className='post__embed-container' hidden={!this.state.embedVisible} > - {generateEmbed} + {toggleableEmbed} ); diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index c8807ae8d9..363347a4f2 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -237,6 +237,7 @@ export default { POST_DELETED: 'deleted', POST_TYPE_EPHEMERAL: 'system_ephemeral', POST_TYPE_JOIN_LEAVE: 'system_join_leave', + POST_TYPE_ATTACHMENT: 'slack_attachment', SYSTEM_MESSAGE_PREFIX: 'system_', SYSTEM_MESSAGE_PROFILE_NAME: 'System', SYSTEM_MESSAGE_PROFILE_IMAGE: logoImage,