Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions app/sagas/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { put, takeLatest } from 'redux-saga/effects';
import { put, takeLatest, all } from 'redux-saga/effects';
import RNBootSplash from 'react-native-bootsplash';

// import * as actions from '../actions';
Expand Down Expand Up @@ -28,26 +28,15 @@ export const initLocalSettings = function* initLocalSettings() {

const restore = function* restore() {
try {
const server = yield UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER);
let userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
const { server } = appConfig;
const userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);

if (!server) {
yield put(appStart({ root: ROOT_OUTSIDE }));
} else if (!userId) {
const serversDB = database.servers;
const serversCollection = serversDB.get('servers');
const servers = yield serversCollection.query().fetch();

// Check if there're other logged in servers and picks first one
if (servers.length > 0) {
for (let i = 0; i < servers.length; i += 1) {
const newServer = servers[i].id;
userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ newServer }`);
if (userId) {
return yield put(selectServerRequest(newServer));
}
}
}
if (!userId) {
yield all([
UserPreferences.removeItem(RocketChat.TOKEN_KEY),
UserPreferences.removeItem(RocketChat.CURRENT_SERVER)
]);
yield put(serverRequest(appConfig.server));
yield put(appStart({ root: ROOT_OUTSIDE }));
} else {
const serversDB = database.servers;
Expand Down