diff --git a/android/app/build.gradle b/android/app/build.gradle
index 4a0eec9fe..bb7fb4518 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -111,7 +111,7 @@ android {
applicationId "com.mattermost.rnbeta"
minSdkVersion 21
targetSdkVersion 23
- versionCode 100
+ versionCode 101
versionName "1.8.0"
multiDexEnabled true
ndk {
diff --git a/app/components/profile_picture/profile_picture.js b/app/components/profile_picture/profile_picture.js
index 869a816c6..42668125e 100644
--- a/app/components/profile_picture/profile_picture.js
+++ b/app/components/profile_picture/profile_picture.js
@@ -48,7 +48,6 @@ export default class ProfilePicture extends PureComponent {
componentWillMount() {
const {edit, imageUri, user} = this.props;
- this.mounted = true;
if (edit && imageUri) {
this.setImageURL(imageUri);
@@ -61,21 +60,23 @@ export default class ProfilePicture extends PureComponent {
if (!this.props.status && this.props.user) {
this.props.actions.getStatusForId(this.props.user.id);
}
+
+ this.mounted = true;
}
- componentWillUpdate(nextProps) {
+ componentWillReceiveProps(nextProps) {
if (this.mounted) {
- const url = this.state.pictureUrl;
+ const url = this.props.user ? Client4.getProfilePictureUrl(this.props.user.id, this.props.user.last_picture_update) : null;
const nextUrl = nextProps.user ? Client4.getProfilePictureUrl(nextProps.user.id, nextProps.user.last_picture_update) : null;
if (url !== nextUrl) {
this.setState({
- pictureUrl: nextUrl,
+ pictureUrl: null,
});
if (nextUrl) {
// empty function is so that promise unhandled is not triggered in dev mode
- ImageCacheManager.cache('', nextUrl, this.setImageUrl).then(emptyFunction).catch(emptyFunction);
+ ImageCacheManager.cache('', nextUrl, this.setImageURL).then(emptyFunction).catch(emptyFunction);
}
}
@@ -128,7 +129,8 @@ export default class ProfilePicture extends PureComponent {
let source = null;
if (pictureUrl) {
let prefix = '';
- if (Platform.OS === 'android' && !pictureUrl.includes('content://')) {
+ if (Platform.OS === 'android' && !pictureUrl.startsWith('content://') &&
+ !pictureUrl.startsWith('http://') && !pictureUrl.startsWith('https://')) {
prefix = 'file://';
}
diff --git a/app/utils/image_cache_manager.js b/app/utils/image_cache_manager.js
index 45c64c8e5..5b91d88e7 100644
--- a/app/utils/image_cache_manager.js
+++ b/app/utils/image_cache_manager.js
@@ -3,7 +3,6 @@
// Based on the work done by https://github.com/wcandillon/react-native-expo-image-cache/
-import base64 from 'base-64';
import RNFetchBlob from 'react-native-fetch-blob';
import {DeviceTypes} from 'app/constants';
@@ -14,6 +13,10 @@ export default class ImageCacheManager {
static listeners = {};
static cache = async (filename, uri, listener) => {
+ if (!listener) {
+ console.warn('Unable to cache image when no listener is provided'); // eslint-disable-line no-console
+ }
+
const {path, exists} = await getCacheFile(filename, uri);
if (isDownloading(uri)) {
addListener(uri, listener);
@@ -21,9 +24,15 @@ export default class ImageCacheManager {
listener(path);
} else {
addListener(uri, listener);
+ if (uri.startsWith('file://')) {
+ // In case the uri we are trying to cache is already a local file just notify and return
+ notifyAll(uri, uri);
+ return;
+ }
+
try {
const options = {
- session: base64.encode(uri),
+ session: uri,
timeout: 10000,
indicator: true,
overwrite: true,
@@ -48,7 +57,7 @@ export default class ImageCacheManager {
export const getCacheFile = async (name, uri) => {
const filename = name || uri.substring(uri.lastIndexOf('/'), uri.indexOf('?') === -1 ? uri.length : uri.indexOf('?'));
const ext = filename.indexOf('.') === -1 ? '.png' : filename.substring(filename.lastIndexOf('.'));
- const path = `${IMAGES_PATH}/${base64.encode(uri)}${ext}`;
+ const path = `${IMAGES_PATH}/${hashCode(uri)}${ext}`;
try {
const isDir = await RNFetchBlob.fs.isDir(IMAGES_PATH);
@@ -81,3 +90,20 @@ const notifyAll = (uri, path) => {
}
});
};
+
+// taken from https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
+const hashCode = (str) => {
+ let hash = 0;
+ let i;
+ let chr;
+ if (str.length === 0) {
+ return hash;
+ }
+
+ for (i = 0; i < str.length; i++) {
+ chr = str.charCodeAt(i);
+ hash = ((hash << 5) - hash) + chr;
+ hash |= 0; // Convert to 32bit integer
+ }
+ return hash;
+};
diff --git a/ios/Mattermost.xcodeproj/project.pbxproj b/ios/Mattermost.xcodeproj/project.pbxproj
index 7fd8883fc..15393d4a5 100644
--- a/ios/Mattermost.xcodeproj/project.pbxproj
+++ b/ios/Mattermost.xcodeproj/project.pbxproj
@@ -2468,7 +2468,7 @@
CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 100;
+ CURRENT_PROJECT_VERSION = 101;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = UQ8HT4Q2XM;
ENABLE_BITCODE = NO;
@@ -2518,7 +2518,7 @@
CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
- CURRENT_PROJECT_VERSION = 100;
+ CURRENT_PROJECT_VERSION = 101;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = UQ8HT4Q2XM;
ENABLE_BITCODE = NO;
diff --git a/ios/Mattermost/Info.plist b/ios/Mattermost/Info.plist
index a72d89e70..74828e904 100644
--- a/ios/Mattermost/Info.plist
+++ b/ios/Mattermost/Info.plist
@@ -34,7 +34,7 @@
CFBundleVersion
- 100
+ 101
ITSAppUsesNonExemptEncryption
LSRequiresIPhoneOS
diff --git a/ios/MattermostShare/Info.plist b/ios/MattermostShare/Info.plist
index 31becd995..82d536592 100644
--- a/ios/MattermostShare/Info.plist
+++ b/ios/MattermostShare/Info.plist
@@ -23,7 +23,7 @@
CFBundleShortVersionString
1.8.0
CFBundleVersion
- 100
+ 101
NSAppTransportSecurity
NSAllowsArbitraryLoads
diff --git a/ios/MattermostTests/Info.plist b/ios/MattermostTests/Info.plist
index 39d0c64c7..f59976c19 100644
--- a/ios/MattermostTests/Info.plist
+++ b/ios/MattermostTests/Info.plist
@@ -19,6 +19,6 @@
CFBundleSignature
????
CFBundleVersion
- 100
+ 101
diff --git a/package.json b/package.json
index 14146e94c..fdcef9c17 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,6 @@
"dependencies": {
"analytics-react-native": "1.2.0",
"babel-polyfill": "6.26.0",
- "base-64": "0.1.0",
"commonmark": "github:mattermost/commonmark.js#21742b9d51070b6abba82d88590a0c51ee552a47",
"commonmark-react-renderer": "mattermost/commonmark-react-renderer#86fa63f898802953842526c2030f3b63c5d1ae7a",
"deep-equal": "1.0.1",