diff --git a/app/components/post_attachment_opengraph/post_attachment_opengraph.js b/app/components/post_attachment_opengraph/post_attachment_opengraph.js
index fc0a221f6..79f331ec0 100644
--- a/app/components/post_attachment_opengraph/post_attachment_opengraph.js
+++ b/app/components/post_attachment_opengraph/post_attachment_opengraph.js
@@ -13,7 +13,6 @@ import {
View,
} from 'react-native';
-import ProgressiveImage from 'app/components/progressive_image';
import ImageCacheManager from 'app/utils/image_cache_manager';
import {previewImageAtIndex, calculateDimensions} from 'app/utils/images';
import {getNearestPoint} from 'app/utils/opengraph';
@@ -96,10 +95,22 @@ export default class PostAttachmentOpenGraph extends PureComponent {
});
if (imageUrl) {
- ImageCacheManager.cache(null, imageUrl, this.getImageSize);
+ ImageCacheManager.cache(this.getFilename(imageUrl), imageUrl, this.getImageSize);
}
}
+ getFilename = (link) => {
+ let filename = link.substring(link.lastIndexOf('/') + 1, link.indexOf('?') === -1 ? link.length : link.indexOf('?'));
+ const extension = filename.split('.').pop();
+
+ if (extension === filename) {
+ const ext = filename.indexOf('.') === -1 ? '.png' : filename.substring(filename.lastIndexOf('.'));
+ filename = `${filename}${ext}`;
+ }
+
+ return `og-${filename}`;
+ };
+
getImageSize = (imageUrl) => {
let prefix = '';
if (Platform.OS === 'android') {
@@ -141,13 +152,7 @@ export default class PostAttachmentOpenGraph extends PureComponent {
originalWidth,
originalHeight,
} = this.state;
- let filename = link.substring(link.lastIndexOf('/') + 1, link.indexOf('?') === -1 ? link.length : link.indexOf('?'));
- const extension = filename.split('.').pop();
-
- if (extension === filename) {
- const ext = filename.indexOf('.') === -1 ? '.png' : filename.substring(filename.lastIndexOf('.'));
- filename = `${filename}${ext}`;
- }
+ const filename = this.getFilename(link);
const files = [{
caption: filename,
@@ -175,6 +180,13 @@ export default class PostAttachmentOpenGraph extends PureComponent {
const style = getStyleSheet(theme);
let description = null;
+ let source;
+ if (imageUrl) {
+ source = {
+ uri: imageUrl,
+ };
+ }
+
if (openGraphData.description) {
description = (
@@ -216,19 +228,22 @@ export default class PostAttachmentOpenGraph extends PureComponent {
{description}
{hasImage &&
-
-
-
-
-
+
+
+
+
+
}
);
@@ -266,6 +281,9 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => {
color: changeOpacity(theme.centerChannelColor, 0.7),
marginBottom: 10,
},
+ imageContainer: {
+ alignItems: 'center',
+ },
image: {
borderRadius: 3,
},
diff --git a/app/utils/image_cache_manager.js b/app/utils/image_cache_manager.js
index fa96aa803..be5c58bf9 100644
--- a/app/utils/image_cache_manager.js
+++ b/app/utils/image_cache_manager.js
@@ -27,33 +27,33 @@ export default class ImageCacheManager {
listener(path);
} else {
addListener(uri, listener);
- if (!uri.startsWith('http')) {
+ if (uri.startsWith('http')) {
+ try {
+ const certificate = await mattermostBucket.getPreference('cert', LocalConfig.AppGroupId);
+ const options = {
+ session: uri,
+ timeout: 10000,
+ indicator: true,
+ overwrite: true,
+ path,
+ certificate,
+ };
+
+ this.downloadTask = await RNFetchBlob.config(options).fetch('GET', uri);
+ if (this.downloadTask.respInfo.respType === 'text') {
+ throw new Error();
+ }
+
+ notifyAll(uri, path);
+ } catch (e) {
+ RNFetchBlob.fs.unlink(path);
+ notifyAll(uri, uri);
+ }
+ } else {
// In case the uri we are trying to cache is already a local file just notify and return
notifyAll(uri, uri);
- return;
}
- try {
- const certificate = await mattermostBucket.getPreference('cert', LocalConfig.AppGroupId);
- const options = {
- session: uri,
- timeout: 10000,
- indicator: true,
- overwrite: true,
- path,
- certificate,
- };
-
- this.downloadTask = await RNFetchBlob.config(options).fetch('GET', uri);
- if (this.downloadTask.respInfo.respType === 'text') {
- throw new Error();
- }
-
- notifyAll(uri, path);
- } catch (e) {
- RNFetchBlob.fs.unlink(path);
- notifyAll(uri, uri);
- }
unsubscribe(uri);
}
};