From 2e99a71a0d5d4952c5cf8a853bf57bd34c5e78f2 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 24 Apr 2017 17:39:23 -0300 Subject: [PATCH] Several Fixes (#495) * Revert files to use APIv3 * Fix channel intro constants * Add src to transpiler for mattermost-redux * Fix android back button * Fix check for MFA * feedback review --- .babelrc | 2 +- android/app/src/main/AndroidManifest.xml | 8 ++++-- .../java/com/mattermost/MainActivity.java | 13 +++++++++ app/components/channel_intro/channel_intro.js | 28 +++++++++---------- app/components/channel_intro/index.js | 8 +++--- .../file_attachment_image.js | 12 ++++---- .../profile_picture/profile_picture.js | 8 ++---- app/scenes/login/login.js | 2 +- app/scenes/root/root.js | 3 +- app/scenes/select_server/select_server.js | 3 +- 10 files changed, 51 insertions(+), 36 deletions(-) diff --git a/.babelrc b/.babelrc index 5fdee0245..dacd468e9 100644 --- a/.babelrc +++ b/.babelrc @@ -2,7 +2,7 @@ "presets": [ "react-native" ], "plugins": [ ["module-resolver", { - "root": ["."], + "root": ["./src", "."], "alias": { "assets": "./dist/assets" } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3f2108031..b635ad036 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -26,12 +26,16 @@ android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + > + android:configChanges="keyboard|keyboardHidden|orientation|screenSize" + android:launchMode="singleInstance" + android:taskAffinity="" + > diff --git a/android/app/src/main/java/com/mattermost/MainActivity.java b/android/app/src/main/java/com/mattermost/MainActivity.java index 76f26b7f9..37acf3781 100644 --- a/android/app/src/main/java/com/mattermost/MainActivity.java +++ b/android/app/src/main/java/com/mattermost/MainActivity.java @@ -34,4 +34,17 @@ public class MainActivity extends ReactActivity { intent.putExtra("newConfig", newConfig); this.sendBroadcast(intent); } + + /** + * When the back button is pressed and the app is closed it will + * be sent to the background instead of exiting fixing the newIntent + * problem where the splash screen wasn't being removed + */ + @Override + public void invokeDefaultOnBackPressed() { + Intent setIntent = new Intent(Intent.ACTION_MAIN); + setIntent.addCategory(Intent.CATEGORY_HOME); + setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(setIntent); + } } diff --git a/app/components/channel_intro/channel_intro.js b/app/components/channel_intro/channel_intro.js index 863a4a016..b7f5d5c35 100644 --- a/app/components/channel_intro/channel_intro.js +++ b/app/components/channel_intro/channel_intro.js @@ -8,7 +8,7 @@ import { View } from 'react-native'; import {getFullName} from 'mattermost-redux/utils/user_utils'; -import {Constants} from 'mattermost-redux/constants'; +import {General} from 'mattermost-redux/constants'; import {injectIntl, intlShape} from 'react-intl'; import ProfilePicture from 'app/components/profile_picture'; @@ -55,7 +55,7 @@ class ChannelIntro extends PureComponent { /> )); - } + }; buildNames = () => { const {currentChannelMembers, theme} = this.props; @@ -64,7 +64,7 @@ class ChannelIntro extends PureComponent { const names = currentChannelMembers.map((member) => this.getDisplayName(member)); return {names.join(', ')}; - } + }; buildDMContent = () => { const {currentChannelMembers, intl, theme} = this.props; @@ -81,7 +81,7 @@ class ChannelIntro extends PureComponent { })} ); - } + }; buildGMContent = () => { const {intl, theme} = this.props; @@ -95,7 +95,7 @@ class ChannelIntro extends PureComponent { })} ); - } + }; buildOpenChannelContent = () => { const {currentChannel, currentChannelMembers, currentUser, intl, theme} = this.props; @@ -164,7 +164,7 @@ class ChannelIntro extends PureComponent { ); - } + }; buildPrivateChannelContent = () => { const {currentChannel, currentChannelMembers, currentUser, intl, theme} = this.props; @@ -211,7 +211,7 @@ class ChannelIntro extends PureComponent { ); - } + }; buildTownSquareContent = () => { const {currentChannel, intl, theme} = this.props; @@ -243,32 +243,32 @@ class ChannelIntro extends PureComponent { ); - } + }; buildContent = () => { const {currentChannel} = this.props; switch (currentChannel.type) { default: - case Constants.DM_CHANNEL: + case General.DM_CHANNEL: return this.buildDMContent(); - case Constants.GM_CHANNEL: + case General.GM_CHANNEL: return this.buildGMContent(); - case Constants.OPEN_CHANNEL: { - if (currentChannel.name === Constants.DEFAULT_CHANNEL) { + case General.OPEN_CHANNEL: { + if (currentChannel.name === General.DEFAULT_CHANNEL) { return this.buildTownSquareContent(); } return this.buildOpenChannelContent(); } - case Constants.PRIVATE_CHANNEL: + case General.PRIVATE_CHANNEL: return this.buildPrivateChannelContent(); } - } + }; render() { const {theme} = this.props; diff --git a/app/components/channel_intro/index.js b/app/components/channel_intro/index.js index 04c642e0e..6d03499cc 100644 --- a/app/components/channel_intro/index.js +++ b/app/components/channel_intro/index.js @@ -3,7 +3,7 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {Constants} from 'mattermost-redux/constants'; +import {General} from 'mattermost-redux/constants'; import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentUser, getProfilesInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; @@ -16,12 +16,12 @@ function mapStateToProps(state) { const currentUser = getCurrentUser(state); let currentChannelMembers = []; - if (currentChannel.type === Constants.DM_CHANNEL) { - const otherChannelMember = currentChannel.name.split('__').find((m) => m.id !== currentUser.id); + if (currentChannel.type === General.DM_CHANNEL) { + const otherChannelMember = currentChannel.name.split('__').find((m) => m !== currentUser.id); currentChannelMembers.push(state.entities.users.profiles[otherChannelMember]); } - if (currentChannel.type === Constants.GM_CHANNEL) { + if (currentChannel.type === General.GM_CHANNEL) { currentChannelMembers = getProfilesInCurrentChannel(state); } diff --git a/app/components/file_attachment_list/file_attachment_image.js b/app/components/file_attachment_list/file_attachment_image.js index 4c45a4d8c..2d8c560c8 100644 --- a/app/components/file_attachment_list/file_attachment_image.js +++ b/app/components/file_attachment_list/file_attachment_image.js @@ -13,7 +13,7 @@ import { StyleSheet } from 'react-native'; -import {Client4} from 'mattermost-redux/client'; +import {Client} from 'mattermost-redux/client'; import imageIcon from 'assets/images/icons/image.png'; @@ -25,8 +25,6 @@ const IMAGE_SIZE = { Thumbnail: 'thumbnail' }; -const IMAGE_HEADERS = Client4.getOptions().headers; - export default class FileAttachmentImage extends PureComponent { static propTypes = { addFileToFetchCache: PropTypes.func.isRequired, @@ -105,12 +103,12 @@ export default class FileAttachmentImage extends PureComponent { switch (imageSize) { case IMAGE_SIZE.Fullsize: - return Client4.getFileUrl(file.id, this.state.timestamp); + return Client.getFileUrl(file.id, this.state.timestamp); case IMAGE_SIZE.Preview: - return Client4.getFilePreviewUrl(file.id, this.state.timestamp); + return Client.getFilePreviewUrl(file.id, this.state.timestamp); case IMAGE_SIZE.Thumbnail: default: - return Client4.getFileThumbnailUrl(file.id, this.state.timestamp); + return Client.getFileThumbnailUrl(file.id, this.state.timestamp); } }; @@ -133,7 +131,7 @@ export default class FileAttachmentImage extends PureComponent { if (this.state.retry === 4) { source = imageIcon; } else if (file.id) { - source = {uri: this.handleGetImageURL(), headers: IMAGE_HEADERS}; + source = {uri: this.handleGetImageURL()}; } const isInFetchCache = fetchCache[source.uri]; diff --git a/app/components/profile_picture/profile_picture.js b/app/components/profile_picture/profile_picture.js index 61928e6ef..f79295237 100644 --- a/app/components/profile_picture/profile_picture.js +++ b/app/components/profile_picture/profile_picture.js @@ -9,7 +9,7 @@ import {makeStyleSheetFromTheme} from 'app/utils/theme'; import placeholder from 'assets/images/profile.jpg'; -import {Client4} from 'mattermost-redux/client'; +import {Client} from 'mattermost-redux/client'; const statusToIcon = { online: 'check', @@ -21,8 +21,6 @@ const STATUS_BUFFER = Platform.select({ android: 2 }); -const IMAGE_HEADERS = Client4.getOptions().headers; - export default class ProfilePicture extends React.PureComponent { static propTypes = { size: React.PropTypes.number, @@ -55,7 +53,7 @@ export default class ProfilePicture extends React.PureComponent { let pictureUrl; if (this.props.user) { - pictureUrl = Client4.getProfilePictureUrl(this.props.user.id, this.props.user.last_picture_update); + pictureUrl = Client.getProfilePictureUrl(this.props.user.id, this.props.user.last_picture_update); } let statusIcon; @@ -87,7 +85,7 @@ export default class ProfilePicture extends React.PureComponent { {this.props.status && diff --git a/app/scenes/login/login.js b/app/scenes/login/login.js index 253d8d078..aa5785837 100644 --- a/app/scenes/login/login.js +++ b/app/scenes/login/login.js @@ -123,7 +123,7 @@ class Login extends Component { } if (this.props.config.EnableMultifactorAuthentication === 'true') { this.props.actions.checkMfa(this.props.loginId).then((result) => { - if (result.mfa_required === 'true') { + if (result) { this.props.actions.goToMfa(); } else { this.signIn(); diff --git a/app/scenes/root/root.js b/app/scenes/root/root.js index 727c7f9a2..bfb4b0aec 100644 --- a/app/scenes/root/root.js +++ b/app/scenes/root/root.js @@ -5,7 +5,7 @@ import React, {PropTypes, PureComponent} from 'react'; import Orientation from 'react-native-orientation'; import SplashScreen from 'react-native-smart-splash-screen'; -import {Client4} from 'mattermost-redux/client'; +import {Client, Client4} from 'mattermost-redux/client'; import {RequestStatus} from 'mattermost-redux/constants'; import Loading from 'app/components/loading'; @@ -63,6 +63,7 @@ export default class Root extends PureComponent { if (loginRequest.status === RequestStatus.NOT_STARTED) { Client4.setToken(credentials.token); Client4.setUrl(stripTrailingSlashes(credentials.url)); + Client.setUrl(stripTrailingSlashes(credentials.url)); loadMe().then(goToLoadTeam).catch(goToLoadTeam); } else { diff --git a/app/scenes/select_server/select_server.js b/app/scenes/select_server/select_server.js index a5d1c333b..784cc2650 100644 --- a/app/scenes/select_server/select_server.js +++ b/app/scenes/select_server/select_server.js @@ -16,7 +16,7 @@ import { import Button from 'react-native-button'; import {RequestStatus} from 'mattermost-redux/constants'; -import {Client4} from 'mattermost-redux/client'; +import {Client, Client4} from 'mattermost-redux/client'; import ErrorText from 'app/components/error_text'; import FormattedText from 'app/components/formatted_text'; @@ -84,6 +84,7 @@ export default class SelectServer extends PureComponent { if (isValidUrl(url)) { Client4.setUrl(stripTrailingSlashes(url)); + Client.setUrl(stripTrailingSlashes(url)); await this.props.actions.getPing(); } else { error = {