[FIX] Load messages on notification tap (#564)

This commit is contained in:
Diego Mello 2018-12-07 15:47:50 -02:00 committed by GitHub
parent bdc564c281
commit dca2181b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 18 deletions

View File

@ -1,7 +1,7 @@
import { AsyncStorage } from 'react-native'; import { AsyncStorage } from 'react-native';
import { delay } from 'redux-saga'; import { delay } from 'redux-saga';
import { import {
takeLatest, take, select, put takeLatest, take, select, put, all
} from 'redux-saga/effects'; } from 'redux-saga/effects';
import { Navigation } from 'react-native-navigation'; import { Navigation } from 'react-native-navigation';
@ -51,7 +51,6 @@ const navigate = function* navigate({ params, sameServer = true }) {
const handleOpen = function* handleOpen({ params }) { const handleOpen = function* handleOpen({ params }) {
const isReady = yield select(state => state.app.ready); const isReady = yield select(state => state.app.ready);
const server = yield select(state => state.server.server);
if (!isReady) { if (!isReady) {
yield take(types.APP.READY); yield take(types.APP.READY);
@ -70,26 +69,31 @@ const handleOpen = function* handleOpen({ params }) {
host = host.slice(0, host.length - 1); host = host.slice(0, host.length - 1);
} }
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 (user) {
yield take(types.SERVER.SELECT_SUCCESS);
yield navigate({ params });
}
} else {
// if deep link is from a different server
try { try {
// Verify if server is real
yield RocketChat.testServer(host); yield RocketChat.testServer(host);
} catch (error) { } catch (error) {
return; return;
} }
const token = yield AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ host }`);
// TODO: needs better test
// if deep link is from same server
if (server === host) {
if (token) {
yield navigate({ params });
}
} else { // if deep link is from a different server
// search if deep link's server already exists // search if deep link's server already exists
const servers = yield database.databases.serversDB.objects('servers').filtered('id = $0', host); // TODO: need better test 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 put(selectServerRequest(host));
yield take(types.METEOR.REQUEST);
yield navigate({ params, sameServer: false }); yield navigate({ params, sameServer: false });
} else { } else {
yield put(appStart('outside')); yield put(appStart('outside'));

View File

@ -68,16 +68,17 @@ const watchRoomOpen = function* watchRoomOpen({ room }) {
} }
opened = true; opened = true;
const auth = yield select(state => state.login.isAuthenticated);
if (!auth) {
yield take(types.LOGIN.SUCCESS);
}
yield put(messagesRequest({ ...room })); yield put(messagesRequest({ ...room }));
if (room._id) { if (room._id) {
RocketChat.readMessages(room.rid); RocketChat.readMessages(room.rid);
} }
const auth = yield select(state => state.login.isAuthenticated);
if (!auth) {
yield take(types.LOGIN.SUCCESS);
}
sub = yield RocketChat.subscribeRoom(room); sub = yield RocketChat.subscribeRoom(room);
thread = yield fork(usersTyping, { rid: room.rid }); thread = yield fork(usersTyping, { rid: room.rid });

View File

@ -24,9 +24,9 @@ const handleSelectServer = function* handleSelectServer({ server }) {
if (userStringified) { if (userStringified) {
const user = JSON.parse(userStringified); const user = JSON.parse(userStringified);
RocketChat.connect({ server, user });
yield put(setUser(user)); yield put(setUser(user));
yield put(actions.appStart('inside')); yield put(actions.appStart('inside'));
RocketChat.connect({ server, user });
} else { } else {
RocketChat.connect({ server }); RocketChat.connect({ server });
} }