Merge branch 'add-lastmessage' into develop

This commit is contained in:
Guilherme Gazzo 2018-02-16 20:59:13 -02:00
commit caa67d10c3
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
4 changed files with 24 additions and 39 deletions

View File

@ -18,4 +18,4 @@
# org.gradle.parallel=true
android.useDeprecatedNdk=true
# VERSIONCODE=999999999
VERSIONCODE=999999999

View File

@ -1,9 +1,9 @@
import * as types from './actionsTypes';
export function requestActiveUser(user) {
export function requestActiveUser(users) {
return {
type: types.ACTIVE_USERS.REQUEST,
user
users
};
}

View File

@ -45,21 +45,27 @@ const RocketChat = {
throw new Error({ error: 'invalid server' });
},
_setUser(ddpMessage) {
let status;
if (!ddpMessage.fields) {
status = 'offline';
} else {
status = ddpMessage.fields.status || 'offline';
}
this.activeUsers = this.activeUsers || {};
const { user } = reduxStore.getState().login;
const status = (ddpMessage.fields && ddpMessage.fields.status) || 'offline';
if (user && user.id === ddpMessage.id) {
return reduxStore.dispatch(setUser({ status }));
}
const activeUser = {};
activeUser[ddpMessage.id] = status;
return reduxStore.dispatch(requestActiveUser(activeUser));
if (this._setUserTimer) {
clearTimeout(this._setUserTimer);
this._setUserTimer = null;
}
this._setUserTimer = setTimeout(() => {
reduxStore.dispatch(requestActiveUser(this.activeUsers));
this._setUserTimer = null;
return this.activeUsers = {};
}, 1000);
this.activeUsers[ddpMessage.id] = status;
},
reconnect() {
if (this.ddp) {
@ -94,11 +100,7 @@ const RocketChat = {
this.ddp.on('connected', () => this.ddp.subscribe('activeUsers', null, false));
this.ddp.on('users', (ddpMessage) => {
if (ddpMessage.collection === 'users') {
return RocketChat._setUser(ddpMessage);
}
});
this.ddp.on('users', ddpMessage => RocketChat._setUser(ddpMessage));
this.ddp.on('stream-room-messages', (ddpMessage) => {
const message = this._buildMessage(ddpMessage.fields.args[0]);

View File

@ -1,30 +1,13 @@
import { put, take, race, fork } from 'redux-saga/effects';
import { delay } from 'redux-saga';
import { put, takeLatest } from 'redux-saga/effects';
import * as types from '../actions/actionsTypes';
import { setActiveUser } from '../actions/activeUsers';
const watchActiveUsers = function* handleInput() {
let obj = {};
while (true) {
const { status, timeout } = yield race({
status: take(types.ACTIVE_USERS.REQUEST),
timeout: delay(3000)
});
if (timeout && Object.keys(obj).length > 0) {
yield put(setActiveUser(obj));
obj = {};
}
if (status) {
obj = {
...obj,
...status.user
};
}
}
const watchActiveUsers = function* handleInput({ users }) {
yield put(setActiveUser(users));
};
const root = function* root() {
yield fork(watchActiveUsers);
yield takeLatest(types.ACTIVE_USERS.REQUEST, watchActiveUsers);
};
export default root;