From 2a4a02b7bc46214bbc8717661e9fdde170b67824 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Fri, 13 Nov 2015 23:55:21 +0100 Subject: PLT-862: Show images from website links below messages --- web/react/components/post_body.jsx | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index 617b4b36c..975ac64dc 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -16,13 +16,13 @@ export default class PostBody extends React.Component { super(props); this.receivedYoutubeData = false; - this.isGifLoading = false; + this.isImgLoading = false; this.handleUserChange = this.handleUserChange.bind(this); this.parseEmojis = this.parseEmojis.bind(this); this.createEmbed = this.createEmbed.bind(this); - this.createGifEmbed = this.createGifEmbed.bind(this); - this.loadGif = this.loadGif.bind(this); + this.createImageEmbed = this.createImageEmbed.bind(this); + this.loadImg = this.loadImg.bind(this); this.createYoutubeEmbed = this.createYoutubeEmbed.bind(this); const linkData = Utils.extractLinks(this.props.post.message); @@ -117,8 +117,12 @@ export default class PostBody extends React.Component { return embed; } - if (link.substring(link.length - 4) === '.gif') { - return this.createGifEmbed(link, this.state.gifLoaded); + 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 this.createImageEmbed(link, this.state.imgLoaded); + } } return null; @@ -135,29 +139,29 @@ export default class PostBody extends React.Component { return false; } - loadGif(src) { - if (this.isGifLoading) { + loadImg(src) { + if (this.isImgLoading) { return; } - this.isGifLoading = true; + this.isImgLoading = true; - const gif = new Image(); - gif.onload = ( + const img = new Image(); + img.onload = ( () => { - this.embed = this.createGifEmbed(src, true); - this.setState({gifLoaded: true}); + this.embed = this.createImageEmbed(src, true); + this.setState({imgLoaded: true}); } ); - gif.src = src; + img.src = src; } - createGifEmbed(link, isLoaded) { + createImageEmbed(link, isLoaded) { if (!isLoaded) { - this.loadGif(link); + this.loadImg(link); return ( ); @@ -165,7 +169,7 @@ export default class PostBody extends React.Component { return ( ); -- cgit v1.2.3-1-g7c22