From 69839d59cd6040a8d28c966b9e0967c565fde0b1 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 24 Sep 2019 14:37:13 -0300 Subject: [PATCH 01/13] [CHORE] Revert react-navigation-drawer (#1227) --- app/index.js | 3 ++- package.json | 2 +- yarn.lock | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/index.js b/app/index.js index bdc378aec..016be1163 100644 --- a/app/index.js +++ b/app/index.js @@ -196,7 +196,8 @@ const ChatsDrawer = createDrawerNavigator({ SettingsStack, AdminPanelStack }, { - contentComponent: Sidebar + contentComponent: Sidebar, + overlayColor: '#00000090' }); const NewMessageStack = createStackNavigator({ diff --git a/package.json b/package.json index 974cfc2f3..0287ed5c1 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "react-native-video": "^5.0.0", "react-native-webview": "6.8.0", "react-navigation": "^4.0.5", - "react-navigation-drawer": "^2.2.1", + "react-navigation-drawer": "1.4.0", "react-navigation-header-buttons": "3.0.1", "react-navigation-stack": "^1.7.3", "react-redux": "7.1.0", diff --git a/yarn.lock b/yarn.lock index e04a4b05e..91c4de9eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8898,6 +8898,13 @@ react-native-swipe-gestures@^1.0.3: resolved "https://registry.yarnpkg.com/react-native-swipe-gestures/-/react-native-swipe-gestures-1.0.3.tgz#4160f8d459627323f3a3d2770af4bcd82fd054f5" integrity sha512-KOouRzPB2fHFjVombsSdRfYo8SFeNVa4Ho4B5il87DuuF26sPNOtb3je+qaT/xVptedOsCzRPJGbWFMsaBApgg== +react-native-tab-view@^1.2.0: + version "1.4.1" + resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-1.4.1.tgz#f113cd87485808f0c991abec937f70fa380478b9" + integrity sha512-Bke8KkDcDhvB/z0AS7MnQKMD2p6Kwfc1rSKlMOvg9CC5CnClQ2QEnhPSbwegKDYhUkBI92iH/BYy7hNSm5kbUQ== + dependencies: + prop-types "^15.6.1" + react-native-unimodules@0.5.3: version "0.5.3" resolved "https://registry.yarnpkg.com/react-native-unimodules/-/react-native-unimodules-0.5.3.tgz#24615ae71615d9aa76f128595286ad5fc4709ed2" @@ -8982,10 +8989,12 @@ react-native@0.60.4: stacktrace-parser "^0.1.3" whatwg-fetch "^3.0.0" -react-navigation-drawer@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/react-navigation-drawer/-/react-navigation-drawer-2.2.1.tgz#00bc5a9fcd80a519834f2db8a37aba9fc7f99d8b" - integrity sha512-FfGG27CGd2zimBYwICyURNpFkP5ggHNfgYLUnWZDo4FnpmPPFTPeYsEmfKeITD0Mg334CI23CLW8HSCuq5Mszw== +react-navigation-drawer@1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/react-navigation-drawer/-/react-navigation-drawer-1.4.0.tgz#70f3dd83e3da9cd4ea6e2739526502c823d466b9" + integrity sha512-ZyWBozcjB2aZ7vwCALv90cYA2NpDjM+WALaiYRshvPvue8l7cqynePbHK8GhlMGyJDwZqp4MxQmu8u1XAKp3Bw== + dependencies: + react-native-tab-view "^1.2.0" react-navigation-header-buttons@3.0.1: version "3.0.1" From f29b9aaa75e07ebe684f7fec59b9b37c02366b3b Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 24 Sep 2019 15:19:33 -0300 Subject: [PATCH 02/13] [FIX] Unnecessary rooms list render on focus (#1226) --- app/views/RoomsListView/index.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 94783eeea..a58496687 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -164,12 +164,19 @@ class RoomsListView extends React.Component { width }; Orientation.unlockAllOrientations(); + this.willFocusListener = props.navigation.addListener('willFocus', () => { + // Check if there were changes while not focused (it's set on sCU) + if (this.shouldUpdate) { + animateNextTransition(); + this.forceUpdate(); + this.shouldUpdate = false; + } + }); this.didFocusListener = props.navigation.addListener('didFocus', () => { BackHandler.addEventListener( 'hardwareBackPress', this.handleBackPress ); - this.forceUpdate(); }); this.willBlurListener = props.navigation.addListener('willBlur', () => BackHandler.addEventListener( 'hardwareBackPress', @@ -204,12 +211,22 @@ class RoomsListView extends React.Component { } shouldComponentUpdate(nextProps, nextState) { + const { allChats } = this.state; // eslint-disable-next-line react/destructuring-assignment const propsUpdated = shouldUpdateProps.some(key => nextProps[key] !== this.props[key]); if (propsUpdated) { return true; } + // Compare changes only once + const chatsNotEqual = !isEqual(nextState.allChats, allChats); + + // If they aren't equal, set to update if focused + if (chatsNotEqual) { + this.shouldUpdate = true; + } + + // Abort if it's not focused if (!nextProps.navigation.isFocused()) { return false; } @@ -218,7 +235,6 @@ class RoomsListView extends React.Component { loading, searching, width, - allChats, search } = this.state; if (nextState.loading !== loading) { @@ -233,7 +249,9 @@ class RoomsListView extends React.Component { if (!isEqual(nextState.search, search)) { return true; } - if (!isEqual(nextState.allChats, allChats)) { + // If it's focused and there are changes, update + if (chatsNotEqual) { + this.shouldUpdate = false; return true; } return false; @@ -275,6 +293,9 @@ class RoomsListView extends React.Component { if (this.querySubscription && this.querySubscription.unsubscribe) { this.querySubscription.unsubscribe(); } + if (this.willFocusListener && this.willFocusListener.remove) { + this.willFocusListener.remove(); + } if (this.didFocusListener && this.didFocusListener.remove) { this.didFocusListener.remove(); } From 31d03ff5e57263f6d3c51197886a115aa0080575 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 24 Sep 2019 17:10:50 -0300 Subject: [PATCH 03/13] [FIX] Show admin panel button logic (#1220) --- app/views/SidebarView/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/SidebarView/index.js b/app/views/SidebarView/index.js index 1341e284f..9e008071c 100644 --- a/app/views/SidebarView/index.js +++ b/app/views/SidebarView/index.js @@ -40,7 +40,8 @@ class Sidebar extends Component { Site_Name: PropTypes.string.isRequired, user: PropTypes.object, logout: PropTypes.func.isRequired, - activeItemKey: PropTypes.string + activeItemKey: PropTypes.string, + loadingServer: PropTypes.bool } constructor(props) { @@ -58,14 +59,17 @@ class Sidebar extends Component { } componentWillReceiveProps(nextProps) { - const { user } = this.props; + const { user, loadingServer } = this.props; if (nextProps.user && user && user.language !== nextProps.user.language) { this.setStatus(); } + if (loadingServer && nextProps.loadingServer !== loadingServer) { + this.setIsAdmin(); + } } shouldComponentUpdate(nextProps, nextState) { - const { status, showStatus } = this.state; + const { status, showStatus, isAdmin } = this.state; const { Site_Name, user, baseUrl, activeItemKey } = this.props; @@ -98,6 +102,9 @@ class Sidebar extends Component { if (!equal(nextState.status, status)) { return true; } + if (nextState.isAdmin !== isAdmin) { + return true; + } return false; } @@ -288,7 +295,8 @@ const mapStateToProps = state => ({ token: state.login.user && state.login.user.token, roles: state.login.user && state.login.user.roles }, - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' + baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + loadingServer: state.server.loading }); const mapDispatchToProps = dispatch => ({ From ae7a9cba60446987d7bc65c8b932cb093c6dd155 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 24 Sep 2019 17:15:13 -0300 Subject: [PATCH 04/13] [REGRESSION] Share this app (#1215) --- app/views/SettingsView/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/views/SettingsView/index.js b/app/views/SettingsView/index.js index 0514922f1..a21fb545e 100644 --- a/app/views/SettingsView/index.js +++ b/app/views/SettingsView/index.js @@ -145,6 +145,14 @@ class SettingsView extends React.Component { right={this.renderDisclosure} /> + + - - From 319ca7f04497769f44bc7ab75ff4ff08251cc77a Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 24 Sep 2019 17:16:59 -0300 Subject: [PATCH 05/13] [FIX] Unify upload check (#1229) --- app/containers/MessageBox/Recording.js | 12 +- app/containers/MessageBox/UploadModal.js | 143 ++++------------------- app/containers/MessageBox/index.js | 43 +++++-- app/lib/methods/sendFileMessage.js | 7 +- app/utils/media.js | 16 +-- app/views/ShareListView/index.js | 12 +- 6 files changed, 78 insertions(+), 155 deletions(-) diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index 96f45c9b7..d5fed549a 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -5,6 +5,7 @@ import { } from 'react-native'; import { AudioRecorder, AudioUtils } from 'react-native-audio'; import { BorderlessButton } from 'react-native-gesture-handler'; +import FileSystem from 'expo-file-system'; import styles from './styles'; import I18n from '../../i18n'; @@ -68,7 +69,7 @@ export default class extends React.PureComponent { // AudioRecorder.onFinished = (data) => { if (!this.recordingCanceled && isIOS) { - this.finishRecording(data.status === 'OK', data.audioFileURL); + this.finishRecording(data.status === 'OK', data.audioFileURL, data.audioFileSize); } }; AudioRecorder.startRecording(); @@ -80,7 +81,7 @@ export default class extends React.PureComponent { } } - finishRecording = (didSucceed, filePath) => { + finishRecording = (didSucceed, filePath, size) => { const { onFinish } = this.props; if (!didSucceed) { return onFinish && onFinish(didSucceed); @@ -90,9 +91,11 @@ export default class extends React.PureComponent { } const fileInfo = { name: this.name, + mime: 'audio/aac', type: 'audio/aac', store: 'Uploads', - path: filePath + path: filePath, + size }; return onFinish && onFinish(fileInfo); } @@ -102,7 +105,8 @@ export default class extends React.PureComponent { this.recording = false; const filePath = await AudioRecorder.stopRecording(); if (isAndroid) { - this.finishRecording(true, filePath); + const data = await FileSystem.getInfoAsync(decodeURIComponent(filePath)); + this.finishRecording(true, filePath, data.size); } } catch (err) { this.finishRecording(false); diff --git a/app/containers/MessageBox/UploadModal.js b/app/containers/MessageBox/UploadModal.js index 596934ebf..3773391b7 100644 --- a/app/containers/MessageBox/UploadModal.js +++ b/app/containers/MessageBox/UploadModal.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, TouchableHighlight } from 'react-native'; -import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import Modal from 'react-native-modal'; import { responsive } from 'react-native-responsive-ui'; @@ -13,9 +12,8 @@ import Button from '../Button'; import I18n from '../../i18n'; import sharedStyles from '../../views/Styles'; import { isIOS } from '../../utils/deviceInfo'; -import { canUploadFile } from '../../utils/media'; import { - COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE, COLOR_DANGER + COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE } from '../../constants/colors'; import { CustomIcon } from '../../lib/Icons'; @@ -75,23 +73,6 @@ const styles = StyleSheet.create({ flex: 1, textAlign: 'center' }, - errorIcon: { - color: COLOR_DANGER - }, - fileMime: { - ...sharedStyles.textColorTitle, - ...sharedStyles.textBold, - textAlign: 'center', - fontSize: 20, - marginBottom: 20 - }, - errorContainer: { - margin: 20, - flex: 1, - textAlign: 'center', - justifyContent: 'center', - alignItems: 'center' - }, video: { flex: 1, borderRadius: 4, @@ -110,9 +91,7 @@ class UploadModal extends Component { file: PropTypes.object, close: PropTypes.func, submit: PropTypes.func, - window: PropTypes.object, - FileUpload_MediaTypeWhiteList: PropTypes.string, - FileUpload_MaxFileSize: PropTypes.number + window: PropTypes.object } state = { @@ -154,79 +133,12 @@ class UploadModal extends Component { return false; } - canUploadFile = () => { - const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize, file } = this.props; - if (!(file && file.path)) { - return true; - } - if (file.size > FileUpload_MaxFileSize) { - return false; - } - // if white list is empty, all media types are enabled - if (!FileUpload_MediaTypeWhiteList) { - return true; - } - const allowedMime = FileUpload_MediaTypeWhiteList.split(','); - if (allowedMime.includes(file.mime)) { - return true; - } - const wildCardGlob = '/*'; - const wildCards = allowedMime.filter(item => item.indexOf(wildCardGlob) > 0); - if (wildCards.includes(file.mime.replace(/(\/.*)$/, wildCardGlob))) { - return true; - } - return false; - } - submit = () => { const { file, submit } = this.props; const { name, description } = this.state; submit({ ...file, name, description }); } - renderError = () => { - const { file, FileUpload_MaxFileSize, close } = this.props; - const { window: { width } } = this.props; - const errorMessage = (FileUpload_MaxFileSize < file.size) - ? 'error-file-too-large' - : 'error-invalid-file-type'; - return ( - - - {I18n.t(errorMessage)} - - - - - { file.mime } - - { - (isIOS) - ? ( -