2022-04-04 19:15:29 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
|
|
|
|
|
|
|
import { setActiveUsers } from '../../../actions/activeUsers';
|
|
|
|
import { setUser } from '../../../actions/login';
|
2022-04-07 14:19:54 +00:00
|
|
|
import { store as reduxStore } from '../../store/auxStore';
|
2022-04-07 13:13:19 +00:00
|
|
|
import { compareServerVersion } from '../../methods/helpers/compareServerVersion';
|
2022-04-04 19:15:29 +00:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
export function _setUser(this: any, ddpMessage: { fields: any; id: any; cleared: any }) {
|
|
|
|
this.activeUsers = this.activeUsers || {};
|
|
|
|
const { user } = reduxStore.getState().login;
|
|
|
|
|
|
|
|
if (ddpMessage.fields && user && user.id === ddpMessage.id) {
|
|
|
|
reduxStore.dispatch(setUser(ddpMessage.fields));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ddpMessage.cleared && user && user.id === ddpMessage.id) {
|
|
|
|
reduxStore.dispatch(setUser({ status: 'offline' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
const serverVersion = reduxStore.getState().server.version;
|
|
|
|
if (compareServerVersion(serverVersion, 'lowerThan', '4.1.0')) {
|
|
|
|
if (!this._setUserTimer) {
|
|
|
|
this._setUserTimer = setTimeout(() => {
|
|
|
|
const activeUsersBatch = this.activeUsers;
|
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
|
reduxStore.dispatch(setActiveUsers(activeUsersBatch));
|
|
|
|
});
|
|
|
|
this._setUserTimer = null;
|
|
|
|
return (this.activeUsers = {});
|
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ddpMessage.fields) {
|
|
|
|
this.activeUsers[ddpMessage.id] = { status: 'offline' };
|
|
|
|
} else if (ddpMessage.fields.status) {
|
|
|
|
this.activeUsers[ddpMessage.id] = { status: ddpMessage.fields.status };
|
|
|
|
}
|
|
|
|
}
|