summaryrefslogtreecommitdiffstats
path: root/webapp/components/post_body_additional_content.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-05-27 16:01:28 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-27 16:01:28 -0400
commit6399a94ce221be3d15e7132654c28cd953075ec6 (patch)
tree4b1927fdd8374e8bd3cb809ecb720f2689043358 /webapp/components/post_body_additional_content.jsx
parentca9f348be6bf62fc888df9a710c9af155872528e (diff)
downloadchat-6399a94ce221be3d15e7132654c28cd953075ec6.tar.gz
chat-6399a94ce221be3d15e7132654c28cd953075ec6.tar.bz2
chat-6399a94ce221be3d15e7132654c28cd953075ec6.zip
PLT-2672 Refactored posts view with caching (#3054)
* Refactored posts view to use view controller design * Add post view caching * Required updates after rebase * Fixed bug where current channel not set yet was causing breakage
Diffstat (limited to 'webapp/components/post_body_additional_content.jsx')
-rw-r--r--webapp/components/post_body_additional_content.jsx151
1 files changed, 0 insertions, 151 deletions
diff --git a/webapp/components/post_body_additional_content.jsx b/webapp/components/post_body_additional_content.jsx
deleted file mode 100644
index cdb735b47..000000000
--- a/webapp/components/post_body_additional_content.jsx
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import PostAttachmentList from './post_attachment_list.jsx';
-import PostAttachmentOEmbed from './post_attachment_oembed.jsx';
-import PostImage from './post_image.jsx';
-import YoutubeVideo from './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';
-
-export default class PostBodyAdditionalContent extends React.Component {
- constructor(props) {
- super(props);
-
- this.getSlackAttachment = this.getSlackAttachment.bind(this);
- this.getOEmbedProvider = this.getOEmbedProvider.bind(this);
- this.generateEmbed = this.generateEmbed.bind(this);
- this.toggleEmbedVisibility = this.toggleEmbedVisibility.bind(this);
-
- this.state = {
- embedVisible: true
- };
- }
-
- shouldComponentUpdate(nextProps, nextState) {
- if (!Utils.areObjectsEqual(nextProps.post, this.props.post)) {
- return true;
- }
- if (nextState.embedVisible !== this.state.embedVisible) {
- return true;
- }
- return false;
- }
-
- toggleEmbedVisibility() {
- this.setState({embedVisible: !this.state.embedVisible});
- }
-
- getSlackAttachment() {
- let attachments = [];
- if (this.props.post.props && this.props.post.props.attachments) {
- attachments = this.props.post.props.attachments;
- }
-
- return (
- <PostAttachmentList
- attachments={attachments}
- />
- );
- }
-
- 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;
- }
-
- generateEmbed() {
- if (this.props.post.type === 'slack_attachment') {
- return this.getSlackAttachment();
- }
-
- 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 (YoutubeVideo.isYoutubeLink(link)) {
- return (
- <YoutubeVideo
- channelId={this.props.post.channel_id}
- link={link}
- />
- );
- }
-
- for (let i = 0; i < Constants.IMAGE_TYPES.length; i++) {
- const imageType = Constants.IMAGE_TYPES[i];
- const suffix = link.substring(link.length - (imageType.length + 1));
- if (suffix === '.' + imageType || suffix === '=' + imageType) {
- return (
- <PostImage
- channelId={this.props.post.channel_id}
- link={link}
- />
- );
- }
- }
-
- return null;
- }
-
- render() {
- const generateEmbed = this.generateEmbed();
-
- if (generateEmbed) {
- let toggle;
- if (Utils.isFeatureEnabled(Constants.PRE_RELEASE_FEATURES.EMBED_TOGGLE)) {
- toggle = (
- <a
- className='post__embed-visibility'
- data-expanded={this.state.embedVisible}
- aria-label='Toggle Embed Visibility'
- onClick={this.toggleEmbedVisibility}
- />
- );
- }
-
- return (
- <div>
- {toggle}
- <div
- className='post__embed-container'
- hidden={!this.state.embedVisible}
- >
- {generateEmbed}
- </div>
- </div>
- );
- }
-
- return null;
- }
-}
-
-PostBodyAdditionalContent.propTypes = {
- post: React.PropTypes.object.isRequired
-};