Create single-server

This commit is contained in:
Diego Mello 2019-12-12 09:13:57 -03:00
parent 9bea72faac
commit 6e66897089
5 changed files with 25 additions and 38 deletions

View File

@ -1,5 +1,6 @@
{ {
"name": "RocketChatRN", "name": "RocketChatRN",
"share": "ShareRocketChatRN", "share": "ShareRocketChatRN",
"displayName": "RocketChatRN" "displayName": "RocketChatRN",
"server": "https://open.rocket.chat"
} }

View File

@ -67,13 +67,13 @@ const parseDeepLinking = (url) => {
// Outside // Outside
const OutsideStack = createStackNavigator({ const OutsideStack = createStackNavigator({
OnboardingView: { // OnboardingView: {
getScreen: () => require('./views/OnboardingView').default, // getScreen: () => require('./views/OnboardingView').default,
header: null // header: null
}, // },
NewServerView: { // NewServerView: {
getScreen: () => require('./views/NewServerView').default // getScreen: () => require('./views/NewServerView').default
}, // },
LoginSignupView: { LoginSignupView: {
getScreen: () => require('./views/LoginSignupView').default getScreen: () => require('./views/LoginSignupView').default
}, },

View File

@ -5,7 +5,7 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import RNBootSplash from 'react-native-bootsplash'; import RNBootSplash from 'react-native-bootsplash';
import * as actions from '../actions'; import * as actions from '../actions';
import { selectServerRequest } from '../actions/server'; import { selectServerRequest, serverRequest } from '../actions/server';
import { setAllPreferences } from '../actions/sortPreferences'; import { setAllPreferences } from '../actions/sortPreferences';
import { toggleCrashReport } from '../actions/crashReport'; import { toggleCrashReport } from '../actions/crashReport';
import { APP } from '../actions/actionsTypes'; import { APP } from '../actions/actionsTypes';
@ -18,6 +18,7 @@ import {
import { isIOS } from '../utils/deviceInfo'; import { isIOS } from '../utils/deviceInfo';
import database from '../lib/database'; import database from '../lib/database';
import protectedFunction from '../lib/methods/helpers/protectedFunction'; import protectedFunction from '../lib/methods/helpers/protectedFunction';
import appConfig from '../../app.json';
export const initLocalSettings = function* initLocalSettings() { export const initLocalSettings = function* initLocalSettings() {
const sortPreferences = yield RocketChat.getSortPreferences(); const sortPreferences = yield RocketChat.getSortPreferences();
@ -95,7 +96,7 @@ const restore = function* restore() {
RNUserDefaults.clear(RocketChat.TOKEN_KEY), RNUserDefaults.clear(RocketChat.TOKEN_KEY),
RNUserDefaults.clear('currentServer') RNUserDefaults.clear('currentServer')
]); ]);
yield put(actions.appStart('outside')); yield put(serverRequest(appConfig.server));
} else { } else {
const serversDB = database.servers; const serversDB = database.servers;
const serverCollections = serversDB.collections.get('servers'); const serverCollections = serversDB.collections.get('servers');

View File

@ -8,7 +8,7 @@ import 'moment/min/locales';
import * as types from '../actions/actionsTypes'; import * as types from '../actions/actionsTypes';
import { appStart } from '../actions'; import { appStart } from '../actions';
import { serverFinishAdd, selectServerRequest } from '../actions/server'; import { serverFinishAdd, serverRequest } from '../actions/server';
import { import {
loginFailure, loginSuccess, setUser, logout loginFailure, loginSuccess, setUser, logout
} from '../actions/login'; } from '../actions/login';
@ -21,6 +21,7 @@ import database from '../lib/database';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
import { inviteLinksRequest } from '../actions/inviteLinks'; import { inviteLinksRequest } from '../actions/inviteLinks';
import { showErrorAlert } from '../utils/info'; import { showErrorAlert } from '../utils/info';
import appConfig from '../../app.json';
const getServer = state => state.server.server; const getServer = state => state.server.server;
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args); const loginWithPasswordCall = args => RocketChat.loginWithPassword(args);
@ -158,25 +159,8 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
if (forcedByServer) { if (forcedByServer) {
yield put(appStart('outside')); yield put(appStart('outside'));
showErrorAlert(I18n.t('Logged_out_by_server'), I18n.t('Oops')); showErrorAlert(I18n.t('Logged_out_by_server'), I18n.t('Oops'));
EventEmitter.emit('NewServer', { server });
} else { } else {
const serversDB = database.servers; yield put(serverRequest(appConfig.server));
// all servers
const serversCollection = serversDB.collections.get('servers');
const servers = yield serversCollection.query().fetch();
// see if there're other logged in servers and selects first one
if (servers.length > 0) {
for (let i = 0; i < servers.length; i += 1) {
const newServer = servers[i].id;
const token = yield RNUserDefaults.get(`${ RocketChat.TOKEN_KEY }-${ newServer }`);
if (token) {
return yield put(selectServerRequest(newServer));
}
}
}
// if there's no servers, go outside
yield put(appStart('outside'));
} }
} catch (e) { } catch (e) {
yield put(appStart('outside')); yield put(appStart('outside'));

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { import {
Text, View, TouchableOpacity, Image, StyleSheet Text, View, StyleSheet
} from 'react-native'; } from 'react-native';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
@ -49,10 +49,10 @@ const HeaderTitle = React.memo(({ connecting, isFetching, theme }) => {
}); });
const Header = React.memo(({ const Header = React.memo(({
connecting, isFetching, serverName, showServerDropdown, onPress, theme connecting, isFetching, theme
}) => ( }) => (
<View style={styles.container}> <View style={styles.container}>
<TouchableOpacity {/* <TouchableOpacity
onPress={onPress} onPress={onPress}
testID='rooms-list-header-server-dropdown-button' testID='rooms-list-header-server-dropdown-button'
style={styles.container} style={styles.container}
@ -63,22 +63,23 @@ const Header = React.memo(({
<Text style={[styles.server, { color: themes[theme].headerTintColor }]}>{serverName}</Text> <Text style={[styles.server, { color: themes[theme].headerTintColor }]}>{serverName}</Text>
<Image style={[styles.disclosure, showServerDropdown && styles.upsideDown]} source={{ uri: 'disclosure_indicator_server' }} /> <Image style={[styles.disclosure, showServerDropdown && styles.upsideDown]} source={{ uri: 'disclosure_indicator_server' }} />
</View> </View>
</TouchableOpacity> </TouchableOpacity> */}
<HeaderTitle connecting={connecting} isFetching={isFetching} theme={theme} />
</View> </View>
)); ));
Header.propTypes = { Header.propTypes = {
connecting: PropTypes.bool, connecting: PropTypes.bool,
isFetching: PropTypes.bool, isFetching: PropTypes.bool,
serverName: PropTypes.string, // serverName: PropTypes.string,
theme: PropTypes.string, theme: PropTypes.string,
showServerDropdown: PropTypes.bool.isRequired, // showServerDropdown: PropTypes.bool.isRequired,
onPress: PropTypes.func.isRequired onPress: PropTypes.func.isRequired
}; };
Header.defaultProps = { // Header.defaultProps = {
serverName: 'Rocket.Chat' // serverName: 'Rocket.Chat'
}; // };
HeaderTitle.propTypes = { HeaderTitle.propTypes = {
connecting: PropTypes.bool, connecting: PropTypes.bool,