diff --git a/app/components/logout/index.js b/app/components/logout/index.js deleted file mode 100644 index 0e5754cd9..000000000 --- a/app/components/logout/index.js +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import LogoutContainer from './logout_container'; - -export default LogoutContainer; diff --git a/app/components/logout/logout.js b/app/components/logout/logout.js deleted file mode 100644 index 53582ca73..000000000 --- a/app/components/logout/logout.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import React from 'react'; - -import {TouchableHighlight} from 'react-native'; -import FormattedText from 'app/components/formatted_text'; - -export default class Logout extends React.Component { - static propTypes = { - actions: React.PropTypes.object.isRequired - } - - render() { - return ( - - - - ); - } -} diff --git a/app/components/logout/logout_container.js b/app/components/logout/logout_container.js deleted file mode 100644 index 264c881a2..000000000 --- a/app/components/logout/logout_container.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {bindActionCreators} from 'redux'; -import {connect} from 'react-redux'; - -import {logout} from 'mattermost-redux/actions/users'; - -import Logout from './logout.js'; - -function mapDispatchToProps(dispatch) { - return { - actions: bindActionCreators({logout}, dispatch) - }; -} - -export default connect(null, mapDispatchToProps)(Logout); diff --git a/app/components/root/root.js b/app/components/root/root.js index a37f5b267..8760f4c4e 100644 --- a/app/components/root/root.js +++ b/app/components/root/root.js @@ -2,15 +2,18 @@ // See License.txt for license information. import React, {Component, PropTypes} from 'react'; -import {AppState, StatusBar, View} from 'react-native'; +import {Alert, AppState, AsyncStorage, InteractionManager, StatusBar, View} from 'react-native'; import {IntlProvider} from 'react-intl'; import DeviceInfo from 'react-native-device-info'; +import semver from 'semver'; + +import Config from 'assets/config'; import PushNotification from 'app/components/push_notification'; +import {getTranslations} from 'app/i18n'; import Client from 'mattermost-redux/client'; import {Constants} from 'mattermost-redux/constants'; -import {getTranslations} from 'app/i18n'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; export default class Root extends Component { @@ -20,9 +23,12 @@ export default class Root extends Component { currentChannelId: PropTypes.string, locale: PropTypes.string.isRequired, actions: PropTypes.shape({ + closeDrawers: PropTypes.func.isRequired, loadConfigAndLicense: PropTypes.func.isRequired, + logout: PropTypes.func.isRequired, setAppState: PropTypes.func.isRequired, - flushToStorage: PropTypes.func.isRequired + flushToStorage: PropTypes.func.isRequired, + unrenderDrawer: PropTypes.func.isRequired }).isRequired }; @@ -53,8 +59,41 @@ export default class Root extends Component { } } + handleVersionUpgrade = async () => { + const {closeDrawers, logout, unrenderDrawer} = this.props.actions; + + Client.serverVersion = ''; + + const storage = await AsyncStorage.getItem('storage'); + if (storage) { + setTimeout(async () => { + const {token} = JSON.parse(await AsyncStorage.getItem('storage')); + if (token) { + closeDrawers(); + unrenderDrawer(); + InteractionManager.runAfterInteractions(logout); + } + }, 1000); + } + }; + handleConfigChanged = (serverVersion) => { - this.props.actions.loadConfigAndLicense(serverVersion); + const {loadConfigAndLicense} = this.props.actions; + const version = serverVersion.match(/^[0-9]*.[0-9]*.[0-9]*(-[a-zA-Z0-9.-]*)?/g)[0]; + if (serverVersion) { + if (semver.valid(version) && semver.lt(version, Config.MinServerVersion)) { + Alert.alert( + 'Server upgrade required', + 'A server upgrade is required to use the Mattermost app. Please ask your System Administrator for details.', + [{ + text: 'OK', + onPress: this.handleVersionUpgrade + }] + ); + } else { + loadConfigAndLicense(serverVersion); + } + } }; render() { diff --git a/app/components/root/root_container.js b/app/components/root/root_container.js index 2b5408665..1b7c54459 100644 --- a/app/components/root/root_container.js +++ b/app/components/root/root_container.js @@ -6,9 +6,11 @@ import {connect} from 'react-redux'; import Config from 'assets/config.json'; +import {closeDrawers, unrenderDrawer} from 'app/actions/navigation'; import {flushToStorage} from 'app/actions/storage'; import {goToNotification, loadConfigAndLicense, queueNotification} from 'app/actions/views/root'; import {setAppState, setDeviceToken} from 'mattermost-redux/actions/general'; +import {logout} from 'mattermost-redux/actions/users'; import Root from './root'; @@ -34,12 +36,15 @@ function mapStateToProps(state, ownProps) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ + closeDrawers, loadConfigAndLicense, + logout, goToNotification, queueNotification, setAppState, setDeviceToken, - flushToStorage + flushToStorage, + unrenderDrawer }, dispatch) }; } diff --git a/assets/base/config.json b/assets/base/config.json index 587710424..ed2971609 100644 --- a/assets/base/config.json +++ b/assets/base/config.json @@ -4,5 +4,6 @@ "DefaultLocale": "en", "DefaultTheme": "default", "ShowErrorsList": false, - "GooglePlaySenderId": "184930218130" + "GooglePlaySenderId": "184930218130", + "MinServerVersion": "3.7.0" } diff --git a/package.json b/package.json index bad7b086b..75f8f59e2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "redux": "3.6.0", "redux-batched-actions": "0.1.5", "redux-thunk": "2.1.0", - "reselect": "2.5.4" + "reselect": "2.5.4", + "semver": "5.3.0" }, "devDependencies": { "babel-cli": "6.23.0",