[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 { 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);
}
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 {
// Verify if server is real
yield RocketChat.testServer(host);
} catch (error) {
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
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'));

View File

@ -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 });

View File

@ -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 });
}