summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webapp/components/post_view/post_body_additional_content.jsx29
1 files changed, 28 insertions, 1 deletions
diff --git a/webapp/components/post_view/post_body_additional_content.jsx b/webapp/components/post_view/post_body_additional_content.jsx
index 9310d951e..bd7574949 100644
--- a/webapp/components/post_view/post_body_additional_content.jsx
+++ b/webapp/components/post_view/post_body_additional_content.jsx
@@ -54,11 +54,19 @@ export default class PostBodyAdditionalContent extends React.PureComponent {
};
}
+ componentDidMount() {
+ // check the availability of the image rendered(if any) in the first render.
+ this.preCheckImageLink();
+ }
+
componentWillReceiveProps(nextProps) {
if (nextProps.previewCollapsed !== this.props.previewCollapsed || nextProps.post.message !== this.props.post.message) {
this.setState({
embedVisible: nextProps.previewCollapsed.startsWith('false'),
link: Utils.extractFirstLink(nextProps.post.message)
+ }, () => {
+ // check the availability of the image link
+ this.preCheckImageLink();
});
}
}
@@ -83,6 +91,24 @@ export default class PostBodyAdditionalContent extends React.PureComponent {
);
}
+ // when image links are collapsed, check if the link is a valid image url and it is available
+ preCheckImageLink() {
+ // check only if embedVisible is false i.e the image are by default hidden/collapsed
+ // if embedVisible is true, the image is rendered, during which image load error is captured
+ if (!this.state.embedVisible && this.isLinkImage(this.state.link)) {
+ const image = new Image();
+ image.src = this.state.link;
+
+ image.onload = () => {
+ this.handleLinkLoaded();
+ };
+
+ image.onerror = () => {
+ this.handleLinkLoadError();
+ };
+ }
+ }
+
isLinkImage(link) {
const regex = /.+\/(.+\.(?:jpg|gif|bmp|png|jpeg))(?:\?.*)?$/i;
const match = link.match(regex);
@@ -194,7 +220,8 @@ export default class PostBodyAdditionalContent extends React.PureComponent {
);
const contents = [message];
- if (this.state.linkLoaded || this.props.previewCollapsed.startsWith('true')) {
+
+ if (this.state.linkLoaded || YoutubeVideo.isYoutubeLink(this.state.link)) {
if (prependToggle) {
contents.unshift(toggle);
} else {