[FIX] Unsubscribe rooms listeners on server change (#1153)
This commit is contained in:
parent
c78732729d
commit
0aeedbb2f2
|
@ -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({
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue