[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 log from '../utils/log';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
|
|
||||||
const getServerInfo = function* getServerInfo({ server }) {
|
const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
|
||||||
try {
|
try {
|
||||||
const serverInfo = yield RocketChat.getServerInfo(server);
|
const serverInfo = yield RocketChat.getServerInfo(server);
|
||||||
if (!serverInfo.success) {
|
if (!serverInfo.success) {
|
||||||
|
if (raiseError) {
|
||||||
Alert.alert(I18n.t('Oops'), I18n.t(serverInfo.message, serverInfo.messageOptions));
|
Alert.alert(I18n.t('Oops'), I18n.t(serverInfo.message, serverInfo.messageOptions));
|
||||||
|
}
|
||||||
yield put(serverFailure());
|
yield put(serverFailure());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +34,6 @@ const getServerInfo = function* getServerInfo({ server }) {
|
||||||
|
|
||||||
const handleSelectServer = function* handleSelectServer({ server, version, fetchVersion }) {
|
const handleSelectServer = function* handleSelectServer({ server, version, fetchVersion }) {
|
||||||
try {
|
try {
|
||||||
let serverInfo;
|
|
||||||
if (fetchVersion) {
|
|
||||||
serverInfo = yield getServerInfo({ server });
|
|
||||||
}
|
|
||||||
yield AsyncStorage.setItem('currentServer', server);
|
yield AsyncStorage.setItem('currentServer', server);
|
||||||
const userStringified = yield AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ 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');
|
const settings = database.objects('settings');
|
||||||
yield put(actions.setAllSettings(RocketChat.parseSettings(settings.slice(0, settings.length))));
|
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) {
|
} catch (e) {
|
||||||
log('err_select_server', e);
|
log('err_select_server', e);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +66,6 @@ const handleServerRequest = function* handleServerRequest({ server }) {
|
||||||
try {
|
try {
|
||||||
const serverInfo = yield getServerInfo({ server });
|
const serverInfo = yield getServerInfo({ server });
|
||||||
|
|
||||||
// TODO: cai aqui O.o
|
|
||||||
const loginServicesLength = yield RocketChat.getLoginServices(server);
|
const loginServicesLength = yield RocketChat.getLoginServices(server);
|
||||||
if (loginServicesLength === 0) {
|
if (loginServicesLength === 0) {
|
||||||
Navigation.navigate('LoginView');
|
Navigation.navigate('LoginView');
|
||||||
|
|
Loading…
Reference in New Issue