2017-08-17 06:28:41 +00:00
|
|
|
import { takeEvery, takeLatest, select, take, put } from 'redux-saga/effects';
|
|
|
|
import { MESSAGES, LOGIN } from '../actions/actionsTypes';
|
|
|
|
import { messagesSuccess, messagesFailure } from '../actions/messages';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
|
|
|
|
|
|
|
const get = function* get({ rid }) {
|
|
|
|
const auth = yield select(state => state.login.isAuthenticated);
|
2017-08-21 00:11:46 +00:00
|
|
|
console.log('hey now', yield select(state => state.login));
|
2017-08-17 06:28:41 +00:00
|
|
|
if (!auth) {
|
|
|
|
yield take(LOGIN.SUCCESS);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yield RocketChat.loadMessagesForRoom(rid, null);
|
|
|
|
yield put(messagesSuccess());
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
yield put(messagesFailure(err.status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const getData = function* getData() {
|
|
|
|
yield takeLatest(MESSAGES.REQUEST, get);
|
|
|
|
};
|
2017-08-21 00:11:46 +00:00
|
|
|
export default getData;
|