[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 = {
TOKEN_KEY,
subscribeRooms,
async subscribeRooms() {
if (this.roomsSub) {
this.roomsSub.stop();
}
this.roomsSub = await subscribeRooms.call(this);
},
subscribeRoom,
canOpenRoom,
createChannel({

View File

@ -1,5 +1,5 @@
import {
put, select, race, take, fork, cancel, takeLatest, delay
put, select, race, take, fork, cancel, delay
} from 'redux-saga/effects';
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 RocketChat from '../lib/rocketchat';
let roomsSub;
const removeSub = function removeSub() {
if (roomsSub && roomsSub.stop) {
roomsSub.stop();
}
};
const handleRoomsRequest = function* handleRoomsRequest() {
try {
removeSub();
roomsSub = yield RocketChat.subscribeRooms();
yield RocketChat.subscribeRooms();
const newRoomsUpdatedAt = new Date();
const server = yield select(state => state.server.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() {
yield takeLatest(types.LOGOUT, handleLogout);
while (true) {
const params = yield take(types.ROOMS.REQUEST);
const isAuthenticated = yield select(state => state.login.isAuthenticated);