From dca2181b2c25d46494aa5bcb89362cc4d4b47e85 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 7 Dec 2018 15:47:50 -0200 Subject: [PATCH] [FIX] Load messages on notification tap (#564) --- app/sagas/deepLinking.js | 30 +++++++++++++++++------------- app/sagas/rooms.js | 9 +++++---- app/sagas/selectServer.js | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/sagas/deepLinking.js b/app/sagas/deepLinking.js index c4479e068..caa74f7d0 100644 --- a/app/sagas/deepLinking.js +++ b/app/sagas/deepLinking.js @@ -1,7 +1,7 @@ import { AsyncStorage } from 'react-native'; import { delay } from 'redux-saga'; import { - takeLatest, take, select, put + takeLatest, take, select, put, all } from 'redux-saga/effects'; import { Navigation } from 'react-native-navigation'; @@ -51,7 +51,6 @@ const navigate = function* navigate({ params, sameServer = true }) { const handleOpen = function* handleOpen({ params }) { const isReady = yield select(state => state.app.ready); - const server = yield select(state => state.server.server); if (!isReady) { yield take(types.APP.READY); @@ -70,26 +69,31 @@ const handleOpen = function* handleOpen({ params }) { host = host.slice(0, host.length - 1); } - try { - yield RocketChat.testServer(host); - } catch (error) { - return; - } - - const token = yield AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ host }`); + const [server, user] = yield all([ + AsyncStorage.getItem('currentServer'), + AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ host }`) + ]); // TODO: needs better test // if deep link is from same server if (server === host) { - if (token) { + if (user) { + yield take(types.SERVER.SELECT_SUCCESS); yield navigate({ params }); } - } else { // if deep link is from a different server + } else { + // if deep link is from a different server + try { + // Verify if server is real + yield RocketChat.testServer(host); + } catch (error) { + return; + } + // search if deep link's server already exists const servers = yield database.databases.serversDB.objects('servers').filtered('id = $0', host); // TODO: need better test - if (servers.length && token) { + if (servers.length && user) { yield put(selectServerRequest(host)); - yield take(types.METEOR.REQUEST); yield navigate({ params, sameServer: false }); } else { yield put(appStart('outside')); diff --git a/app/sagas/rooms.js b/app/sagas/rooms.js index 1296fb3b2..6c1df3a89 100644 --- a/app/sagas/rooms.js +++ b/app/sagas/rooms.js @@ -68,16 +68,17 @@ const watchRoomOpen = function* watchRoomOpen({ room }) { } opened = true; + const auth = yield select(state => state.login.isAuthenticated); + if (!auth) { + yield take(types.LOGIN.SUCCESS); + } + yield put(messagesRequest({ ...room })); if (room._id) { RocketChat.readMessages(room.rid); } - const auth = yield select(state => state.login.isAuthenticated); - if (!auth) { - yield take(types.LOGIN.SUCCESS); - } sub = yield RocketChat.subscribeRoom(room); thread = yield fork(usersTyping, { rid: room.rid }); diff --git a/app/sagas/selectServer.js b/app/sagas/selectServer.js index f3e9fd1d8..a2350ac66 100644 --- a/app/sagas/selectServer.js +++ b/app/sagas/selectServer.js @@ -24,9 +24,9 @@ const handleSelectServer = function* handleSelectServer({ server }) { if (userStringified) { const user = JSON.parse(userStringified); + RocketChat.connect({ server, user }); yield put(setUser(user)); yield put(actions.appStart('inside')); - RocketChat.connect({ server, user }); } else { RocketChat.connect({ server }); }