Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Load messages on notification tap #564

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
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
30 changes: 17 additions & 13 deletions app/sagas/deepLinking.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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'));
Expand Down
9 changes: 5 additions & 4 deletions app/sagas/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion app/sagas/selectServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down