[FIX] Lazy fetch server info (#959)
This commit is contained in:
parent
637ea54958
commit
86b79be15e
|
@ -11,11 +11,13 @@ import database from '../lib/realm';
|
|||
import log from '../utils/log';
|
||||
import I18n from '../i18n';
|
||||
|
||||
const getServerInfo = function* getServerInfo({ server }) {
|
||||
const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
|
||||
try {
|
||||
const serverInfo = yield RocketChat.getServerInfo(server);
|
||||
if (!serverInfo.success) {
|
||||
if (raiseError) {
|
||||
Alert.alert(I18n.t('Oops'), I18n.t(serverInfo.message, serverInfo.messageOptions));
|
||||
}
|
||||
yield put(serverFailure());
|
||||
return;
|
||||
}
|
||||
|
@ -32,10 +34,6 @@ const getServerInfo = function* getServerInfo({ server }) {
|
|||
|
||||
const handleSelectServer = function* handleSelectServer({ server, version, fetchVersion }) {
|
||||
try {
|
||||
let serverInfo;
|
||||
if (fetchVersion) {
|
||||
serverInfo = yield getServerInfo({ server });
|
||||
}
|
||||
yield AsyncStorage.setItem('currentServer', server);
|
||||
const userStringified = yield AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ server }`);
|
||||
|
||||
|
@ -52,7 +50,13 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
|||
const settings = database.objects('settings');
|
||||
yield put(actions.setAllSettings(RocketChat.parseSettings(settings.slice(0, settings.length))));
|
||||
|
||||
yield put(selectServerSuccess(server, fetchVersion ? serverInfo && serverInfo.version : version));
|
||||
let serverInfo;
|
||||
if (fetchVersion) {
|
||||
serverInfo = yield getServerInfo({ server, raiseError: false });
|
||||
}
|
||||
|
||||
// Return server version even when offline
|
||||
yield put(selectServerSuccess(server, (serverInfo && serverInfo.version) || version));
|
||||
} catch (e) {
|
||||
log('err_select_server', e);
|
||||
}
|
||||
|
@ -62,7 +66,6 @@ const handleServerRequest = function* handleServerRequest({ server }) {
|
|||
try {
|
||||
const serverInfo = yield getServerInfo({ server });
|
||||
|
||||
// TODO: cai aqui O.o
|
||||
const loginServicesLength = yield RocketChat.getLoginServices(server);
|
||||
if (loginServicesLength === 0) {
|
||||
Navigation.navigate('LoginView');
|
||||
|
|
Loading…
Reference in New Issue