2018-04-24 19:34:03 +00:00
|
|
|
import { put, takeLatest } from 'redux-saga/effects';
|
2018-03-23 16:49:51 +00:00
|
|
|
import * as types from '../actions/actionsTypes';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { readyRoomFiles } from '../actions/roomFiles';
|
2018-03-23 16:49:51 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
let sub;
|
|
|
|
let newSub;
|
|
|
|
|
|
|
|
const openRoomFiles = function* openRoomFiles({ rid, limit }) {
|
|
|
|
newSub = yield RocketChat.subscribe('roomFiles', rid, limit);
|
|
|
|
yield put(readyRoomFiles());
|
|
|
|
if (sub) {
|
|
|
|
sub.unsubscribe().catch(e => console.warn('openRoomFiles', e));
|
|
|
|
}
|
|
|
|
sub = newSub;
|
|
|
|
};
|
|
|
|
|
|
|
|
const closeRoomFiles = function* closeRoomFiles() {
|
|
|
|
if (sub) {
|
|
|
|
yield sub.unsubscribe().catch(e => console.warn('closeRoomFiles sub', e));
|
|
|
|
}
|
|
|
|
if (newSub) {
|
|
|
|
yield newSub.unsubscribe().catch(e => console.warn('closeRoomFiles newSub', e));
|
|
|
|
}
|
2018-03-23 16:49:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const root = function* root() {
|
2018-04-24 19:34:03 +00:00
|
|
|
yield takeLatest(types.ROOM_FILES.OPEN, openRoomFiles);
|
|
|
|
yield takeLatest(types.ROOM_FILES.CLOSE, closeRoomFiles);
|
2018-03-23 16:49:51 +00:00
|
|
|
};
|
|
|
|
export default root;
|