[FIX] Unsubscribe rooms listeners on server change (#1153)

This commit is contained in:
Diego Mello 2019-08-27 14:41:07 -03:00 committed by GitHub
parent c78732729d
commit 0aeedbb2f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 17 deletions

View File

@ -53,7 +53,12 @@ const STATUSES = ['offline', 'online', 'away', 'busy'];
const RocketChat = { const RocketChat = {
TOKEN_KEY, TOKEN_KEY,
subscribeRooms, async subscribeRooms() {
if (this.roomsSub) {
this.roomsSub.stop();
}
this.roomsSub = await subscribeRooms.call(this);
},
subscribeRoom, subscribeRoom,
canOpenRoom, canOpenRoom,
createChannel({ createChannel({

View File

@ -1,5 +1,5 @@
import { import {
put, select, race, take, fork, cancel, takeLatest, delay put, select, race, take, fork, cancel, delay
} from 'redux-saga/effects'; } from 'redux-saga/effects';
import { BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate'; import { BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
@ -10,18 +10,9 @@ import log from '../utils/log';
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms'; import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
let roomsSub;
const removeSub = function removeSub() {
if (roomsSub && roomsSub.stop) {
roomsSub.stop();
}
};
const handleRoomsRequest = function* handleRoomsRequest() { const handleRoomsRequest = function* handleRoomsRequest() {
try { try {
removeSub(); yield RocketChat.subscribeRooms();
roomsSub = yield RocketChat.subscribeRooms();
const newRoomsUpdatedAt = new Date(); const newRoomsUpdatedAt = new Date();
const server = yield select(state => state.server.server); const server = yield select(state => state.server.server);
const [serverRecord] = database.databases.serversDB.objects('servers').filtered('id = $0', server); const [serverRecord] = database.databases.serversDB.objects('servers').filtered('id = $0', server);
@ -53,12 +44,7 @@ const handleRoomsRequest = function* handleRoomsRequest() {
} }
}; };
const handleLogout = function handleLogout() {
removeSub();
};
const root = function* root() { const root = function* root() {
yield takeLatest(types.LOGOUT, handleLogout);
while (true) { while (true) {
const params = yield take(types.ROOMS.REQUEST); const params = yield take(types.ROOMS.REQUEST);
const isAuthenticated = yield select(state => state.login.isAuthenticated); const isAuthenticated = yield select(state => state.login.isAuthenticated);